-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmir.nelua
588 lines (588 loc) · 24.8 KB
/
mir.nelua
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
##[[
cinclude 'c2mir.h'
linklib 'mir'
]]
global FILE: type <cimport,nodecl,forwarddecl> = @record{}
global function mir_varr_assert_fail(op: cstring, var: cstring): void <cimport,nodecl> end
global function mir_varr_error(message: cstring): void <cimport,nodecl> end
global function mir_htab_error(message: cstring): void <cimport,nodecl> end
global MIR_error_type: type <cimport,nodecl,using,ctypedef> = @enum(cint){
MIR_no_error = 0,
MIR_syntax_error = 1,
MIR_binary_io_error = 2,
MIR_alloc_error = 3,
MIR_finish_error = 4,
MIR_no_module_error = 5,
MIR_nested_module_error = 6,
MIR_no_func_error = 7,
MIR_func_error = 8,
MIR_vararg_func_error = 9,
MIR_nested_func_error = 10,
MIR_wrong_param_value_error = 11,
MIR_reserved_name_error = 12,
MIR_import_export_error = 13,
MIR_undeclared_func_reg_error = 14,
MIR_repeated_decl_error = 15,
MIR_reg_type_error = 16,
MIR_wrong_type_error = 17,
MIR_unique_reg_error = 18,
MIR_undeclared_op_ref_error = 19,
MIR_ops_num_error = 20,
MIR_call_op_error = 21,
MIR_unspec_op_error = 22,
MIR_ret_error = 23,
MIR_op_mode_error = 24,
MIR_out_op_error = 25,
MIR_invalid_insn_error = 26,
MIR_ctx_change_error = 27,
MIR_parallel_error = 28
}
global MIR_error_type_t: type = @MIR_error_type
global MIR_error_func_t: type <cimport,nodecl> = @function(MIR_error_type_t, cstring, cvarargs): void
global MIR_insn_code_t: type <cimport,nodecl,using> = @enum(cint){
MIR_MOV = 0,
MIR_FMOV = 1,
MIR_DMOV = 2,
MIR_LDMOV = 3,
MIR_EXT8 = 4,
MIR_EXT16 = 5,
MIR_EXT32 = 6,
MIR_UEXT8 = 7,
MIR_UEXT16 = 8,
MIR_UEXT32 = 9,
MIR_I2F = 10,
MIR_I2D = 11,
MIR_I2LD = 12,
MIR_UI2F = 13,
MIR_UI2D = 14,
MIR_UI2LD = 15,
MIR_F2I = 16,
MIR_D2I = 17,
MIR_LD2I = 18,
MIR_F2D = 19,
MIR_F2LD = 20,
MIR_D2F = 21,
MIR_D2LD = 22,
MIR_LD2F = 23,
MIR_LD2D = 24,
MIR_NEG = 25,
MIR_NEGS = 26,
MIR_FNEG = 27,
MIR_DNEG = 28,
MIR_LDNEG = 29,
MIR_ADD = 30,
MIR_ADDS = 31,
MIR_FADD = 32,
MIR_DADD = 33,
MIR_LDADD = 34,
MIR_SUB = 35,
MIR_SUBS = 36,
MIR_FSUB = 37,
MIR_DSUB = 38,
MIR_LDSUB = 39,
MIR_MUL = 40,
MIR_MULS = 41,
MIR_FMUL = 42,
MIR_DMUL = 43,
MIR_LDMUL = 44,
MIR_DIV = 45,
MIR_DIVS = 46,
MIR_UDIV = 47,
MIR_UDIVS = 48,
MIR_FDIV = 49,
MIR_DDIV = 50,
MIR_LDDIV = 51,
MIR_MOD = 52,
MIR_MODS = 53,
MIR_UMOD = 54,
MIR_UMODS = 55,
MIR_AND = 56,
MIR_ANDS = 57,
MIR_OR = 58,
MIR_ORS = 59,
MIR_XOR = 60,
MIR_XORS = 61,
MIR_LSH = 62,
MIR_LSHS = 63,
MIR_RSH = 64,
MIR_RSHS = 65,
MIR_URSH = 66,
MIR_URSHS = 67,
MIR_EQ = 68,
MIR_EQS = 69,
MIR_FEQ = 70,
MIR_DEQ = 71,
MIR_LDEQ = 72,
MIR_NE = 73,
MIR_NES = 74,
MIR_FNE = 75,
MIR_DNE = 76,
MIR_LDNE = 77,
MIR_LT = 78,
MIR_LTS = 79,
MIR_ULT = 80,
MIR_ULTS = 81,
MIR_FLT = 82,
MIR_DLT = 83,
MIR_LDLT = 84,
MIR_LE = 85,
MIR_LES = 86,
MIR_ULE = 87,
MIR_ULES = 88,
MIR_FLE = 89,
MIR_DLE = 90,
MIR_LDLE = 91,
MIR_GT = 92,
MIR_GTS = 93,
MIR_UGT = 94,
MIR_UGTS = 95,
MIR_FGT = 96,
MIR_DGT = 97,
MIR_LDGT = 98,
MIR_GE = 99,
MIR_GES = 100,
MIR_UGE = 101,
MIR_UGES = 102,
MIR_FGE = 103,
MIR_DGE = 104,
MIR_LDGE = 105,
MIR_JMP = 106,
MIR_BT = 107,
MIR_BTS = 108,
MIR_BF = 109,
MIR_BFS = 110,
MIR_BEQ = 111,
MIR_BEQS = 112,
MIR_FBEQ = 113,
MIR_DBEQ = 114,
MIR_LDBEQ = 115,
MIR_BNE = 116,
MIR_BNES = 117,
MIR_FBNE = 118,
MIR_DBNE = 119,
MIR_LDBNE = 120,
MIR_BLT = 121,
MIR_BLTS = 122,
MIR_UBLT = 123,
MIR_UBLTS = 124,
MIR_FBLT = 125,
MIR_DBLT = 126,
MIR_LDBLT = 127,
MIR_BLE = 128,
MIR_BLES = 129,
MIR_UBLE = 130,
MIR_UBLES = 131,
MIR_FBLE = 132,
MIR_DBLE = 133,
MIR_LDBLE = 134,
MIR_BGT = 135,
MIR_BGTS = 136,
MIR_UBGT = 137,
MIR_UBGTS = 138,
MIR_FBGT = 139,
MIR_DBGT = 140,
MIR_LDBGT = 141,
MIR_BGE = 142,
MIR_BGES = 143,
MIR_UBGE = 144,
MIR_UBGES = 145,
MIR_FBGE = 146,
MIR_DBGE = 147,
MIR_LDBGE = 148,
MIR_CALL = 149,
MIR_INLINE = 150,
MIR_SWITCH = 151,
MIR_RET = 152,
MIR_ALLOCA = 153,
MIR_BSTART = 154,
MIR_BEND = 155,
MIR_VA_ARG = 156,
MIR_VA_BLOCK_ARG = 157,
MIR_VA_START = 158,
MIR_VA_END = 159,
MIR_LABEL = 160,
MIR_UNSPEC = 161,
MIR_PHI = 162,
MIR_INVALID_INSN = 163,
MIR_INSN_BOUND = 164
}
global MIR_type_t: type <cimport,nodecl,using> = @enum(cint){
MIR_T_I8 = 0,
MIR_T_U8 = 1,
MIR_T_I16 = 2,
MIR_T_U16 = 3,
MIR_T_I32 = 4,
MIR_T_U32 = 5,
MIR_T_I64 = 6,
MIR_T_U64 = 7,
MIR_T_F = 8,
MIR_T_D = 9,
MIR_T_LD = 10,
MIR_T_P = 11,
MIR_T_BLK = 12,
MIR_T_RBLK = 17,
MIR_T_UNDEF = 18,
MIR_T_BOUND = 19
}
global function MIR_int_type_p(t: MIR_type_t): cint <cimport,nodecl> end
global function MIR_fp_type_p(t: MIR_type_t): cint <cimport,nodecl> end
global function MIR_blk_type_p(t: MIR_type_t): cint <cimport,nodecl> end
global function MIR_all_blk_type_p(t: MIR_type_t): cint <cimport,nodecl> end
global MIR_imm_t: type <cimport,nodecl> = @union{
i: int64,
u: uint64,
f: float32,
d: float64,
ld: clongdouble
}
global MIR_mem_t: type <cimport,nodecl> = @record{
type: cuchar,
scale: cuchar,
base: cuint,
index: cuint,
disp: clong
}
global MIR_insn: type <cimport,nodecl,forwarddecl,cincomplete,ctypedef> = @record{}
global MIR_label_t: type = @*MIR_insn
global MIR_name_t: type = @cstring
global MIR_op_mode_t: type <cimport,nodecl,using> = @enum(cint){
MIR_OP_UNDEF = 0,
MIR_OP_REG = 1,
MIR_OP_HARD_REG = 2,
MIR_OP_INT = 3,
MIR_OP_UINT = 4,
MIR_OP_FLOAT = 5,
MIR_OP_DOUBLE = 6,
MIR_OP_LDOUBLE = 7,
MIR_OP_REF = 8,
MIR_OP_STR = 9,
MIR_OP_MEM = 10,
MIR_OP_HARD_REG_MEM = 11,
MIR_OP_LABEL = 12,
MIR_OP_BOUND = 13
}
global MIR_item: type <cimport,nodecl,forwarddecl,cincomplete,ctypedef> = @record{}
global MIR_item_t: type = @*MIR_item
global MIR_str: type <cimport,nodecl,ctypedef> = @record{
len: csize,
s: cstring
}
global MIR_str_t: type = @MIR_str
global MIR_op_t: type <cimport,nodecl> = @record{
data: pointer,
mode: MIR_op_mode_t,
value_mode: MIR_op_mode_t,
u: union{
reg: cuint,
hard_reg: cuint,
i: int64,
u: uint64,
f: float32,
d: float64,
ld: clongdouble,
ref: MIR_item_t,
str: MIR_str_t,
mem: MIR_mem_t,
hard_reg_mem: MIR_mem_t,
label: MIR_label_t
}
}
global MIR_insn_t: type = @*MIR_insn
MIR_insn = @record{
data: pointer,
code: MIR_insn_code_t,
nops: cuint,
ops: [1]MIR_op_t
}
global DLIST_MIR_insn_t: type <cimport,nodecl> = @record{
head: MIR_insn_t,
tail: MIR_insn_t
}
global function DLIST_MIR_insn_t_init(list: *DLIST_MIR_insn_t): void <cimport,nodecl> end
global function DLIST_MIR_insn_t_head(list: *DLIST_MIR_insn_t): MIR_insn_t <cimport,nodecl> end
global function DLIST_MIR_insn_t_tail(list: *DLIST_MIR_insn_t): MIR_insn_t <cimport,nodecl> end
global function DLIST_MIR_insn_t_prev(elem: MIR_insn_t): MIR_insn_t <cimport,nodecl> end
global function DLIST_MIR_insn_t_next(elem: MIR_insn_t): MIR_insn_t <cimport,nodecl> end
global function DLIST_MIR_insn_t_el(list: *DLIST_MIR_insn_t, n: cint): MIR_insn_t <cimport,nodecl> end
global function DLIST_MIR_insn_t_prepend(list: *DLIST_MIR_insn_t, elem: MIR_insn_t): void <cimport,nodecl> end
global function DLIST_MIR_insn_t_append(list: *DLIST_MIR_insn_t, elem: MIR_insn_t): void <cimport,nodecl> end
global function DLIST_MIR_insn_t_insert_before(list: *DLIST_MIR_insn_t, before: MIR_insn_t, elem: MIR_insn_t): void <cimport,nodecl> end
global function DLIST_MIR_insn_t_insert_after(list: *DLIST_MIR_insn_t, after: MIR_insn_t, elem: MIR_insn_t): void <cimport,nodecl> end
global function DLIST_MIR_insn_t_remove(list: *DLIST_MIR_insn_t, elem: MIR_insn_t): void <cimport,nodecl> end
global function DLIST_MIR_insn_t_length(list: *DLIST_MIR_insn_t): csize <cimport,nodecl> end
global MIR_var: type <cimport,nodecl,ctypedef> = @record{
type: MIR_type_t,
name: cstring,
size: csize
}
global MIR_var_t: type = @MIR_var
global VARR_MIR_var_t: type <cimport,nodecl> = @record{
els_num: csize,
size: csize,
varr: *MIR_var_t
}
global function VARR_MIR_var_tcreate(varr: **VARR_MIR_var_t, size: csize): void <cimport,nodecl> end
global function VARR_MIR_var_tdestroy(varr: **VARR_MIR_var_t): void <cimport,nodecl> end
global function VARR_MIR_var_tlength(varr: *VARR_MIR_var_t): csize <cimport,nodecl> end
global function VARR_MIR_var_taddr(varr: *VARR_MIR_var_t): *MIR_var_t <cimport,nodecl> end
global function VARR_MIR_var_tlast(varr: *VARR_MIR_var_t): MIR_var_t <cimport,nodecl> end
global function VARR_MIR_var_tget(varr: *VARR_MIR_var_t, ix: csize): MIR_var_t <cimport,nodecl> end
global function VARR_MIR_var_tset(varr: *VARR_MIR_var_t, ix: csize, obj: MIR_var_t): void <cimport,nodecl> end
global function VARR_MIR_var_ttrunc(varr: *VARR_MIR_var_t, size: csize): void <cimport,nodecl> end
global function VARR_MIR_var_texpand(varr: *VARR_MIR_var_t, size: csize): cint <cimport,nodecl> end
global function VARR_MIR_var_ttailor(varr: *VARR_MIR_var_t, size: csize): void <cimport,nodecl> end
global function VARR_MIR_var_tpush(varr: *VARR_MIR_var_t, obj: MIR_var_t): void <cimport,nodecl> end
global function VARR_MIR_var_tpush_arr(varr: *VARR_MIR_var_t, objs: *MIR_var_t, len: csize): void <cimport,nodecl> end
global function VARR_MIR_var_tpop(varr: *VARR_MIR_var_t): MIR_var_t <cimport,nodecl> end
global MIR_func: type <cimport,nodecl,ctypedef> = @record{
name: cstring,
func_item: MIR_item_t,
original_vars_num: csize,
insns: DLIST_MIR_insn_t,
original_insns: DLIST_MIR_insn_t,
nres: uint32,
nargs: uint32,
last_temp_num: uint32,
n_inlines: uint32,
res_types: *MIR_type_t,
vararg_p: cchar,
expr_p: cchar,
vars: *VARR_MIR_var_t,
machine_code: pointer,
call_addr: pointer,
internal: pointer
}
global MIR_func_t: type = @*MIR_func
global MIR_proto: type <cimport,nodecl,ctypedef> = @record{
name: cstring,
nres: uint32,
res_types: *MIR_type_t,
vararg_p: cchar,
args: *VARR_MIR_var_t
}
global MIR_proto_t: type = @*MIR_proto
global MIR_data: type <cimport,nodecl,ctypedef> = @record{
name: cstring,
el_type: MIR_type_t,
nel: csize,
u: union{
d: clongdouble,
els: [1]uint8
}
}
global MIR_data_t: type = @*MIR_data
global MIR_ref_data: type <cimport,nodecl,ctypedef> = @record{
name: cstring,
ref_item: MIR_item_t,
disp: int64,
load_addr: pointer
}
global MIR_ref_data_t: type = @*MIR_ref_data
global MIR_expr_data: type <cimport,nodecl,ctypedef> = @record{
name: cstring,
expr_item: MIR_item_t,
load_addr: pointer
}
global MIR_expr_data_t: type = @*MIR_expr_data
global MIR_bss: type <cimport,nodecl,ctypedef> = @record{
name: cstring,
len: uint64
}
global MIR_bss_t: type = @*MIR_bss
global MIR_module: type <cimport,nodecl,forwarddecl,cincomplete,ctypedef> = @record{}
global MIR_module_t: type = @*MIR_module
global MIR_item_type_t: type <cimport,nodecl,using> = @enum(cint){
MIR_func_item = 0,
MIR_proto_item = 1,
MIR_import_item = 2,
MIR_export_item = 3,
MIR_forward_item = 4,
MIR_data_item = 5,
MIR_ref_data_item = 6,
MIR_expr_data_item = 7,
MIR_bss_item = 8
}
MIR_item = @record{
data: pointer,
module: MIR_module_t,
item_type: MIR_item_type_t,
ref_def: MIR_item_t,
addr: pointer,
export_p: cchar,
section_head_p: cchar,
u: union{
func: MIR_func_t,
proto: MIR_proto_t,
import_id: MIR_name_t,
export_id: MIR_name_t,
forward_id: MIR_name_t,
data: MIR_data_t,
ref_data: MIR_ref_data_t,
expr_data: MIR_expr_data_t,
bss: MIR_bss_t
}
}
global DLIST_MIR_item_t: type <cimport,nodecl> = @record{
head: MIR_item_t,
tail: MIR_item_t
}
global function DLIST_MIR_item_t_init(list: *DLIST_MIR_item_t): void <cimport,nodecl> end
global function DLIST_MIR_item_t_head(list: *DLIST_MIR_item_t): MIR_item_t <cimport,nodecl> end
global function DLIST_MIR_item_t_tail(list: *DLIST_MIR_item_t): MIR_item_t <cimport,nodecl> end
global function DLIST_MIR_item_t_prev(elem: MIR_item_t): MIR_item_t <cimport,nodecl> end
global function DLIST_MIR_item_t_next(elem: MIR_item_t): MIR_item_t <cimport,nodecl> end
global function DLIST_MIR_item_t_el(list: *DLIST_MIR_item_t, n: cint): MIR_item_t <cimport,nodecl> end
global function DLIST_MIR_item_t_prepend(list: *DLIST_MIR_item_t, elem: MIR_item_t): void <cimport,nodecl> end
global function DLIST_MIR_item_t_append(list: *DLIST_MIR_item_t, elem: MIR_item_t): void <cimport,nodecl> end
global function DLIST_MIR_item_t_insert_before(list: *DLIST_MIR_item_t, before: MIR_item_t, elem: MIR_item_t): void <cimport,nodecl> end
global function DLIST_MIR_item_t_insert_after(list: *DLIST_MIR_item_t, after: MIR_item_t, elem: MIR_item_t): void <cimport,nodecl> end
global function DLIST_MIR_item_t_remove(list: *DLIST_MIR_item_t, elem: MIR_item_t): void <cimport,nodecl> end
global function DLIST_MIR_item_t_length(list: *DLIST_MIR_item_t): csize <cimport,nodecl> end
MIR_module = @record{
data: pointer,
name: cstring,
items: DLIST_MIR_item_t,
last_temp_item_num: uint32
}
global DLIST_MIR_module_t: type <cimport,nodecl> = @record{
head: MIR_module_t,
tail: MIR_module_t
}
global function DLIST_MIR_module_t_init(list: *DLIST_MIR_module_t): void <cimport,nodecl> end
global function DLIST_MIR_module_t_head(list: *DLIST_MIR_module_t): MIR_module_t <cimport,nodecl> end
global function DLIST_MIR_module_t_tail(list: *DLIST_MIR_module_t): MIR_module_t <cimport,nodecl> end
global function DLIST_MIR_module_t_prev(elem: MIR_module_t): MIR_module_t <cimport,nodecl> end
global function DLIST_MIR_module_t_next(elem: MIR_module_t): MIR_module_t <cimport,nodecl> end
global function DLIST_MIR_module_t_el(list: *DLIST_MIR_module_t, n: cint): MIR_module_t <cimport,nodecl> end
global function DLIST_MIR_module_t_prepend(list: *DLIST_MIR_module_t, elem: MIR_module_t): void <cimport,nodecl> end
global function DLIST_MIR_module_t_append(list: *DLIST_MIR_module_t, elem: MIR_module_t): void <cimport,nodecl> end
global function DLIST_MIR_module_t_insert_before(list: *DLIST_MIR_module_t, before: MIR_module_t, elem: MIR_module_t): void <cimport,nodecl> end
global function DLIST_MIR_module_t_insert_after(list: *DLIST_MIR_module_t, after: MIR_module_t, elem: MIR_module_t): void <cimport,nodecl> end
global function DLIST_MIR_module_t_remove(list: *DLIST_MIR_module_t, elem: MIR_module_t): void <cimport,nodecl> end
global function DLIST_MIR_module_t_length(list: *DLIST_MIR_module_t): csize <cimport,nodecl> end
global MIR_context: type <cimport,nodecl,forwarddecl,ctypedef> = @record{}
global MIR_context_t: type = @*MIR_context
global function MIR_FP_branch_code_p(code: MIR_insn_code_t): cint <cimport,nodecl> end
global function MIR_call_code_p(code: MIR_insn_code_t): cint <cimport,nodecl> end
global function MIR_int_branch_code_p(code: MIR_insn_code_t): cint <cimport,nodecl> end
global function MIR_branch_code_p(code: MIR_insn_code_t): cint <cimport,nodecl> end
global function MIR_init(): MIR_context_t <cimport,nodecl> end
global function MIR_finish(ctx: MIR_context_t): void <cimport,nodecl> end
global function MIR_new_module(ctx: MIR_context_t, name: cstring): MIR_module_t <cimport,nodecl> end
global function MIR_get_module_list(ctx: MIR_context_t): *DLIST_MIR_module_t <cimport,nodecl> end
global function MIR_new_import(ctx: MIR_context_t, name: cstring): MIR_item_t <cimport,nodecl> end
global function MIR_new_export(ctx: MIR_context_t, name: cstring): MIR_item_t <cimport,nodecl> end
global function MIR_new_forward(ctx: MIR_context_t, name: cstring): MIR_item_t <cimport,nodecl> end
global function MIR_new_bss(ctx: MIR_context_t, name: cstring, len: csize): MIR_item_t <cimport,nodecl> end
global function MIR_new_data(ctx: MIR_context_t, name: cstring, el_type: MIR_type_t, nel: csize, els: pointer): MIR_item_t <cimport,nodecl> end
global function MIR_new_string_data(ctx: MIR_context_t, name: cstring, str: MIR_str_t): MIR_item_t <cimport,nodecl> end
global function MIR_new_ref_data(ctx: MIR_context_t, name: cstring, item: MIR_item_t, disp: int64): MIR_item_t <cimport,nodecl> end
global function MIR_new_expr_data(ctx: MIR_context_t, name: cstring, expr_item: MIR_item_t): MIR_item_t <cimport,nodecl> end
global function MIR_new_proto_arr(ctx: MIR_context_t, name: cstring, nres: csize, res_types: *MIR_type_t, nargs: csize, vars: *MIR_var_t): MIR_item_t <cimport,nodecl> end
global function MIR_new_proto(ctx: MIR_context_t, name: cstring, nres: csize, res_types: *MIR_type_t, nargs: csize, ...: cvarargs): MIR_item_t <cimport,nodecl> end
global function MIR_new_vararg_proto_arr(ctx: MIR_context_t, name: cstring, nres: csize, res_types: *MIR_type_t, nargs: csize, vars: *MIR_var_t): MIR_item_t <cimport,nodecl> end
global function MIR_new_vararg_proto(ctx: MIR_context_t, name: cstring, nres: csize, res_types: *MIR_type_t, nargs: csize, ...: cvarargs): MIR_item_t <cimport,nodecl> end
global function MIR_new_func_arr(ctx: MIR_context_t, name: cstring, nres: csize, res_types: *MIR_type_t, nargs: csize, vars: *MIR_var_t): MIR_item_t <cimport,nodecl> end
global function MIR_new_func(ctx: MIR_context_t, name: cstring, nres: csize, res_types: *MIR_type_t, nargs: csize, ...: cvarargs): MIR_item_t <cimport,nodecl> end
global function MIR_new_vararg_func_arr(ctx: MIR_context_t, name: cstring, nres: csize, res_types: *MIR_type_t, nargs: csize, vars: *MIR_var_t): MIR_item_t <cimport,nodecl> end
global function MIR_new_vararg_func(ctx: MIR_context_t, name: cstring, nres: csize, res_types: *MIR_type_t, nargs: csize, ...: cvarargs): MIR_item_t <cimport,nodecl> end
global function MIR_item_name(ctx: MIR_context_t, item: MIR_item_t): cstring <cimport,nodecl> end
global function MIR_new_func_reg(ctx: MIR_context_t, func: MIR_func_t, type: MIR_type_t, name: cstring): cuint <cimport,nodecl> end
global function MIR_finish_func(ctx: MIR_context_t): void <cimport,nodecl> end
global function MIR_finish_module(ctx: MIR_context_t): void <cimport,nodecl> end
global function MIR_get_error_func(ctx: MIR_context_t): MIR_error_func_t <cimport,nodecl> end
global function MIR_set_error_func(ctx: MIR_context_t, func: MIR_error_func_t): void <cimport,nodecl> end
global function MIR_new_insn_arr(ctx: MIR_context_t, code: MIR_insn_code_t, nops: csize, ops: *MIR_op_t): MIR_insn_t <cimport,nodecl> end
global function MIR_new_insn(ctx: MIR_context_t, code: MIR_insn_code_t, ...: cvarargs): MIR_insn_t <cimport,nodecl> end
global function MIR_new_call_insn(ctx: MIR_context_t, nops: csize, ...: cvarargs): MIR_insn_t <cimport,nodecl> end
global function MIR_new_ret_insn(ctx: MIR_context_t, nops: csize, ...: cvarargs): MIR_insn_t <cimport,nodecl> end
global function MIR_copy_insn(ctx: MIR_context_t, insn: MIR_insn_t): MIR_insn_t <cimport,nodecl> end
global function MIR_insn_name(ctx: MIR_context_t, code: MIR_insn_code_t): cstring <cimport,nodecl> end
global function MIR_insn_nops(ctx: MIR_context_t, insn: MIR_insn_t): csize <cimport,nodecl> end
global function MIR_insn_op_mode(ctx: MIR_context_t, insn: MIR_insn_t, nop: csize, out_p: *cint): MIR_op_mode_t <cimport,nodecl> end
global function MIR_new_label(ctx: MIR_context_t): MIR_insn_t <cimport,nodecl> end
global function MIR_reg(ctx: MIR_context_t, reg_name: cstring, func: MIR_func_t): cuint <cimport,nodecl> end
global function MIR_reg_type(ctx: MIR_context_t, reg: cuint, func: MIR_func_t): MIR_type_t <cimport,nodecl> end
global function MIR_reg_name(ctx: MIR_context_t, reg: cuint, func: MIR_func_t): cstring <cimport,nodecl> end
global function MIR_new_reg_op(ctx: MIR_context_t, reg: cuint): MIR_op_t <cimport,nodecl> end
global function MIR_new_int_op(ctx: MIR_context_t, v: int64): MIR_op_t <cimport,nodecl> end
global function MIR_new_uint_op(ctx: MIR_context_t, v: uint64): MIR_op_t <cimport,nodecl> end
global function MIR_new_float_op(ctx: MIR_context_t, v: float32): MIR_op_t <cimport,nodecl> end
global function MIR_new_double_op(ctx: MIR_context_t, v: float64): MIR_op_t <cimport,nodecl> end
global function MIR_new_ldouble_op(ctx: MIR_context_t, v: clongdouble): MIR_op_t <cimport,nodecl> end
global function MIR_new_ref_op(ctx: MIR_context_t, item: MIR_item_t): MIR_op_t <cimport,nodecl> end
global function MIR_new_str_op(ctx: MIR_context_t, str: MIR_str_t): MIR_op_t <cimport,nodecl> end
global function MIR_new_mem_op(ctx: MIR_context_t, type: MIR_type_t, disp: clong, base: cuint, index: cuint, scale: cuchar): MIR_op_t <cimport,nodecl> end
global function MIR_new_label_op(ctx: MIR_context_t, label: MIR_label_t): MIR_op_t <cimport,nodecl> end
global function MIR_op_eq_p(ctx: MIR_context_t, op1: MIR_op_t, op2: MIR_op_t): cint <cimport,nodecl> end
global function MIR_op_hash_step(ctx: MIR_context_t, h: cuint, op: MIR_op_t): cuint <cimport,nodecl> end
global function MIR_append_insn(ctx: MIR_context_t, func: MIR_item_t, insn: MIR_insn_t): void <cimport,nodecl> end
global function MIR_prepend_insn(ctx: MIR_context_t, func: MIR_item_t, insn: MIR_insn_t): void <cimport,nodecl> end
global function MIR_insert_insn_after(ctx: MIR_context_t, func: MIR_item_t, after: MIR_insn_t, insn: MIR_insn_t): void <cimport,nodecl> end
global function MIR_insert_insn_before(ctx: MIR_context_t, func: MIR_item_t, before: MIR_insn_t, insn: MIR_insn_t): void <cimport,nodecl> end
global function MIR_remove_insn(ctx: MIR_context_t, func: MIR_item_t, insn: MIR_insn_t): void <cimport,nodecl> end
global function MIR_change_module_ctx(old_ctx: MIR_context_t, m: MIR_module_t, new_ctx: MIR_context_t): void <cimport,nodecl> end
global function MIR_reverse_branch_code(code: MIR_insn_code_t): MIR_insn_code_t <cimport,nodecl> end
global function MIR_type_str(ctx: MIR_context_t, tp: MIR_type_t): cstring <cimport,nodecl> end
global function MIR_output_op(ctx: MIR_context_t, f: *FILE, op: MIR_op_t, func: MIR_func_t): void <cimport,nodecl> end
global function MIR_output_insn(ctx: MIR_context_t, f: *FILE, insn: MIR_insn_t, func: MIR_func_t, newline_p: cint): void <cimport,nodecl> end
global function MIR_output_item(ctx: MIR_context_t, f: *FILE, item: MIR_item_t): void <cimport,nodecl> end
global function MIR_output_module(ctx: MIR_context_t, f: *FILE, module: MIR_module_t): void <cimport,nodecl> end
global function MIR_output(ctx: MIR_context_t, f: *FILE): void <cimport,nodecl> end
global function MIR_write(ctx: MIR_context_t, f: *FILE): void <cimport,nodecl> end
global function MIR_write_module(ctx: MIR_context_t, f: *FILE, module: MIR_module_t): void <cimport,nodecl> end
global function MIR_read(ctx: MIR_context_t, f: *FILE): void <cimport,nodecl> end
global function MIR_write_with_func(ctx: MIR_context_t, writer_func: function(MIR_context_t, uint8): cint): void <cimport,nodecl> end
global function MIR_write_module_with_func(ctx: MIR_context_t, writer_func: function(MIR_context_t, uint8): cint, module: MIR_module_t): void <cimport,nodecl> end
global function MIR_read_with_func(ctx: MIR_context_t, reader_func: function(MIR_context_t): cint): void <cimport,nodecl> end
global function MIR_scan_string(ctx: MIR_context_t, str: cstring): void <cimport,nodecl> end
global function MIR_get_global_item(ctx: MIR_context_t, name: cstring): MIR_item_t <cimport,nodecl> end
global function MIR_load_module(ctx: MIR_context_t, m: MIR_module_t): void <cimport,nodecl> end
global function MIR_load_external(ctx: MIR_context_t, name: cstring, addr: pointer): void <cimport,nodecl> end
global function MIR_link(ctx: MIR_context_t, set_interface: function(MIR_context_t, MIR_item_t): void, import_resolver: function(cstring): pointer): void <cimport,nodecl> end
global MIR_val_t: type <cimport,nodecl> = @union{
ic: MIR_insn_code_t,
a: pointer,
i: int64,
u: uint64,
f: float32,
d: float64,
ld: clongdouble
}
global function MIR_interp(ctx: MIR_context_t, func_item: MIR_item_t, results: *MIR_val_t, nargs: csize, ...: cvarargs): void <cimport,nodecl> end
global function MIR_interp_arr(ctx: MIR_context_t, func_item: MIR_item_t, results: *MIR_val_t, nargs: csize, vals: *MIR_val_t): void <cimport,nodecl> end
global function MIR_interp_arr_varg(ctx: MIR_context_t, func_item: MIR_item_t, results: *MIR_val_t, nargs: csize, vals: *MIR_val_t, va: cvalist): void <cimport,nodecl> end
global function MIR_set_interp_interface(ctx: MIR_context_t, func_item: MIR_item_t): void <cimport,nodecl> end
global MIR_code_reloc: type <cimport,nodecl,ctypedef> = @record{
offset: csize,
value: pointer
}
global MIR_code_reloc_t: type = @MIR_code_reloc
global c2mir_macro_command: type <cimport,nodecl,ctypedef> = @record{
def_p: cint,
name: cstring,
def: cstring
}
global c2mir_options: type <cimport,nodecl,ctypedef> = @record{
message_file: *FILE,
debug_p: cint,
verbose_p: cint,
ignore_warnings_p: cint,
no_prepro_p: cint,
prepro_only_p: cint,
syntax_only_p: cint,
pedantic_p: cint,
asm_p: cint,
object_p: cint,
module_num: csize,
prepro_output_file: *FILE,
output_file_name: cstring,
macro_commands_num: csize,
include_dirs_num: csize,
macro_commands: *c2mir_macro_command,
include_dirs: *cstring
}
global function c2mir_init(ctx: MIR_context_t): void <cimport,nodecl> end
global function c2mir_finish(ctx: MIR_context_t): void <cimport,nodecl> end
global function c2mir_compile(ctx: MIR_context_t, ops: *c2mir_options, getc_func: function(pointer): cint, getc_data: pointer, source_name: cstring, output_file: *FILE): cint <cimport,nodecl> end
global function MIR_init(): MIR_context_t <cimport, nodecl> end