tnj_air/instructions/
value.rs

1mod block;
2mod constant;
3mod inst;
4
5use arch::reg::Reg;
6pub use block::*;
7pub use constant::*;
8pub use inst::*;
9
10/// A value
11/// TODO: can we somehow optimize the packing of these so they can fit in a single 32 bit value?
12#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
13pub enum Value {
14    /// Value is an instruction
15    Inst(Inst),
16    /// Value is a constant
17    Const(Const),
18    /// Value is a label (block)
19    Label(BasicBlock),
20    /// Value is a register
21    Reg(Reg),
22    /// Value is a block parameter
23    BlockParam(BlockParam),
24    /// Value is the special `undef` value
25    Undef,
26}
27
28impl Value {
29    /// Returns true if `self` is an instruction
30    pub fn is_inst(&self) -> bool {
31        matches!(self, Self::Inst(_))
32    }
33    /// Returns true if `self` is a constant
34    pub fn is_const(&self) -> bool {
35        matches!(self, Self::Const(_))
36    }
37}
38
39macro_rules! value_from {
40    ($variant:ident, $inner:ident) => {
41        impl From<$inner> for Value {
42            fn from(value: $inner) -> Value {
43                Value::$variant(value)
44            }
45        }
46    };
47}
48
49value_from!(Inst, Inst);
50value_from!(Const, Const);
51value_from!(Label, BasicBlock);
52value_from!(Reg, Reg);
53value_from!(BlockParam, BlockParam);