Skip to main content

luaur_code_gen/methods/
ir_builder_const_any.rs

1use crate::enums::ir_op_kind::IrOpKind;
2use crate::records::ir_builder::{ConstantKey, IrBuilder};
3use crate::records::ir_const::IrConst;
4use crate::records::ir_op::IrOp;
5
6impl IrBuilder {
7    pub fn const_any(&mut self, constant: IrConst, as_common_key: u64) -> IrOp {
8        let key = ConstantKey {
9            kind: constant.kind,
10            value: as_common_key,
11        };
12
13        if let Some(&index) = self.constant_map.find(&key) {
14            return IrOp::ir_op_ir_op_kind_u32(IrOpKind::Constant, index);
15        }
16
17        let index = self.function.constants.len() as u32;
18        self.function.constants.push(constant);
19        *self.constant_map.get_or_insert(key) = index;
20
21        IrOp::ir_op_ir_op_kind_u32(IrOpKind::Constant, index)
22    }
23}