luaur_bytecode/methods/
bc_inst_helper_insert_before.rs1use crate::records::bc_block::BcBlock;
2use crate::records::bc_inst::BcInst;
3use crate::records::bc_inst_helper::BcInstHelper;
4use crate::records::bc_ref::BcRef;
5use luaur_common::macros::luau_assert::LUAU_ASSERT;
6
7impl BcInstHelper<'_> {
8 pub fn insert_before(&mut self, op: BcRef<'_, BcInst>) {
9 let op_block = unsafe { (*op.operator_arrow()).block };
10
11 unsafe {
13 (*self.inst.operator_arrow()).block = op_block;
14 }
15
16 let block_ref = self.graph.block(op_block);
18 let block: &mut BcBlock = unsafe { &mut *block_ref.operator_arrow() };
19
20 let it = block.ops.iter().position(|&x| x == op.op);
22
23 LUAU_ASSERT!(it.is_some());
25
26 if let Some(index) = it {
28 block.ops.insert(index, self.inst.op);
29 }
30 }
31}