diff --git a/cranelift/filetests/parser/instruction_encoding.cton b/cranelift/filetests/parser/instruction_encoding.cton index 49c1913bcf..0e40d0b2f1 100644 --- a/cranelift/filetests/parser/instruction_encoding.cton +++ b/cranelift/filetests/parser/instruction_encoding.cton @@ -17,9 +17,9 @@ ebb1(v0: i32, v1: i32): ; nextln: $ebb1($v0: i32, $v1: i32): ; nextln: [-]$WS $v2 = iadd $v0, $v1 ; nextln: [-]$WS trap -; nextln: [0#1234]$WS $v6, $v7 = iadd_cout $v2, $v0 +; nextln: [R#1234]$WS $v6, $v7 = iadd_cout $v2, $v0 ; TODO Add the full encoding information available: instruction recipe name and architectural registers if specified -; nextln: [2#beef]$WS $v8 = ishl_imm $v6, 2 +; nextln: [Rshamt#beef]$WS $v8 = ishl_imm $v6, 2 ; nextln: [-]$WS $v9 = iadd $v8, $v7 -; nextln: [3#05]$WS return $v0, $v8 -; nextln: } \ No newline at end of file +; nextln: [Iret#05]$WS return $v0, $v8 +; nextln: } diff --git a/cranelift/src/cat.rs b/cranelift/src/cat.rs index 443c37dadc..fd49722ec0 100644 --- a/cranelift/src/cat.rs +++ b/cranelift/src/cat.rs @@ -61,6 +61,6 @@ impl SubTest for TestCat { } fn run(&self, func: Cow, context: &Context) -> STResult<()> { - subtest::run_filecheck(&func.to_string(), context) + subtest::run_filecheck(&func.display(context.isa).to_string(), context) } } diff --git a/cranelift/src/filetest/runone.rs b/cranelift/src/filetest/runone.rs index 06e4cfce6b..2067a245b9 100644 --- a/cranelift/src/filetest/runone.rs +++ b/cranelift/src/filetest/runone.rs @@ -90,7 +90,10 @@ fn test_tuples<'a>(tests: &'a [Box], } } } else { - out.push((&**test, no_isa_flags, None)); + // This test doesn't require an ISA, and we only want to run one instance of it. + // Still, give it an ISA ref if we happen to have a unique one. + // For example, `test cat` can use this to print encodings and register names. + out.push((&**test, no_isa_flags, isa_spec.unique_isa())); } } Ok(out) diff --git a/cranelift/src/filetest/subtest.rs b/cranelift/src/filetest/subtest.rs index 8ba3528a6c..170490fb3a 100644 --- a/cranelift/src/filetest/subtest.rs +++ b/cranelift/src/filetest/subtest.rs @@ -10,7 +10,7 @@ use filecheck::{self, CheckerBuilder, Checker, Value as FCValue}; pub type Result = result::Result; -/// Context for running a a test on a single function. +/// Context for running a test on a single function. pub struct Context<'a> { /// Comments from the preamble f the test file. These apply to all functions. pub preamble_comments: &'a [Comment<'a>], @@ -24,8 +24,8 @@ pub struct Context<'a> { /// ISA-independent flags for this test. pub flags: &'a Flags, - /// Target ISA to test against. Only present for sub-tests whose `needs_isa` method returned - /// true. + /// Target ISA to test against. Only guaranteed to be present for sub-tests whose `needs_isa` + /// method returned `true`. For other sub-tests, this is set if the test file has a unique ISA. pub isa: Option<&'a TargetIsa>, } diff --git a/lib/cretonne/src/ir/function.rs b/lib/cretonne/src/ir/function.rs index b0115a70e3..1abf9c4b35 100644 --- a/lib/cretonne/src/ir/function.rs +++ b/lib/cretonne/src/ir/function.rs @@ -6,7 +6,7 @@ use std::fmt::{self, Display, Debug, Formatter}; use ir::{FunctionName, Signature, Value, Inst, StackSlot, StackSlotData, JumpTable, JumpTableData, ValueLoc, DataFlowGraph, Layout}; -use isa::Encoding; +use isa::{TargetIsa, Encoding}; use entity_map::{EntityMap, PrimaryEntityData}; use write::write_function; @@ -64,6 +64,20 @@ impl Function { pub fn new() -> Function { Self::with_name_signature(FunctionName::default(), Signature::new()) } + + /// Return an object that can display this function with correct ISA-specific annotations. + pub fn display<'a, I: Into>>(&'a self, isa: I) -> DisplayFunction<'a> { + DisplayFunction(self, isa.into()) + } +} + +/// Wrapper type capable of displaying a `Function` with correct ISA annotations. +pub struct DisplayFunction<'a>(&'a Function, Option<&'a TargetIsa>); + +impl<'a> Display for DisplayFunction<'a> { + fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + write_function(fmt, self.0, self.1) + } } impl Display for Function {