-
Notifications
You must be signed in to change notification settings - Fork 0
/
codegen.h
86 lines (63 loc) · 1.28 KB
/
codegen.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
#ifndef CODEGEN_H
#define CODEGEN_H
#include "ir/ir.h"
#include <stddef.h>
enum codegen_unit_ty {
CODEGEN_UNIT_TY_AARCH64,
CODEGEN_UNIT_TY_EEP,
};
struct codegen_var {
int tmp;
};
struct codegen_function {
struct codegen_unit *unit;
bool prologue;
size_t stack_size;
size_t instr_count;
struct instr* first;
struct instr* last;
};
enum codegen_entry_ty {
CODEGEN_ENTRY_TY_FUNC,
CODEGEN_ENTRY_TY_STRING,
CODEGEN_ENTRY_TY_CONST_DATA,
CODEGEN_ENTRY_TY_DATA,
CODEGEN_ENTRY_TY_DECL,
};
struct codegen_data {
void *data;
size_t len_data;
};
struct codegen_entry {
enum codegen_entry_ty ty;
size_t glb_id;
const char *name;
union {
struct codegen_function func;
struct codegen_data data;
const char *str;
};
};
struct codegen_unit {
enum codegen_unit_ty ty;
struct arena_allocator *arena;
struct codegen_entry *entries;
size_t num_entries;
// the size of the element within the union, so it can be allocated
size_t instr_size;
};
struct aarch64_instr;
struct eep_instr;
struct instr {
size_t id;
struct instr *pred;
struct instr *succ;
struct relocation *reloc;
union {
void *p;
struct aarch64_instr *aarch64;
struct eep_instr *eep;
};
};
struct instr *alloc_instr(struct codegen_function *func);
#endif