Use a unique ISA in 'test cat' file tests.

Add a Function::display() method which can include ISA-specific
information when printing the function.

If a test file has a unique ISA, use that in the `test cat`
implementation.
This commit is contained in:
Jakob Stoklund Olesen
2017-03-08 12:50:43 -08:00
parent 4525929df2
commit cbbf5cc88b
5 changed files with 27 additions and 10 deletions

View File

@@ -17,9 +17,9 @@ ebb1(v0: i32, v1: i32):
; nextln: $ebb1($v0: i32, $v1: i32): ; nextln: $ebb1($v0: i32, $v1: i32):
; nextln: [-]$WS $v2 = iadd $v0, $v1 ; nextln: [-]$WS $v2 = iadd $v0, $v1
; nextln: [-]$WS trap ; 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 ; 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: [-]$WS $v9 = iadd $v8, $v7
; nextln: [3#05]$WS return $v0, $v8 ; nextln: [Iret#05]$WS return $v0, $v8
; nextln: } ; nextln: }

View File

@@ -61,6 +61,6 @@ impl SubTest for TestCat {
} }
fn run(&self, func: Cow<Function>, context: &Context) -> STResult<()> { fn run(&self, func: Cow<Function>, context: &Context) -> STResult<()> {
subtest::run_filecheck(&func.to_string(), context) subtest::run_filecheck(&func.display(context.isa).to_string(), context)
} }
} }

View File

@@ -90,7 +90,10 @@ fn test_tuples<'a>(tests: &'a [Box<SubTest>],
} }
} }
} else { } 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) Ok(out)

View File

@@ -10,7 +10,7 @@ use filecheck::{self, CheckerBuilder, Checker, Value as FCValue};
pub type Result<T> = result::Result<T, String>; pub type Result<T> = result::Result<T, String>;
/// Context for running a a test on a single function. /// Context for running a test on a single function.
pub struct Context<'a> { pub struct Context<'a> {
/// Comments from the preamble f the test file. These apply to all functions. /// Comments from the preamble f the test file. These apply to all functions.
pub preamble_comments: &'a [Comment<'a>], pub preamble_comments: &'a [Comment<'a>],
@@ -24,8 +24,8 @@ pub struct Context<'a> {
/// ISA-independent flags for this test. /// ISA-independent flags for this test.
pub flags: &'a Flags, pub flags: &'a Flags,
/// Target ISA to test against. Only present for sub-tests whose `needs_isa` method returned /// Target ISA to test against. Only guaranteed to be present for sub-tests whose `needs_isa`
/// true. /// method returned `true`. For other sub-tests, this is set if the test file has a unique ISA.
pub isa: Option<&'a TargetIsa>, pub isa: Option<&'a TargetIsa>,
} }

View File

@@ -6,7 +6,7 @@
use std::fmt::{self, Display, Debug, Formatter}; use std::fmt::{self, Display, Debug, Formatter};
use ir::{FunctionName, Signature, Value, Inst, StackSlot, StackSlotData, JumpTable, JumpTableData, use ir::{FunctionName, Signature, Value, Inst, StackSlot, StackSlotData, JumpTable, JumpTableData,
ValueLoc, DataFlowGraph, Layout}; ValueLoc, DataFlowGraph, Layout};
use isa::Encoding; use isa::{TargetIsa, Encoding};
use entity_map::{EntityMap, PrimaryEntityData}; use entity_map::{EntityMap, PrimaryEntityData};
use write::write_function; use write::write_function;
@@ -64,6 +64,20 @@ impl Function {
pub fn new() -> Function { pub fn new() -> Function {
Self::with_name_signature(FunctionName::default(), Signature::new()) 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<Option<&'a TargetIsa>>>(&'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 { impl Display for Function {