forked from rishikeshsg/C-to-3AddressCode-Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quadrupelcode.h
116 lines (85 loc) · 2.43 KB
/
quadrupelcode.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
#include <stdbool.h>
#include <stdio.h>
typedef enum
{
ST_FUNC,
ST_PROC,
ST_MAIN,
ST_PROTO,
ST_ARRAY,
ST_NONE,
ST_INT,
ST_REAL,
ST_BOOL,
} SYMBOL_TYPE;
typedef enum
{
SIT_NONE,
SIT_INT,
SIT_REAL,
SIT_BOOL
} SYMBOL_INTERNAL_TYPE;
typedef enum
{
C_CONSTANT,
C_VARIABLE,
C_NONE
} CONSTANT_TYPE;
#define PARENT_NONE NULL
typedef struct _SymbolTableEntry
{
char *name;
SYMBOL_TYPE type;
SYMBOL_INTERNAL_TYPE internalType;
unsigned long offsetOrSize, line;
long index1, index2;
char *parent;
unsigned long parameter;
struct _SymbolTableEntry *next;
} SymbolTableEntry;
typedef struct
{
char *name;
int type;
float floatValue;
int intValue;
} ExpressionInfo;
typedef ExpressionInfo* expression;
typedef struct _CodeLineEntry
{
char *code;
int gotoL;
struct _CodeLineEntry *next;
} CodeLineEntry;
typedef struct _BackpatchList
{
CodeLineEntry *entry;
struct _BackpatchList *next;
} BackpatchList;
CodeLineEntry *genquad(char *code);
void backpatch(BackpatchList* list, int gotoL);
BackpatchList* mergelists(BackpatchList* a, BackpatchList* b);
BackpatchList* addToList(BackpatchList* list, CodeLineEntry* entry);
SymbolTableEntry* addSymbol(const char *name,
SYMBOL_TYPE type,
SYMBOL_INTERNAL_TYPE internalType,
unsigned long offsetOrSize,
unsigned long line,
long index1,
long index2,
char *parent,
unsigned long parameter);
bool printCode(FILE *outputFile);
bool printSymbolTable(FILE *outputFile);
SymbolTableEntry* addSymbolToParameterQueue(SymbolTableEntry* queue, char *name, SYMBOL_TYPE type);
void freeCodeLinesAndSymbolTable();
int checkAndGenerateParams(SymbolTableEntry* queue, char* name ,int parameterCount);
int getFunctionType(char *name);
int getSymbolType(char *name);
char* nextFloatVar();
char* nextIntVar();
char* nextBoolVar();
int nextquad();
void addFunction(char *name, unsigned int parameter_count, SYMBOL_INTERNAL_TYPE ret_type, int line);
SymbolTableEntry* lookup(char *name);
extern SymbolTableEntry *symbolTable;