-
Notifications
You must be signed in to change notification settings - Fork 0
/
icg.h
54 lines (41 loc) · 1.34 KB
/
icg.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
#ifndef COMPILER_ICG_H
#define COMPILER_ICG_H
#include "parserDef.h"
#include "lexer.h"
typedef enum {
VAR, CONST
} type;
typedef struct {
type type;
int value;
} data;
/**
* Intermediate Code will be a linked list of quadruples
*/
typedef struct quadruple{
char operator; // 'T', '+', '-', '*', '/', '=', 'L', 'G', 'I', 'R', 'W'
int condOp;
data arg1;
data arg2;
data result;
struct quadruple* next;
} quadruple;
typedef struct quadruple* iCode;
iCode createiCode(char op);
iCode concat(quadruple* q1, quadruple* q2);
iCode getIntermediateCode(ParseTreeNode* root, int* maxVariableName);
iCode gcfProgram(ParseTreeNode* node);
iCode gcfMainFunction(ParseTreeNode* node);
iCode gcfDeclarations(ParseTreeNode* node);
iCode gcfDeclaration(ParseTreeNode* node);
iCode gcfArithmeticExpr(ParseTreeNode *node, int variableName);
iCode gcfRecordArithmeticExpr(ParseTreeNode *node, int numOfVariables, int* variableNames);
iCode gcfBooleanExpr(ParseTreeNode* node, int labelTrue, int labelFalse);
iCode gcfStatement(ParseTreeNode* node);
iCode gcfAssignmentStatement(ParseTreeNode* node);
iCode gcfIterativeStatement(ParseTreeNode* node);
iCode gcfIOStatement(ParseTreeNode* node);
iCode gcfConditionalStatement(ParseTreeNode* node);
void removeRedundantAssignment(iCode code);
void printiCode(iCode code);
#endif //COMPILER_ICG_H