Skip to main content

luaur_code_gen/functions/
call_get_table.rs

1use crate::enums::size_x_64::SizeX64;
2use crate::functions::emit_update_base_emit_common_x_64::emit_update_base;
3use crate::functions::luau_reg_address::luau_reg_address;
4use crate::records::assembly_builder_x_64::AssemblyBuilderX64;
5use crate::records::ir_call_wrapper_x_64::IrCallWrapperX64;
6use crate::records::ir_data::k_invalid_inst_idx;
7use crate::records::ir_op::IrOp;
8use crate::records::ir_reg_alloc_x_64::IrRegAllocX64;
9use crate::records::native_context::NativeContext;
10use crate::records::operand_x_64::OperandX64;
11use crate::records::register_x_64::RegisterX64;
12
13const fn r_state() -> RegisterX64 {
14    RegisterX64 {
15        bits: (15u8 << RegisterX64::INDEX_SHIFT) | SizeX64::qword as u8,
16    }
17}
18
19const fn r_native_context() -> RegisterX64 {
20    RegisterX64 {
21        bits: (13u8 << RegisterX64::INDEX_SHIFT) | SizeX64::qword as u8,
22    }
23}
24
25pub fn call_get_table(
26    regs: &mut IrRegAllocX64,
27    build: &mut AssemblyBuilderX64,
28    rb: i32,
29    c: OperandX64,
30    ra: i32,
31) {
32    let mut call_wrap = IrCallWrapperX64::ir_call_wrapper_x_64_ir_call_wrapper_x_64(
33        regs,
34        build,
35        k_invalid_inst_idx,
36    );
37
38    call_wrap.add_argument_size_x_64_operand_x_64_ir_op(
39        SizeX64::qword,
40        OperandX64::reg(r_state()),
41        IrOp::ir_op(),
42    );
43    call_wrap.add_argument_size_x_64_operand_x_64_ir_op(
44        SizeX64::qword,
45        luau_reg_address(rb),
46        IrOp::ir_op(),
47    );
48    call_wrap.add_argument_size_x_64_operand_x_64_ir_op(SizeX64::qword, c, IrOp::ir_op());
49    call_wrap.add_argument_size_x_64_operand_x_64_ir_op(
50        SizeX64::qword,
51        luau_reg_address(ra),
52        IrOp::ir_op(),
53    );
54
55    call_wrap.call(&OperandX64::mem(
56        SizeX64::qword,
57        RegisterX64::noreg,
58        1,
59        r_native_context(),
60        core::mem::offset_of!(NativeContext, luaV_gettable) as i32,
61    ));
62
63    emit_update_base(build);
64}