luaur_code_gen/functions/luau_constant_value.rs
1use crate::enums::size_x_64::SizeX64;
2use crate::records::operand_x_64::OperandX64;
3use crate::records::register_x_64::RegisterX64;
4use luaur_vm::type_aliases::t_value::TValue;
5
6/// Returns an operand for the value field of a constant TValue in the constant array.
7///
8/// C++: qword[rConstants + ki * sizeof(TValue) + offsetof(TValue, value)]
9///
10/// In Luau x64 JIT:
11/// - rConstants is a base pointer to the constant array
12/// - sizeof(TValue) is 16 (2^kTValueSizeLog2, where kTValueSizeLog2 = 4)
13/// - offsetof(TValue, value) is 0 (Value is the first member of the union)
14/// - The operand uses qword size for the full TValue value field access
15#[inline]
16pub fn luau_constant_value(ki: i32) -> OperandX64 {
17 let tvalue_size = core::mem::size_of::<TValue>() as i32;
18 let value_offset = 0;
19
20 // NOTE: rConstants is represented as a memory base register operand, not as a RegisterX64::rconstants associated constant.
21 OperandX64::operand_x_64_size_x_64_register_x_64_u8_register_x_64_i32(
22 SizeX64::qword,
23 RegisterX64::noreg,
24 0,
25 RegisterX64::rbp,
26 ki * tvalue_size + value_offset,
27 )
28}