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

@@ -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 {