1pub const OFF_REGISTER_COUNT: i32 = 8;
5pub const OFF_PC: i32 = 12;
6pub const OFF_BUDGET: i32 = 16;
7pub const OFF_FUNCTION: i32 = 20;
8pub const OFF_EXIT_KIND: i32 = 24;
9pub const OFF_RETURN_REG: i32 = 28;
10pub const OFF_CALL_DEPTH: i32 = 32;
11pub const OFF_CALL_STACK: i32 = 40;
12pub const OFF_WRITTEN: i32 = 48;
15pub const OFF_AS_BOOL: i32 = 80;
18pub const OFF_AS_UNIT: i32 = 112;
21pub const OFF_ENTRY_BOOL: i32 = 144;
26pub const OFF_ENTRY_UNIT: i32 = 176;
27pub const OFF_SPILL: i32 = 208;
30pub const OFF_SPILL_STRIDE: i32 = 216;
31pub const OFF_AS_FLOAT: i32 = 224;
33pub const OFF_ENTRY_FLOAT: i32 = 256;
35
36pub const REC_RETURN_PC: i32 = 0;
38pub const REC_RETURN_FN: i32 = 4;
39pub const REC_DEST: i32 = 8;
40pub const REC_CALLER_REGS: i32 = 12;
41pub const REC_WRITTEN: i32 = 16;
42pub const REC_AS_BOOL: i32 = 48;
43pub const REC_AS_UNIT: i32 = 80;
44pub const REC_AS_FLOAT: i32 = 112;
45
46pub const MAX_JIT_CALL_DEPTH: usize = 32;
48
49#[repr(C)]
51#[derive(Clone, Copy, Debug)]
52pub struct JitCallRecord {
53 pub return_pc: u32,
54 pub return_function: u32,
55 pub dest_reg: u32,
56 pub caller_register_count: u32,
57 pub written: [u64; 4],
59 pub as_bool: [u64; 4],
60 pub as_unit: [u64; 4],
61 pub as_float: [u64; 4],
62}
63
64#[repr(C)]
70pub struct JitFrame {
71 pub slots: *mut i64,
72 pub register_count: u32,
73 pub pc: u32,
74 pub budget: u32,
75 pub function: u32,
76 pub exit_kind: u32,
77 pub return_reg: u32,
78 pub call_depth: u32,
79 pub call_stack: *mut JitCallRecord,
80 pub written: [u64; 4],
83 pub as_bool: [u64; 4],
86 pub as_unit: [u64; 4],
88 pub entry_as_bool: [u64; 4],
90 pub entry_as_unit: [u64; 4],
92 pub spill: *mut i64,
95 pub spill_stride: u32,
96 pub as_float: [u64; 4],
99 pub entry_as_float: [u64; 4],
101}
102
103pub type JitEntry = unsafe extern "C" fn(*mut JitFrame);
104
105#[cfg(test)]
106mod tests {
107 use super::*;
108
109 #[test]
110 fn tag_words_sit_where_the_compiler_stores_them() {
111 assert_eq!(
112 std::mem::offset_of!(JitFrame, written),
113 OFF_WRITTEN as usize
114 );
115 assert_eq!(
116 std::mem::offset_of!(JitFrame, as_bool),
117 OFF_AS_BOOL as usize
118 );
119 assert_eq!(
120 std::mem::offset_of!(JitFrame, as_unit),
121 OFF_AS_UNIT as usize
122 );
123 assert_eq!(
124 std::mem::offset_of!(JitFrame, entry_as_bool),
125 OFF_ENTRY_BOOL as usize
126 );
127 assert_eq!(
128 std::mem::offset_of!(JitFrame, entry_as_unit),
129 OFF_ENTRY_UNIT as usize
130 );
131 assert_eq!(std::mem::offset_of!(JitFrame, spill), OFF_SPILL as usize);
132 assert_eq!(
133 std::mem::offset_of!(JitFrame, spill_stride),
134 OFF_SPILL_STRIDE as usize
135 );
136 assert_eq!(
137 std::mem::offset_of!(JitFrame, as_float),
138 OFF_AS_FLOAT as usize
139 );
140 assert_eq!(
141 std::mem::offset_of!(JitFrame, entry_as_float),
142 OFF_ENTRY_FLOAT as usize
143 );
144 assert_eq!(
145 std::mem::offset_of!(JitCallRecord, written),
146 REC_WRITTEN as usize
147 );
148 assert_eq!(
149 std::mem::offset_of!(JitCallRecord, as_bool),
150 REC_AS_BOOL as usize
151 );
152 assert_eq!(
153 std::mem::offset_of!(JitCallRecord, as_unit),
154 REC_AS_UNIT as usize
155 );
156 assert_eq!(
157 std::mem::offset_of!(JitCallRecord, as_float),
158 REC_AS_FLOAT as usize
159 );
160 }
161}