Add options for parsing test files (#942)
* Add options for parsing test files This change allows adding parsing parameters more easily; e.g. a parameter is needed for setting the default calling convention for functions parsed as a part of the `run` test feature. * Set default calling convention that of the host for `test run` file tests Previously `test run` used the parser's hard-coded CallConv::Fast as the default calling convention but with this change any test being `run` will use the default calling convention of the machine running the test. `test run` will now throw an error if the calling convention of the function does not match the host's.
This commit is contained in:
committed by
Till Schneidereit
parent
e4702d695e
commit
6fdc69ff2e
@@ -9,7 +9,7 @@ use cranelift_codegen::ir::{
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use cranelift_codegen::Context;
|
||||
use cranelift_entity::PrimaryMap;
|
||||
use cranelift_reader::parse_test;
|
||||
use cranelift_reader::{parse_test, ParseOptions};
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -27,7 +27,8 @@ pub fn run(
|
||||
let path = Path::new(&filename).to_path_buf();
|
||||
|
||||
let buffer = read_to_string(&path).map_err(|e| format!("{}: {}", filename, e))?;
|
||||
let test_file = parse_test(&buffer, None, None).map_err(|e| format!("{}: {}", filename, e))?;
|
||||
let test_file =
|
||||
parse_test(&buffer, ParseOptions::default()).map_err(|e| format!("{}: {}", filename, e))?;
|
||||
|
||||
// If we have an isa from the command-line, use that. Otherwise if the
|
||||
// file contains a unique isa, use that.
|
||||
@@ -754,12 +755,13 @@ impl<'a> CrashCheckContext<'a> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use cranelift_reader::ParseOptions;
|
||||
|
||||
#[test]
|
||||
fn test_reduce() {
|
||||
const TEST: &'static str = include_str!("./bugpoint_test.clif");
|
||||
|
||||
let test_file = parse_test(TEST, None, None).unwrap();
|
||||
let test_file = parse_test(TEST, ParseOptions::default()).unwrap();
|
||||
|
||||
// If we have an isa from the command-line, use that. Otherwise if the
|
||||
// file contains a unique isa, use that.
|
||||
|
||||
@@ -6,7 +6,7 @@ use cranelift_codegen::print_errors::pretty_error;
|
||||
use cranelift_codegen::settings::FlagsOrIsa;
|
||||
use cranelift_codegen::timing;
|
||||
use cranelift_codegen::Context;
|
||||
use cranelift_reader::parse_test;
|
||||
use cranelift_reader::{parse_test, ParseOptions};
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -44,7 +44,8 @@ fn handle_module(
|
||||
fisa: FlagsOrIsa,
|
||||
) -> Result<(), String> {
|
||||
let buffer = read_to_string(&path).map_err(|e| format!("{}: {}", name, e))?;
|
||||
let test_file = parse_test(&buffer, None, None).map_err(|e| format!("{}: {}", name, e))?;
|
||||
let test_file =
|
||||
parse_test(&buffer, ParseOptions::default()).map_err(|e| format!("{}: {}", name, e))?;
|
||||
|
||||
// If we have an isa from the command-line, use that. Otherwise if the
|
||||
// file contains a unique isa, use that.
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
//! CLI tool to compile Cranelift IR files to native code in memory and execute them.
|
||||
|
||||
use crate::utils::read_to_string;
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use cranelift_codegen::isa::{CallConv, TargetIsa};
|
||||
use cranelift_filetests::FunctionRunner;
|
||||
use cranelift_native::builder as host_isa_builder;
|
||||
use cranelift_reader::{parse_test, Details, IsaSpec};
|
||||
use cranelift_reader::{parse_test, Details, IsaSpec, ParseOptions};
|
||||
use std::path::PathBuf;
|
||||
use target_lexicon::Triple;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
pub fn run(files: Vec<String>, flag_print: bool) -> Result<(), String> {
|
||||
@@ -74,7 +75,11 @@ fn run_single_file(path: &PathBuf) -> Result<(), String> {
|
||||
|
||||
/// Main body of `run_single_file` separated for testing
|
||||
fn run_file_contents(file_contents: String) -> Result<(), String> {
|
||||
let test_file = parse_test(&file_contents, None, None).map_err(|e| e.to_string())?;
|
||||
let options = ParseOptions {
|
||||
default_calling_convention: CallConv::triple_default(&Triple::host()), // use the host's default calling convention
|
||||
..ParseOptions::default()
|
||||
};
|
||||
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")) {
|
||||
let isa = create_target_isa(&test_file.isa_spec)?;
|
||||
|
||||
Reference in New Issue
Block a user