Skip to main content

luaur_bytecode/methods/
call_inliner_append_cmp_proto.rs

1use crate::enums::bc_block_edge_kind::BcBlockEdgeKind;
2use crate::records::bc_block::BcBlock;
3use crate::records::bc_block_edge::BcBlockEdge;
4use crate::records::bc_cmp_proto::BcCmpProto;
5use crate::records::bc_op::BcOp;
6use crate::records::bc_ref::BcRef;
7use crate::records::call_inliner::CallInliner;
8
9impl<'a> CallInliner<'a> {
10    pub fn append_cmp_proto(
11        &mut self,
12        prev_block: &mut BcRef<'a, BcBlock>,
13        target_op: BcOp,
14        target_proto_id: u32,
15    ) {
16        let call_block = self.call.base.operator_deref().block;
17        {
18            let mut cmp_proto =
19                BcCmpProto::<crate::records::bc_function::VmConst>::create(self.caller);
20            cmp_proto.set_closure(target_op);
21            cmp_proto.set_proto_id(target_proto_id);
22            cmp_proto.set_fallback(call_block);
23            cmp_proto.append_to(prev_block.op);
24        }
25        prev_block
26            .operator_deref_mut()
27            .successors
28            .push_back(BcBlockEdge {
29                kind: BcBlockEdgeKind::Branch,
30                target: call_block,
31            });
32        self.caller.blocks[call_block.index as usize]
33            .predecessors
34            .push_back(BcBlockEdge {
35                kind: BcBlockEdgeKind::Branch,
36                target: prev_block.op,
37            });
38    }
39}