Expose parsing of run commands and trivially use in testing framework

This is necessary to avoid build errors from dead code (and I didn't want to litter all of the structs with `#[allow(dead_code)]` just to remove in a subsequent PR).
This commit is contained in:
Andrew Brown
2020-03-30 13:38:51 -07:00
parent f56f9fb01c
commit 5297466add
4 changed files with 19 additions and 1 deletions

View File

@@ -6,7 +6,9 @@ use crate::function_runner::FunctionRunner;
use crate::subtest::{Context, SubTest, SubtestResult}; use crate::subtest::{Context, SubTest, SubtestResult};
use cranelift_codegen; use cranelift_codegen;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use cranelift_reader::parse_run_command;
use cranelift_reader::TestCommand; use cranelift_reader::TestCommand;
use log::trace;
use std::borrow::Cow; use std::borrow::Cow;
struct TestRun; struct TestRun;
@@ -36,6 +38,12 @@ impl SubTest for TestRun {
fn run(&self, func: Cow<ir::Function>, context: &Context) -> SubtestResult<()> { fn run(&self, func: Cow<ir::Function>, context: &Context) -> SubtestResult<()> {
for comment in context.details.comments.iter() { for comment in context.details.comments.iter() {
if comment.text.contains("run") { if comment.text.contains("run") {
let trimmed_comment = comment.text.trim_start_matches(|c| c == ' ' || c == ';');
let command = parse_run_command(trimmed_comment, &func.signature)
.map_err(|e| format!("{}", e))?;
trace!("Parsed run command: {}", command);
// TODO in following changes we will use the parsed command to alter FunctionRunner's behavior.
let runner = let runner =
FunctionRunner::with_host_isa(func.clone().into_owned(), context.flags.clone()); FunctionRunner::with_host_isa(func.clone().into_owned(), context.flags.clone());
runner.run()? runner.run()?

View File

@@ -28,7 +28,8 @@
pub use crate::error::{Location, ParseError, ParseResult}; pub use crate::error::{Location, ParseError, ParseResult};
pub use crate::isaspec::{parse_options, IsaSpec}; pub use crate::isaspec::{parse_options, IsaSpec};
pub use crate::parser::{parse_functions, parse_test, ParseOptions}; pub use crate::parser::{parse_functions, parse_run_command, parse_test, ParseOptions};
pub use crate::run_command::{Comparison, DataValue, Invocation, RunCommand};
pub use crate::sourcemap::SourceMap; pub use crate::sourcemap::SourceMap;
pub use crate::testcommand::{TestCommand, TestOption}; pub use crate::testcommand::{TestCommand, TestOption};
pub use crate::testfile::{Comment, Details, Feature, TestFile}; pub use crate::testfile::{Comment, Details, Feature, TestFile};

View File

@@ -114,6 +114,13 @@ pub fn parse_test<'a>(text: &'a str, options: ParseOptions<'a>) -> ParseResult<T
}) })
} }
/// Parse the entire `text` as a run command.
pub fn parse_run_command<'a>(text: &str, signature: &Signature) -> ParseResult<RunCommand> {
let _tt = timing::parse_text();
let mut parser = Parser::new(text);
parser.parse_run_command(signature)
}
pub struct Parser<'a> { pub struct Parser<'a> {
lex: Lexer<'a>, lex: Lexer<'a>,

View File

@@ -92,7 +92,9 @@ fn run_file_contents(file_contents: String) -> Result<(), String> {
let test_file = parse_test(&file_contents, options).map_err(|e| e.to_string())?; let test_file = parse_test(&file_contents, options).map_err(|e| e.to_string())?;
for (func, Details { comments, .. }) in test_file.functions { for (func, Details { comments, .. }) in test_file.functions {
if comments.iter().any(|c| c.text.contains("run")) { if comments.iter().any(|c| c.text.contains("run")) {
// TODO in following changes we will parse this comment to alter the FunctionRunner's behavior.
let isa = create_target_isa(&test_file.isa_spec)?; let isa = create_target_isa(&test_file.isa_spec)?;
// TODO the following no longer makes sense; use FunctionRunner::with_host_isa(...) instead
FunctionRunner::new(func, isa).run()? FunctionRunner::new(func, isa).run()?
} }
} }