forked from louisje/OpenComputer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerator.h
45 lines (40 loc) · 2.09 KB
/
Generator.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
#ifndef GENERATOR_H
#define GENERATOR_H
#include "Tree.h"
#include "HashTable.h"
#include "Scanner.h"
#include "Lib.h"
#include "SymTable.h"
#include "Parser.h"
/*
typedef enum { SCOPE_GLOBAL, SCOPE_METHOD_NAME, SCOPE_PARAM,
SCOPE_LOCAL, SCOPE_CODE, SCOPE_STRUCT_NAME, SCOPE_STRUCT, SCOPE_DECL
} SCOPE;
*/
// #include "Asm0.h"
// typedef enum { GLOBAL, LOCAL, PARAM, CODE, STRUCT } SCOPE;
typedef enum { CStyle, AsmStyle } PCodeStyle;
typedef struct { // 程式碼產生器物件
SymTable *symTable; // 符號表
Tree *tree; // 剖析樹
FILE *asmFile; // 輸出的CPU0組合語言檔
int forCount, ifCount, whileCount, varCount, labelCount, stringCount; // 標記與臨時變數的數量
// SCOPE scope;
PCodeStyle pCodeStyle;
char type[100];
} Generator;
void generate(Tree *tree, SymTable *symTable, char *asmFile); // 程式碼產生器的主函數
Generator *GenNew(); // Generator 的建構函數
void GenFree(Generator *g); // Generator 的解構函數
void GenCode(Generator *g, Tree *node, char *rzVar); // 產生組合語言程式碼
void GenData(Generator *g);
void GenDecl(Generator *g, Tree *node);
void GenPcode(Generator *g, char* label, char* op, char* p1, char* p2, char* pTo);
void GenTempVar(Generator *g, char *tempVar);
void negateOp(char *condOp, char *negOp);
void pcode(FILE *file, char* label, char* op, char* p1, char* p2, char* pTo, int style);
void pcodeNoLabel(FILE *file, char* op, char* p1, char* p2, char* pTo, int style);
void pcodeCStyle(FILE *file, char* op, char* p1, char* p2, char* pTo);
void pcodeAsmStyle(FILE *file, char* op, char* p1, char* p2, char* pTo);
int typeSize(char *type);
#endif