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