Add an Affinity::display() method.
Make it possible to display affinities given a RegInfo reference.
This commit is contained in:
@@ -153,6 +153,12 @@ impl RegClassData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for RegClassData {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
f.write_str(self.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A small reference to a register class.
|
/// A small reference to a register class.
|
||||||
///
|
///
|
||||||
/// Use this when storing register classes in compact data structures. The `RegInfo::rc()` method
|
/// Use this when storing register classes in compact data structures. The `RegInfo::rc()` method
|
||||||
@@ -176,6 +182,12 @@ impl From<RegClass> for RegClassIndex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for RegClassIndex {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "rci{}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Information about the registers in an ISA.
|
/// Information about the registers in an ISA.
|
||||||
///
|
///
|
||||||
/// The `RegUnit` data structure collects all relevant static information about the registers in an
|
/// The `RegUnit` data structure collects all relevant static information about the registers in an
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
//! subclass. This is just a hint, and the register allocator is allowed to pick a register from a
|
//! subclass. This is just a hint, and the register allocator is allowed to pick a register from a
|
||||||
//! larger register class instead.
|
//! larger register class instead.
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
use ir::{ArgumentType, ArgumentLoc};
|
use ir::{ArgumentType, ArgumentLoc};
|
||||||
use isa::{TargetIsa, RegInfo, RegClassIndex, OperandConstraint, ConstraintKind};
|
use isa::{TargetIsa, RegInfo, RegClassIndex, OperandConstraint, ConstraintKind};
|
||||||
|
|
||||||
@@ -75,4 +76,28 @@ impl Affinity {
|
|||||||
Affinity::Stack => {}
|
Affinity::Stack => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return an object that can display this value affinity, using the register info from the
|
||||||
|
/// target ISA.
|
||||||
|
pub fn display<'a, R: Into<Option<&'a RegInfo>>>(self, regs: R) -> DisplayAffinity<'a> {
|
||||||
|
DisplayAffinity(self, regs.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Displaying an `Affinity` correctly requires the associated `RegInfo` from the target ISA.
|
||||||
|
pub struct DisplayAffinity<'a>(Affinity, Option<&'a RegInfo>);
|
||||||
|
|
||||||
|
impl<'a> fmt::Display for DisplayAffinity<'a> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self.0 {
|
||||||
|
Affinity::None => write!(f, "none"),
|
||||||
|
Affinity::Stack => write!(f, "stack"),
|
||||||
|
Affinity::Reg(rci) => {
|
||||||
|
match self.1 {
|
||||||
|
Some(regs) => write!(f, "{}", regs.rc(rci)),
|
||||||
|
None => write!(f, "{}", rci),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user