-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode_generation.h
105 lines (96 loc) · 5.3 KB
/
code_generation.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
#ifndef _CODE_GENERATION_H_
#define _CODE_GENERATION_H_
#include "semantic.h"
#include "astfunctions.h"
#include "trees.h"
#include <fcntl.h>
#include <io.h>
#include <Winsock2.h>
#pragma comment(lib, "Ws2_32.lib")
static char* classFileName = "Go.class";
struct Program* program;
int fd;
unsigned char u1;
char s1;
unsigned short int u2;
unsigned int u4;
short int s2;
int s4;
float sf4;
int fh;
extern struct Constant* constantCode;
extern struct Constant* constantClassString;
extern struct Constant* objectConstructorMethodRef;
extern struct Constant* constantObjectClass;
extern struct Constant* constantSourceFile;
extern struct Constant* constantSourceFileName;
extern struct Constant* constantClassRuntimeLib;
extern struct Constant* printStringMethodRef;
extern struct Constant* printIntegerMethodRef;
extern struct Constant* printFloatMethodRef;
extern struct Constant* scanStringMethodRef;
extern struct Constant* scanIntegerMethodRef;
extern struct Constant* scanFloatMethodRef;
extern struct Constant* openSquareParenthesis;
extern struct Constant* closeSquareParenthesis;
extern struct Constant* space;
void Write(void* data, int count);
void writeU1();
void writeU2();
void writeU4();
void writeS2();
void writeS4();
void writeSf4();
void writeString(char* str);
void writeU1ToArray(char* code, int* offset);
void writeS1ToArray(char* code, int* offset);
void writeU2ToArray(char* code, int* offset);
void writeU4ToArray(char* code, int* offset);
void writeS2ToArray(char* code, int* offset);
void writeS4ToArray(char* code, int* offset);
void writeSf4ToArray(char* code, int* offset);
void writeConstantsTable();
void writeClassMetadata();
void writeFieldsTable();
void writeMethodsTable();
void writeMethod(struct Method* method);
void generateCode(struct Program* root);
void writeConstant(struct Constant* constant);
void writeField(struct Field* field);
void generateCodeForDefaultConstructor();
void loadComparisonResultToStack(char* code, int* offset);
char* generateCodeForMethod(struct Method* method, int* codeLength);
void generateCodeForVarDecl(struct Method* method, struct VarDecl* varDecl, char* code, int *offset);
void generateCodeForVarSpec(struct Method* method, struct VarSpec* varSpec, char* code, int* offset);
void generateCodeForConstDecl(struct Method* method, struct ConstDecl* constDecl, char* code, int* offset);
void generateCodeForConstSpec(struct Method* method,struct ConstSpec* constSpec, char* code, int* offset);
void generateCodeForStmtList(struct Method* method, struct StatementList* stmtList, char* code, int* offset);
void generateCodeForStmt(struct Method* method, struct Statement* stmt, char* code, int* offset);
void generateCodeForSimpleStmt(struct Method* method, struct SimpleStmt* simpleStmt, char* code, int* offset);
void generateCodeForIfStmt(struct Method* method, struct IfStmt* ifStmt, char* code, int* offset);
void generateCodeForSwitchStmt(struct Method* method, struct SwitchStmt* switchStmt, char* code, int* offset);
void generateCodeForStandardForStmt(struct Method* method, struct ForStmt* forStmt, char* code, int* offset);
void generateCodeForForStmtWithExpr(struct Method* method, struct ForStmt* forStmt, char* code, int* offset);
void generateCodeForInfinitiveFor(struct Method* method, struct ForStmt* forStmt, char* code, int* offset);
void generateCodeForPrintStmt(struct Method* method, struct PrintStatement* printStmt, char* code, int* offset);
void generateCodeForScanStmt(struct Method* method, struct ScanStatement* scanStmt, char* code, int* offset);
void generateCodeForExpression(struct Method* method, struct Expression* expr, char* code, int* offset);
void generateCodeForPrimaryExpression(struct Method* method, struct PrimaryExpression* primaryExpr, char* code, int* offset);
void generateCodeForSingleAssignment(struct Method* method, int localVarId, struct Expression* expr, char* code, int* offset);
void generateCodeForArrayElementAssignment(struct Method* method,
struct PrimaryExpression* arrayExpr, struct Expression* indexExpr, struct Expression* expr, char* code, int* offset);
void generateCodeForArrayInitialization(struct Method* method, int localArrayVarId,
struct ExpressionList* exprList, char* code, int *offset);
void fillBreakAndFContinueJumpAddress(char* code, struct StatementList* stmtList, int forStart, int forEnd);
void generateTempCodeForGotoInstruction(char* code, int* offset);
void fixOffset(char* code, int gotoPosition, int jumpTargetAddress);
void fixDefaultDefinitionPosition(char* code, int lookupswitchInstructionPos, int defaultDeclPos, int defaultDefPos);
void fixCaseDefinitionPosition(char* code, int lookupswitchInstructionPos, int caseDeclPos, int caseDefPos);
void generateCodeForSwitchStmtWithExpression(struct Method* method, struct SwitchStmt* switchStmt, char* code, int* offset);
void generateCodeToCheckForCondition(char* code, int *offset, int forBodyPos);
void sortCaseExpression(struct ExpressionCaseClause* exprCaseClauseList[], int count);
void generateCodeToCallPrint(char* code, int* offset, int printMethodRefId);
void genereteCodeForLogicalOperatorWithInt(char* code, int* offset, unsigned char opcode);
void printConstantString(char*code, int* offset, unsigned char constantId);
unsigned char findInstructionForSugarSyntax(enum StatementType stmtType, enum TypeNames exprSemanticType);
#endif //_CODE_GENERATION_H_