Skip to main content

luaur_code_gen/records/
ir_function.rs

1extern crate alloc;
2
3use crate::enums::ir_const_kind::IrConstKind;
4use crate::enums::ir_op_kind::IrOpKind;
5use crate::records::bytecode_block::BytecodeBlock;
6use crate::records::bytecode_mapping::BytecodeMapping;
7use crate::records::bytecode_type_info::BytecodeTypeInfo;
8use crate::records::bytecode_types::BytecodeTypes;
9use crate::records::cfg_info::CfgInfo;
10use crate::records::ir_block::IrBlock;
11use crate::records::ir_const::IrConst;
12use crate::records::ir_inst::IrInst;
13use crate::records::ir_op::IrOp;
14use crate::records::lowering_stats::LoweringStats;
15use crate::records::store_location_hint::StoreLocationHint;
16use crate::records::value_restore_location::ValueRestoreLocation;
17use crate::records::vm_exit_sync_info::VmExitSyncInfo;
18use alloc::vec::Vec;
19use luaur_common::records::dense_hash_map::DenseHashMap;
20
21#[allow(non_camel_case_types)]
22#[derive(Debug, Clone)]
23#[repr(C)]
24pub struct IrFunction {
25    pub blocks: Vec<IrBlock>,
26    pub instructions: Vec<IrInst>,
27    pub constants: Vec<IrConst>,
28
29    pub bc_blocks: Vec<BytecodeBlock>,
30    pub bc_types: Vec<BytecodeTypes>,
31
32    pub bc_mapping: Vec<BytecodeMapping>,
33    pub entry_block: u32,
34    pub entry_location: u32,
35    pub end_location: u32,
36
37    pub extra_native_data: Vec<u32>,
38
39    pub value_restore_ops: Vec<ValueRestoreLocation>,
40    pub valid_restore_op_blocks: Vec<u32>,
41    pub store_location_hints: DenseHashMap<u32, StoreLocationHint>,
42
43    pub vm_exit_info: DenseHashMap<u32, VmExitSyncInfo>,
44    pub block_to_vm_exit_map: DenseHashMap<u32, u32>,
45
46    pub bc_original_type_info: BytecodeTypeInfo,
47    pub bc_type_info: BytecodeTypeInfo,
48
49    pub proto: *mut luaur_vm::records::proto::Proto,
50    pub variadic: bool,
51
52    pub cfg: CfgInfo,
53
54    pub stats: *mut LoweringStats,
55
56    pub record_counters: bool,
57
58    pub jit_rng_state: u64,
59
60    pub block_exit_tags: Vec<Vec<u8>>,
61}
62
63impl luaur_common::records::dense_hash_table::DenseDefault for StoreLocationHint {
64    fn dense_default() -> Self {
65        Self {
66            op: IrOp { kind_and_index: 0 },
67            inst_idx: !0u32,
68            kind: crate::enums::ir_value_kind::IrValueKind::None,
69        }
70    }
71}
72
73impl luaur_common::records::dense_hash_table::DenseDefault for VmExitSyncInfo {
74    fn dense_default() -> Self {
75        Self {
76            reg_stores: Vec::new(),
77            block: IrOp { kind_and_index: 0 },
78            vm_exit: IrOp { kind_and_index: 0 },
79            arg_ops: luaur_common::records::small_vector::SmallVector::new(),
80        }
81    }
82}
83
84impl Default for IrFunction {
85    fn default() -> Self {
86        Self {
87            blocks: Vec::new(),
88            instructions: Vec::new(),
89            constants: Vec::new(),
90            bc_blocks: Vec::new(),
91            bc_types: Vec::new(),
92            bc_mapping: Vec::new(),
93            entry_block: 0,
94            entry_location: 0,
95            end_location: 0,
96            extra_native_data: Vec::new(),
97            value_restore_ops: Vec::new(),
98            valid_restore_op_blocks: Vec::new(),
99            // kInvalidInstIdx is ~0u32
100            store_location_hints: DenseHashMap::new(!0u32),
101            vm_exit_info: DenseHashMap::new(!0u32),
102            block_to_vm_exit_map: DenseHashMap::new(!0u32),
103            bc_original_type_info: BytecodeTypeInfo::default(),
104            bc_type_info: BytecodeTypeInfo::default(),
105            proto: core::ptr::null_mut(),
106            variadic: false,
107            cfg: CfgInfo::default(),
108            stats: core::ptr::null_mut(),
109            record_counters: false,
110            jit_rng_state: 0,
111            block_exit_tags: Vec::new(),
112        }
113    }
114}