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:
@@ -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: }
|
||||
; nextln: [Iret#05]$WS return $v0, $v8
|
||||
; nextln: }
|
||||
|
||||
@@ -61,6 +61,6 @@ impl SubTest for TestCat {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,10 @@ fn test_tuples<'a>(tests: &'a [Box<SubTest>],
|
||||
}
|
||||
}
|
||||
} 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)
|
||||
|
||||
@@ -10,7 +10,7 @@ use filecheck::{self, CheckerBuilder, Checker, Value as FCValue};
|
||||
|
||||
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> {
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
|
||||
@@ -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<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 {
|
||||
|
||||
Reference in New Issue
Block a user