Skip to main content

luaur_code_gen/records/
ir_inst.rs

1use crate::enums::ir_cmd::IrCmd;
2use crate::records::ir_op::IrOp;
3use crate::records::register_a_64::RegisterA64;
4use crate::records::register_x_64::RegisterX64;
5use crate::type_aliases::ir_ops::IrOps;
6
7#[derive(Debug, Clone)]
8#[repr(C)]
9// Public in the C++ `IrInst`; exposed so the cross-crate test harness (and the
10// pub `apply_substitutions`/`IrFunction::instructions` that already reference it)
11// can name it.
12pub struct IrInst {
13    pub cmd: IrCmd,
14    pub ops: IrOps,
15    pub last_use: u32,
16    pub use_count: u16,
17    pub reg_x64: RegisterX64,
18    pub reg_a64: RegisterA64,
19    pub reused_reg: bool,
20    pub spilled: bool,
21    pub needs_reload: bool,
22}
23
24impl IrInst {
25    /// Construct an `IrInst` from a command and an operand list, mirroring the
26    /// C++ aggregate initialization `IrInst{cmd, {ops...}}`. Used by the test
27    /// fixture's `checkEq` to build the expected instruction for comparison.
28    pub fn ir_inst_new(cmd: IrCmd, ops: &[IrOp]) -> Self {
29        Self {
30            cmd,
31            ops: ops.iter().cloned().collect(),
32            ..Self::default()
33        }
34    }
35}
36
37impl Default for IrInst {
38    fn default() -> Self {
39        Self {
40            cmd: IrCmd::NOP,
41            ops: IrOps::new(),
42            last_use: 0,
43            use_count: 0,
44            reg_x64: RegisterX64::noreg,
45            reg_a64: RegisterA64::noreg,
46            reused_reg: false,
47            spilled: false,
48            needs_reload: false,
49        }
50    }
51}