use super::{Register, Variable, Precision, UnaryOp, BinaryOp, Width};
#[no_mangle]
pub extern fn debug_word(x: u64) {
println!("Debug: {:#018x}", x);
}
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
pub struct Address {
pub base: Variable,
pub offset: i32,
pub width: Width,
}
impl std::fmt::Debug for Address {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if self.offset >= 0 {
write!(f, "[{:?} + {:#x}] {:?}", self.base, self.offset, self.width)
} else {
write!(f, "[{:?} - {:#x}] {:?}", self.base, self.offset.wrapping_neg() as u32, self.width)
}
}
}
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
pub enum Action {
Move(Variable, Variable),
Constant(Precision, Register, i64),
Unary(UnaryOp, Precision, Register, Variable),
Binary(BinaryOp, Precision, Register, Variable, Variable),
Load(Register, Address),
Store(Register, Variable, Address),
Send(Register, Variable, Variable),
Push(Option<Variable>, Option<Variable>),
Drop(usize),
Debug(Variable),
}
impl std::fmt::Debug for Action {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Action::Move(dest, src) =>
write!(f, "Move {:?}, {:?}", dest, src),
Action::Constant(prec, dest, c) =>
write!(f, "Constant_{:?} {:?}, {:x?}", prec, dest, c),
Action::Unary(op, prec, dest, src) =>
write!(f, "{:?}_{:?} {:?}, {:?}", op, prec, dest, src),
Action::Binary(op, prec, dest, src1, src2) =>
write!(f, "{:?}_{:?} {:?}, {:?}, {:?}", op, prec, dest, src1, src2),
Action::Load(dest, addr) =>
write!(f, "Load {:?}, {:?}", dest, addr),
Action::Store(dest, src, addr) =>
write!(f, "Store{:?} {:?}, {:?}", dest, src, addr),
Action::Send(dest, src1, src2) =>
write!(f, "Send {:?}, {:?}, {:?}", dest, src1, src2),
Action::Push(src1, src2) =>
write!(f, "Push ({:?}, {:?})", src1, src2),
Action::Drop(n) =>
write!(f, "Drop 2*{:?}", n),
Action::Debug(src) =>
write!(f, "Debug {:?}", src),
}
}
}
#[cfg(test)]
pub mod tests {
use super::*;
#[test]
fn not_really_a_test() {
debug_word(0);
}
}