diff --git a/cranelift/filetests/src/test_run.rs b/cranelift/filetests/src/test_run.rs index 6e34bfebfa..2fbb657aa7 100644 --- a/cranelift/filetests/src/test_run.rs +++ b/cranelift/filetests/src/test_run.rs @@ -6,7 +6,9 @@ use crate::function_runner::FunctionRunner; use crate::subtest::{Context, SubTest, SubtestResult}; use cranelift_codegen; use cranelift_codegen::ir; +use cranelift_reader::parse_run_command; use cranelift_reader::TestCommand; +use log::trace; use std::borrow::Cow; struct TestRun; @@ -36,6 +38,12 @@ impl SubTest for TestRun { fn run(&self, func: Cow, context: &Context) -> SubtestResult<()> { for comment in context.details.comments.iter() { 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 = FunctionRunner::with_host_isa(func.clone().into_owned(), context.flags.clone()); runner.run()? diff --git a/cranelift/reader/src/lib.rs b/cranelift/reader/src/lib.rs index 369b173453..c352b7c910 100644 --- a/cranelift/reader/src/lib.rs +++ b/cranelift/reader/src/lib.rs @@ -28,7 +28,8 @@ pub use crate::error::{Location, ParseError, ParseResult}; 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::testcommand::{TestCommand, TestOption}; pub use crate::testfile::{Comment, Details, Feature, TestFile}; diff --git a/cranelift/reader/src/parser.rs b/cranelift/reader/src/parser.rs index 7ecf6473b4..465701155e 100644 --- a/cranelift/reader/src/parser.rs +++ b/cranelift/reader/src/parser.rs @@ -114,6 +114,13 @@ pub fn parse_test<'a>(text: &'a str, options: ParseOptions<'a>) -> ParseResult(text: &str, signature: &Signature) -> ParseResult { + let _tt = timing::parse_text(); + let mut parser = Parser::new(text); + parser.parse_run_command(signature) +} + pub struct Parser<'a> { lex: Lexer<'a>, diff --git a/cranelift/src/run.rs b/cranelift/src/run.rs index 0f553c8702..37c65adf70 100644 --- a/cranelift/src/run.rs +++ b/cranelift/src/run.rs @@ -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())?; for (func, Details { comments, .. }) in test_file.functions { 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)?; + // TODO the following no longer makes sense; use FunctionRunner::with_host_isa(...) instead FunctionRunner::new(func, isa).run()? } }