-
Notifications
You must be signed in to change notification settings - Fork 1
/
ir.h
99 lines (86 loc) · 1.39 KB
/
ir.h
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
struct instr {
uint64_t val;
enum {
IR_NONE,
IR_IMM,
IR_STORE,
IR_ALLOC,
IR_LOAD,
IR_CALL,
IR_RETURN,
IR_LABEL,
IR_CONDJUMP,
IR_JUMP,
// unary ops
IR_NOT,
// binary ops
IR_ADD,
// comparison
IR_CEQ,
// extension
IR_ZEXT,
// glue
IR_ASSIGN,
IR_CALLARG,
IR_IN,
IR_EXTRA,
} op;
enum {
VT_EMPTY = 1,
VT_TEMP,
VT_IMM,
VT_FUNC,
VT_LABEL,
} valtype;
};
struct iblock {
uint64_t start, end;
struct {
size_t len, cap;
uint64_t *data;
} used;
};
struct temp {
uint64_t start;
uint64_t end;
enum {
TF_PTR,
TF_INT,
} flags;
uint8_t size;
uint8_t reg;
uint64_t block;
};
struct iproc {
size_t len;
size_t cap;
struct instr *data;
uint64_t addr; // FIXME: 'addr' and 's' are only necessary because syscalls are intrinsics.
struct slice s; // Once syscalls are moved out, we can just use the decl fields and have a pointer to the declaration.
struct {
size_t len;
size_t cap;
struct iblock *data;
} blocks;
struct {
size_t len;
size_t cap;
struct temp *data;
} temps;
struct {
size_t len;
size_t cap;
uint64_t *data; // instruction offset in function
} labels;
};
struct iprocs {
size_t len, cap;
struct iproc *data;
};
struct toplevel {
struct data data;
struct data text;
struct iprocs code;
uint64_t entry;
};
void genproc(struct stack *blockstack, struct iproc *const out, const struct proc *const proc);