-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcodegen.h
96 lines (75 loc) · 2.92 KB
/
codegen.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
#ifndef _Codegen
#define _Codegen
#include "ast.h"
#include "symbolTable.h"
extern baseST *realBase ;
extern FILE *fpOut ;
extern int realPresent ;
#define codePrint(x, ...) fprintf (fpOut, x, ##__VA_ARGS__ )
typedef enum _textFlags
{
boundERROR, declERROR, declNegERROR, argLimERROR, asgnLimERROR, divZeroERROR, printGetArrPrompt, getValuePrimitive, getArr, printInteger, printBoolean, printIntegerArr, printBooleanArr, boundCheck, dynamicDeclCheck, asgnArr
} textFlag ;
typedef enum _dataFlags
{
boundPrint, declPrint, declNeg, arrArgMismatch, asgnArgMismatch, divZero, printFormatArray, printInt, printNewLine, printFormat, printTrue, printFalse, DATA_true, DATA_false, inputIntPrompt, inputBoolPrompt, inputIntArrPrompt, inputBoolArrPrompt, leftRange, rightRange, inputInt
} dataFlag ;
typedef enum _switchDeclareStatus
{
NOT_SWITCH, SWITCH_INIT, SWITCH_GEN
} switchDeclareStatus ;
typedef enum _pushArrLim
{
LEFT, RIGHT
} pushArrLim ;
typedef enum _labelType
{
LABEL_SWITCH, LABEL_FOR, LABEL_WHILE, LABEL_DIV_ZERO, LABEL_OTHER
} labelType ;
// Helper functions
int get_label (labelType lt) ;
void codeComment (int tabCount, char *comment) ;
char* getOffsetStr (int offset) ;
int isIndexStatic (astNode *node) ;
void loadRegLeftLim (varST *searchedVar, char *reg) ;
void loadRegRightLim (varST *searchedVar, char *reg) ;
// Array handling
int getStaticOffset (varST *vst, astNode *node, int size) ;
void arrBoundCheck (astNode *node, moduleST *lst, varST *vst) ;
void dynamicDeclarationCheck (moduleST *lst, varST *searchedVar) ;
void dynamicDeclaration (moduleST *lst, varST *searchedVar, int declCount) ;
// Expression helper function
int isExprLeaf (tokenID id) ;
int isUnary (tokenID id) ;
int isAssignUnary (astNode *assignNode) ;
int isSingleRHS (astNode *node) ;
void dynAsgnArr (varST *lhs, varST *rhs) ;
// Expression
void exprAssign (astNode *node, moduleST *lst, int singleAssign) ;
void exprAssign (astNode *node, moduleST *lst, int singleAssign) ;
void exprLeaf (astNode *node, moduleST *lst, int singleAssign) ;
// I/O
void print (astNode *node, moduleST *lst) ;
void RSPAlign () ;
void RSPRestore () ;
void getValue (moduleST *lst, varST *searchedVar) ;
void preamble () ;
void errorTF (char *errStr) ;
void printArrStart () ;
void printArrEnd () ;
void postamble () ;
int isFlagSet (int flagInt, int id) ;
// Switch case
int getCaseCount (astNode *statementsNode) ;
void switchDeclareVars (astNode *statementNode) ;
int switchCaseLabels (astNode *node, moduleST *lst, int caseCount , int *caseLabels) ;
// Function call
void pushInputDynamicArr (varST *vst, varSTentry *varEntry, char *reg, pushArrLim flag) ;
void pushInput (astNode *inputEnd, varSTentry *varEntry, moduleST *lst) ;
void popOutput (astNode *inputEnd, moduleST *lst) ;
void freeDynamic (varSTentry *varEntry) ;
void retModule (moduleST *lst) ;
void moduleGeneration (astNode *node, moduleST *lst) ;
void codeGeneration(astNode *node) ;
void printCommentLineNASM () ;
#endif