-
Notifications
You must be signed in to change notification settings - Fork 0
/
enums.h
246 lines (167 loc) · 5.96 KB
/
enums.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
All structs that are not to be used directly will be prefixed with '_'
All new types to be used will be suffixed with T to avoid repeatation
All enum while definition will be preffixed with enum_
*/
#ifndef __ENUMS_H__
#define __ENUMS_H__
#define NUM_REG 10
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/* ALL ENUM DEFINITIONS */
typedef enum enum_operations{Add, Sub, Mul, Div}OperationsT;
typedef enum enum_relops{Equal, NEqual, Leq, Geq, Le, Ge}RelopsT;
typedef enum enum_keywords{If, Else, Func}KeywordsT;
typedef enum enum_types{Int, Flt}TypesT;
typedef enum enum_tokens{LRbrac, RRbrack, LCbrac, RCbrac, LSbrac, RSbrac}TokensT;
typedef enum enum_groups{Constant, Variable, Codeblock}GroupsT;
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/* ALL STRUCT DEFINITIONS */
//--------------------------------------------------------------------------------------------------
// This is the only exception to the suffix rule
typedef struct _codeBlock
{
char *code;
unsigned long int len;
} codeBlock;
//--------------------------------------------------------------------------------------------------
struct _constant
{
TypesT Type;
union{
long int num;
double flt;
};
};
typedef struct _constant ConstantT;
struct _variable
{
TypesT Type;
char *Name;
};
typedef struct _variable VariableT;
// To be replaced with argument list later
// Return to be replaced with return list later
struct _function
{
char *Name;
VariableT Argument;
TypesT Return;
};
//--------------------------------------------------------------------------------------------------
// For maintaining variable stack frame
struct _stackNode{
unsigned long int id;
unsigned long int offset;
unsigned long int level;
// To Define thee type of Node
GroupsT Group;
union{
ConstantT constant;
VariableT variable;
codeBlock *codeblock;
};
struct _stackNode *prev;
struct _stackNode *next;
};
typedef struct _stackNode StackNode;
// Level is used to store the load point of a variable
struct _register
{
unsigned long int id;
unsigned long int load_level;
unsigned long int access_level;
StackNode *snode;
GroupsT Group;
};
typedef struct _register RegisterT;
//--------------------------------------------------------------------------------------------------
// Node construct for expression evaluation
struct _expression
{
// For proper register allocation
long unsigned int depth;
// Register allocated
int reg;
// Pointer to the stackNode with temporary expression
StackNode * snode;
};
typedef struct _expression ExpressionT;
// Register code struct
struct GetReg
{
int i;
codeBlock *c;
};
// Loop Stack Level Manager
struct LoopNode
{
unsigned long int level;
unsigned long int offset;
struct LoopNode * prev;
unsigned long int spill[NUM_REG];
};
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/* FUNCTION DEFINITIONS ONLY BELOW */
//--------------------------------------------------------------------------------------------------
/* BEGIN codeman.c */
codeBlock * genCode();
codeBlock * Assign(const char *format, ...);
void Concat(codeBlock *c1, codeBlock *c2);
char *Label(codeBlock *c);
/* END codeman.c */
//--------------------------------------------------------------------------------------------------
/* BEGIN stackframe.c */
void RemoveNode(StackNode * s);
StackNode * AddNode();
StackNode * CheckVar(char * name);
void LoopAdd();
codeBlock * LoopRemove();
/* END stackframe.c */
//--------------------------------------------------------------------------------------------------
/* BEGIN regman.c */
struct GetReg GetRegister();
int CheckVarReg(StackNode *s);
/* END regman.c */
//--------------------------------------------------------------------------------------------------
/* BEGIN blocks.c */
codeBlock * ConCode(ExpressionT exp1, ExpressionT exp2, RelopsT op);
codeBlock * IFBlock(codeBlock * cond, codeBlock * block_if, codeBlock * block_else);
codeBlock * WhileBlock(codeBlock * cond, codeBlock * block);
codeBlock * BlockClean();
/* END blocks.c */
//--------------------------------------------------------------------------------------------------
/* BEGIN expops.c */
ExpressionT ExpOp(ExpressionT exp1, ExpressionT exp2, OperationsT op);
ExpressionT ExpNeg(ExpressionT exp);
ExpressionT DecConst(char * constant, TypesT type);
ExpressionT LoadVar(char * var, int lw);
codeBlock * VarOp(char * var, OperationsT op);
codeBlock * VarAssign(char * var, ExpressionT exp, int mem);
codeBlock * PrintExp(ExpressionT exp);
/* END expops.c */
//--------------------------------------------------------------------------------------------------
/* BEGIN golang.y */
int yylex(void);
void yyerror (char *);
/* END golang.y */
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/* ALL GLOBAL DECLARATIONS BELOW */
// Global for label counter
unsigned long int label_count;
// Global for maintaing level
unsigned long int Level;
// Temporary Register Array
RegisterT TArray[NUM_REG];
// StackTop pointer
StackNode * StackTop;
// Final Code Block
codeBlock * FINAL_CODE;
// Loop Initial node for nested loop handling
struct LoopNode * LoopTop;
// Reg rotator when kickout required
int reg_rot;
#endif /* __ENUMS_H__ */