-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.h
116 lines (105 loc) · 2.37 KB
/
tree.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
111
112
113
114
115
116
/*
* tree.h - Definitions for intermediate representation (IR) trees.
*
*/
#ifndef TREE_H
#define TREE_H
#include "temp.h"
typedef struct T_stm_ *T_stm;
typedef struct T_exp_ *T_exp;
typedef struct T_expList_ *T_expList;
struct T_expList_ {
T_exp head;
T_expList tail;
};
typedef struct T_stmList_ *T_stmList;
struct T_stmList_ {
T_stm head;
T_stmList tail;
};
typedef enum {
T_plus,
T_minus,
T_mul,
T_div,
T_and,
T_or,
T_lshift,
T_rshift,
T_arshift,
T_xor
} T_binOp;
typedef enum {
T_eq,
T_ne,
T_lt,
T_gt,
T_le,
T_ge,
T_ult,
T_ule,
T_ugt,
T_uge
} T_relOp;
struct T_stm_ {
enum { T_SEQ, T_LABEL, T_JUMP, T_CJUMP, T_MOVE, T_EXP } kind;
union {
struct {
T_stm left, right;
} SEQ;
Temp_label LABEL;
struct {
T_exp exp;
Temp_labelList jumps;
} JUMP;
struct {
T_relOp op;
T_exp left, right;
Temp_label true, false;
} CJUMP;
struct {
T_exp dst, src;
} MOVE;
T_exp EXP;
} u;
};
struct T_exp_ {
enum { T_BINOP, T_MEM, T_TEMP, T_ESEQ, T_NAME, T_CONST, T_CALL } kind;
union {
struct {
T_binOp op;
T_exp left, right;
} BINOP;
T_exp MEM;
Temp_temp TEMP;
struct {
T_stm stm;
T_exp exp;
} ESEQ;
Temp_label NAME;
int CONST;
struct {
T_exp fun;
T_expList args;
} CALL;
} u;
};
T_expList T_ExpList(T_exp head, T_expList tail);
T_stmList T_StmList(T_stm head, T_stmList tail);
T_stm T_Seq(T_stm left, T_stm right);
T_stm T_Label(Temp_label);
T_stm T_Jump(T_exp exp, Temp_labelList labels);
T_stm T_Cjump(T_relOp op, T_exp left, T_exp right, Temp_label true,
Temp_label false);
T_stm T_Move(T_exp, T_exp);
T_stm T_Exp(T_exp);
T_exp T_Binop(T_binOp, T_exp, T_exp);
T_exp T_Mem(T_exp);
T_exp T_Temp(Temp_temp);
T_exp T_Eseq(T_stm, T_exp);
T_exp T_Name(Temp_label);
T_exp T_Const(int);
T_exp T_Call(T_exp, T_expList);
T_relOp T_notRel(T_relOp); /* a op b == not(a notRel(op) b) */
T_relOp T_commute(T_relOp); /* a op b == b commute(op) a */
#endif