From 65f69fb0885a118be2dc83837c74ae72ae4416de Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Wed, 21 Sep 2016 13:32:46 -0700 Subject: [PATCH] Add a 'test legaliser' filetest command. This test command sends each function through legalize_function() and then filecheck. --- filetests/isa/riscv/encoding.cton | 19 +++++++++++++ src/libcretonne/lib.rs | 3 ++- src/tools/filetest/legalizer.rs | 45 +++++++++++++++++++++++++++++++ src/tools/filetest/mod.rs | 2 ++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 filetests/isa/riscv/encoding.cton create mode 100644 src/tools/filetest/legalizer.rs diff --git a/filetests/isa/riscv/encoding.cton b/filetests/isa/riscv/encoding.cton new file mode 100644 index 0000000000..2ba06007bb --- /dev/null +++ b/filetests/isa/riscv/encoding.cton @@ -0,0 +1,19 @@ +test legalizer +isa riscv supports_m=1 + +function int32(i32, i32) { +ebb0(v1: i32, v2: i32): + v10 = iadd v1, v2 + ; check: [R#0c] + ; sameln: $v10 = iadd + + v11 = isub v1, v2 + ; check: [R#200c] + ; sameln: $v11 = isub + + v12 = imul v1, v2 + ; check: [R#10c] + ; sameln: $v12 = imul + + return +} diff --git a/src/libcretonne/lib.rs b/src/libcretonne/lib.rs index f0a328ba8f..26a87bd223 100644 --- a/src/libcretonne/lib.rs +++ b/src/libcretonne/lib.rs @@ -7,6 +7,7 @@ pub use verifier::verify_function; pub use write::write_function; +pub use legalizer::legalize_function; pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); @@ -17,11 +18,11 @@ pub mod dominator_tree; pub mod entity_map; pub mod settings; pub mod verifier; -pub mod legalizer; mod write; mod constant_hash; mod predicates; +mod legalizer; #[cfg(test)] pub mod test_utils; diff --git a/src/tools/filetest/legalizer.rs b/src/tools/filetest/legalizer.rs new file mode 100644 index 0000000000..ea53a703b7 --- /dev/null +++ b/src/tools/filetest/legalizer.rs @@ -0,0 +1,45 @@ +//! Test command for checking the IL legalizer. +//! +//! The `test legalizer` test command runs each function through `legalize_function()` and sends +//! the result to filecheck. + +use std::borrow::Cow; +use cretonne::{legalize_function, write_function}; +use cretonne::ir::Function; +use cton_reader::TestCommand; +use filetest::subtest::{SubTest, Context, Result, run_filecheck}; + +struct TestLegalizer; + +pub fn subtest(parsed: &TestCommand) -> Result> { + assert_eq!(parsed.command, "legalizer"); + if !parsed.options.is_empty() { + Err(format!("No options allowed on {}", parsed)) + } else { + Ok(Box::new(TestLegalizer)) + } +} + +impl SubTest for TestLegalizer { + fn name(&self) -> Cow { + Cow::from("legalizer") + } + + fn is_mutating(&self) -> bool { + true + } + + fn needs_isa(&self) -> bool { + true + } + + fn run(&self, func: Cow, context: &Context) -> Result<()> { + let mut func = func.into_owned(); + let isa = context.isa.expect("legalizer needs an ISA"); + legalize_function(&mut func, isa); + + let mut text = String::new(); + try!(write_function(&mut text, &func, Some(isa)).map_err(|e| e.to_string())); + run_filecheck(&text, context) + } +} diff --git a/src/tools/filetest/mod.rs b/src/tools/filetest/mod.rs index a924cb04eb..28a9b94d45 100644 --- a/src/tools/filetest/mod.rs +++ b/src/tools/filetest/mod.rs @@ -17,6 +17,7 @@ mod runone; mod concurrent; mod domtree; mod verifier; +mod legalizer; /// The result of running the test in a file. pub type TestResult = Result; @@ -55,6 +56,7 @@ fn new_subtest(parsed: &TestCommand) -> subtest::Result> { "print-cfg" => print_cfg::subtest(parsed), "domtree" => domtree::subtest(parsed), "verifier" => verifier::subtest(parsed), + "legalizer" => legalizer::subtest(parsed), _ => Err(format!("unknown test command '{}'", parsed.command)), } }