Skip to main content

luaur_code_gen/methods/
ir_function_as_inst_op.rs

1use crate::enums::ir_op_kind::IrOpKind;
2use crate::records::ir_function::IrFunction;
3use crate::records::ir_inst::IrInst;
4use crate::records::ir_op::IrOp;
5
6impl IrFunction {
7    pub fn as_inst_op(&mut self, op: IrOp) -> *mut IrInst {
8        if op.kind() == IrOpKind::Inst {
9            // Safety: the C++ source directly indexes into instructions[op.index] without bounds
10            // checking, assuming the index is valid. We match that behavior here.
11            unsafe { self.instructions.as_mut_ptr().add(op.index() as usize) }
12        } else {
13            std::ptr::null_mut()
14        }
15    }
16}