1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
#ifndef EJIT_COMMON_H
#define EJIT_COMMON_H
#include <ejit/ejit.h>
#include <stdbool.h>
#define VEC_TYPE struct ejit_arg
#define VEC_NAME args
#include "vec.h"
#define VEC_TYPE int64_t
#define VEC_NAME gprs
#include "vec.h"
#define VEC_TYPE double
#define VEC_NAME fprs
#include "vec.h"
#define VEC_TYPE size_t
#define VEC_NAME labels
#include "vec.h"
enum ejit_opcode {
EJIT_OP_MOVI,
EJIT_OP_MOVI_F,
EJIT_OP_MOVI_D,
EJIT_OP_MOVR,
EJIT_OP_MOVR_F,
EJIT_OP_MOVR_D,
EJIT_OP_LDI8,
EJIT_OP_LDI16,
EJIT_OP_LDI32,
EJIT_OP_LDI64,
EJIT_OP_LDIU8,
EJIT_OP_LDIU16,
EJIT_OP_LDIU32,
EJIT_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IT_OP_ESCAPEI_L,
EJIT_OP_ESCAPEI_F,
EJIT_OP_ESCAPEI_D,
EJIT_OP_CALLI_I,
EJIT_OP_CALLI_L,
EJIT_OP_CALLI_F,
EJIT_OP_CALLI_D,
EJIT_OP_RETR,
EJIT_OP_RETI,
EJIT_OP_RETR_F,
EJIT_OP_RETR_D,
EJIT_OP_RETI_F,
EJIT_OP_RETI_D,
EJIT_OP_RETVAL,
EJIT_OP_RETVAL_F,
EJIT_OP_RETVAL_D,
EJIT_OP_START,
EJIT_OP_END,
EJIT_OPCODE_COUNT,
};
struct ejit_insn {
union {
enum ejit_opcode op;
void *addr;
};
size_t r0;
size_t r1;
union {
size_t r2;
void *p;
int64_t o;
double d;
float f;
};
};
#define VEC_TYPE struct ejit_insn
#define VEC_NAME insns
#include "vec.h"
#define VEC_TYPE enum ejit_type
#define VEC_NAME types
#include "vec.h"
struct fpr_stat {
struct ejit_fpr f;
size_t prio, fno, start, end;
};
#define VEC_NAME fpr_stats
#define VEC_TYPE struct fpr_stat
#include "vec.h"
struct gpr_stat {
struct ejit_gpr r;
size_t prio, rno, start, end;
};
#define VEC_NAME gpr_stats
#define VEC_TYPE struct gpr_stat
#include "vec.h"
struct ejit_func {
struct types sign;
struct insns insns;
struct labels labels;
enum ejit_type rtype;
struct gpr_stats gpr;
struct fpr_stats fpr;
bool use_64;
void *arena;
void *direct_call;
size_t size;
size_t prio;
size_t max_args;
};
union interp_ret {
int64_t i;
double f;
};
union interp_ret ejit_run(struct ejit_func *f, size_t argc,
struct ejit_arg args[argc],
bool run,
void ***labels_wb);
bool ejit_compile(struct ejit_func *f, bool use_64, bool im_scawed);
#endif /* EJIT_COMMON_H */
|