Skip to main content

luaur_code_gen/functions/
replace_inst_operand_ir_utils.rs

1use crate::functions::get_op_ir_data::get_op_mut;
2use crate::functions::replace_ir_utils::replace_ir_function_ir_op_ir_op;
3use crate::records::ir_function::IrFunction;
4use crate::records::ir_op::IrOp;
5
6pub fn replace_ir_function_ir_inst_operand(
7    function: &mut IrFunction,
8    inst_idx: u32,
9    op_idx: u32,
10    replacement: IrOp,
11) {
12    let function_ptr = function as *mut IrFunction;
13
14    unsafe {
15        let original = get_op_mut(
16            &mut (&mut (*function_ptr).instructions)[inst_idx as usize],
17            op_idx,
18        ) as *mut IrOp;
19        replace_ir_function_ir_op_ir_op(&mut *function_ptr, &mut *original, replacement);
20    }
21}