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:
@@ -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<ir::Function>, 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()?
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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> {
|
||||
lex: Lexer<'a>,
|
||||
|
||||
|
||||
@@ -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()?
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user