-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAST.h
228 lines (198 loc) · 4.65 KB
/
AST.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
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
#pragma once
#include <string>
#include <vector>
// #include "AST.h"
using namespace std;
// union NodeTypes
// {
// LITERAL LIT;
// FDECL FD;
// FCALL FC;
// bool NUL;
// NodeTypes() = default;
// ~NodeTypes() = default;
// };
// struct AbstractNode
// {
// NodeTypes node;
// string type;
// AbstractNode()
// {
// node.NUL = true;
// type = "empty";
// // initialize union with empty node
// // initialize stored node type string with "empty"
// }
// };
class x86 {
public:
string type = "o";
string out = "section .text\n ";
string data = "\nsection .data\n\n NEWLINE db 10\n";
string bss = "\nsection .bss\n\n";
vector<string> vars;
int constants = 0;
void add(string addit);
string constant(string ctype, string cvalue);
string variable(string vtype, string vname, string vvalue, bool variate, bool islcl);
string point(string vtype, string vname, string vvalue);
string deref(string vtype, string vname, string vvalue);
void sout();
};
class AbstractNode;
class Node {
public:
string _type;
string _value;
vector<AbstractNode> _data;
// vector<Node> _data2;
Node() = default;
Node(string type, string value, vector<AbstractNode> data);
// void out(string filename);
// ~Node();
};
// class nll: public Node {
// public:
// nll(string type, string value, vector<Node*> data);
// // ~nll();
// };
class LITERAL : public Node {
public:
string ctype;
LITERAL(string type, string value, vector<AbstractNode> data);
LITERAL() = default;
// ~Literal();
string codegen(string otype, x86* a);
};
class FCALL : public Node {
public:
FCALL(string type, string value, vector<AbstractNode> data);
FCALL() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class FDECL : public Node {
public:
vector<AbstractNode> body;
string rtype;
FDECL(string type, string value, vector<AbstractNode> data,
vector<AbstractNode> data2);
FDECL() = default;
// ~FDECL();
string codegen(string otype, x86* a);
};
class RET : public Node {
public:
string ctype;
RET(string type, string value, vector<AbstractNode> data);
RET() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class IMP : public Node {
public:
IMP(string type, string value, vector<AbstractNode> data);
IMP() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class ASM : public Node {
public:
ASM(string type, string value, vector<AbstractNode> data);
ASM() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class ASSIGN : public Node {
public:
ASSIGN(string type, string value, vector<AbstractNode> data);
ASSIGN() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class REFER : public Node {
public:
REFER(string type, string value, vector<AbstractNode> data);
REFER() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class DEREF : public Node {
public:
DEREF(string type, string value, vector<AbstractNode> data);
DEREF() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class EXTERNAL : public Node {
public:
EXTERNAL(string type, string value, vector<AbstractNode> data);
EXTERNAL() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class IE : public Node {
public:
IE(string type, string value, vector<AbstractNode> data);
IE() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class OPP : public Node {
public:
OPP(string type, string value, vector<AbstractNode> data);
OPP() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class PNTR : public Node {
public:
PNTR(string type, string value, vector<AbstractNode> data);
PNTR() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class LCLASS : public Node {
public:
LCLASS(string type, string value, vector<AbstractNode> data);
LCLASS() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
class LCLDEF : public Node {
public:
LCLDEF(string type, string value, vector<AbstractNode> data);
LCLDEF() = default;
// ~FCALL();
string codegen(string otype, x86* a);
};
// class ExprOpen: public Node {
// public:
// ExprOpen(string type, string value, vector<Node> data);
// // ~ExprOpen();
// };
// class ExprClosed: public Node {
// public:
// ExprClosed(string type, string value, vector<Node> data);
// // ~ExprClose();
// };
class AbstractNode {
public:
string _type;
FDECL _FD;
FCALL _FC;
LITERAL _LIT;
RET _RET;
IMP _IMP;
ASM _ASM;
ASSIGN _ASSIGN;
REFER _REFER;
DEREF _DEREF;
EXTERNAL _EXTERNAL;
IE _IE;
OPP _OPP;
PNTR _PNTR;
LCLASS _LCLASS;
LCLDEF _LCLDEF;
AbstractNode() = default;
};