use regalloc2::{PReg, RegClass};
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(crate) struct Reg(PReg);
impl Reg {
pub const fn new(raw: PReg) -> Self {
Reg(raw)
}
pub fn int(enc: usize) -> Self {
Self::new(PReg::new(enc, RegClass::Int))
}
#[allow(dead_code)]
pub fn float(enc: usize) -> Self {
Self::new(PReg::new(enc, RegClass::Float))
}
pub const fn hw_enc(self) -> u8 {
self.0.hw_enc() as u8
}
pub(super) fn inner(&self) -> PReg {
self.0
}
}
impl From<Reg> for cranelift_codegen::Reg {
fn from(reg: Reg) -> Self {
reg.inner().into()
}
}
impl std::fmt::Debug for Reg {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}