Skip to main content

luaur_code_gen/records/
ir_op.rs

1use crate::enums::ir_op_kind::IrOpKind;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4#[repr(C)]
5pub struct IrOp {
6    pub(crate) kind_and_index: u32,
7}
8
9impl IrOp {
10    pub(crate) const KIND_MASK: u32 = 0xF;
11    pub(crate) const INDEX_SHIFT: u32 = 4;
12
13    pub fn kind(&self) -> IrOpKind {
14        unsafe { core::mem::transmute(self.kind_and_index & Self::KIND_MASK) }
15    }
16
17    pub fn index(&self) -> u32 {
18        self.kind_and_index >> Self::INDEX_SHIFT
19    }
20}
21
22impl Default for IrOp {
23    fn default() -> Self {
24        Self {
25            kind_and_index: IrOpKind::None as u32,
26        }
27    }
28}
29
30impl luaur_common::records::dense_hash_table::DenseDefault for IrOp {
31    fn dense_default() -> Self {
32        Self::default()
33    }
34}