luaur_bytecode/records/
bc_call_fb.rs1use core::marker::PhantomData;
2
3use alloc::vec::Vec;
4use luaur_common::enums::luau_opcode::LuauOpcode;
5
6use crate::methods::bc_function_as::BcInstType;
7use crate::methods::bc_inst_helper_create::BcInstHelperCreate;
8use crate::records::bc_function::{BcFunction, VmConst};
9use crate::records::bc_inst::BcInst;
10use crate::records::bc_inst_helper::BcInstHelper;
11use crate::records::bc_op::BcOp;
12use crate::records::bc_ref::BcRef;
13
14#[derive(Debug)]
15pub struct BcCallFB<'a, T = VmConst> {
16 pub(crate) base: BcInstHelper<'a>,
17 _marker: PhantomData<T>,
18}
19
20impl<'a, T> BcCallFB<'a, T> {
21 pub const K_PARAM_START_INPUT: u32 = 4;
22
23 pub fn from(graph: *mut BcFunction, inst: BcRef<'a, BcInst>) -> Self {
24 Self {
25 base: BcInstHelper::new(unsafe { &mut *graph }, inst),
26 _marker: PhantomData,
27 }
28 }
29
30 pub fn params(&self) -> Vec<BcOp> {
31 self.base.slice_inputs(Self::K_PARAM_START_INPUT)
32 }
33
34 pub fn param_count(&mut self) -> i32 {
35 self.base.int_imm_input(0)
36 }
37
38 pub fn set_param_count(&mut self, value: u32) {
39 self.base.set_imm_input(0, value as i32);
40 }
41
42 pub fn return_count(&mut self) -> i32 {
43 self.base.int_imm_input(1)
44 }
45
46 pub fn set_return_count(&mut self, value: u32) {
47 self.base.set_imm_input(1, value as i32);
48 }
49
50 pub fn fb_slot(&mut self) -> i32 {
51 self.base.int_imm_input(2)
52 }
53
54 pub fn set_fb_slot(&mut self, value: u32) {
55 self.base.set_imm_input(2, value as i32);
56 }
57
58 pub fn target(&mut self) -> BcOp {
59 self.base.get_bc_op(3)
60 }
61
62 pub fn set_target(&mut self, value: BcOp) {
63 self.base.set_bc_op(3, value);
64 }
65
66 pub fn op(&self) -> BcOp {
67 self.base.op()
68 }
69}
70
71impl<T> BcInstType for BcCallFB<'_, T> {
72 const OPCODE: i32 = LuauOpcode::LOP_CALLFB as i32;
73}
74
75impl<T> BcInstHelperCreate for BcCallFB<'_, T> {
76 const OPCODE: LuauOpcode = LuauOpcode::LOP_CALLFB;
77}
78
79impl<'a, T> From<(&'a BcFunction, BcRef<'a, BcInst>)> for BcCallFB<'a, T> {
80 fn from((graph, inst): (&'a BcFunction, BcRef<'a, BcInst>)) -> Self {
81 Self::from(graph as *const BcFunction as *mut BcFunction, inst)
82 }
83}