-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.h
110 lines (74 loc) · 1.9 KB
/
code.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
100
101
102
103
104
105
106
107
108
109
110
#ifndef __IC_HEADER__
#define __IC_HEADER__
#include "ast.h"
typedef char* var;
typedef char* label;
typedef char* regist;
typedef enum { nuCOPY, nuADD, nuSUB, nuMULT, nuDIV, nuMOD, nuAND, nuOR, nuGOTO, nuLT, nuLTE, nuGT, nuGTE, nuEQ, nuDIFF, nuIF_F, nuLABEL, nuREAD, nuWRITE } instr_kind;
struct _InstrList
{
struct _Instr *instr;
struct _InstrList *next;
};
struct _Instr
{
instr_kind kind;
struct _Address* addr1;
struct _Address* addr2;
struct _Address* addr3;
};
struct _Address
{
enum
{
ADDR_CONST,
ADDR_REGIST
} kind;
union
{
int val;
regist reg;
} core;
};
struct _Pair
{
struct _Address* first;
struct _InstrList* second;
};
struct _RegList
{
regist reg;
var id;
int reg_num;
struct _RegList* next;
};
typedef struct _Address Address;
typedef struct _Instr Instr;
typedef struct _InstrList InstrList;
typedef struct _Pair Pair;
typedef struct _RegList RegList;
extern RegList* reg_list;
extern int reg_count, label_count;
InstrList* genIC(StmtList* ast);
InstrList* compile_attrib(Attrib* attrib);
Pair* compile_expr(Expr* expr);
InstrList* compile_if(If* _if, int make_exit, Address* exit_addr);
InstrList* compile_while(While* _while);
Pair* mk_pair(Address* first, InstrList* second);
InstrList* mk_instrList(Instr* instr, InstrList* next);
Instr* mk_instr(instr_kind kind, Address* addr1, Address* addr2, Address* addr3);
Address* mk_address_const(int val);
Address* mk_address_regist(regist reg);
instr_kind get_binop_instr(Binop op);
void printIC(InstrList* ic);
void print_operation(Instr* instr, char* op);
void print_address(Address* addr, int eol);
InstrList* list_concat(InstrList* lhs, InstrList* rhs);
InstrList* list_append(InstrList* list, Instr* instr);
label new_label();
regist reg_get(var id);
void reg_free();
regist reg_alloc();
RegList* mk_regList(regist reg, var id, RegList* next);
void reg_assoc(regist reg, var id);
#endif