-
Notifications
You must be signed in to change notification settings - Fork 0
/
decl.h
161 lines (150 loc) · 5.07 KB
/
decl.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// 函数原型
// Copyright (c) 2019 Warren Toomey, GPL3
// scan.c
void reject_token(struct token *t);
int scan(struct token *t);
// tree.c
struct ASTnode *mkastnode(int op, int type,
struct symtable *ctype,
struct ASTnode *left,
struct ASTnode *mid,
struct ASTnode *right,
struct symtable *sym, int intvalue);
struct ASTnode *mkastleaf(int op, int type,
struct symtable *ctype,
struct symtable *sym, int intvalue);
struct ASTnode *mkastunary(int op, int type,
struct symtable *ctype,
struct ASTnode *left,
struct symtable *sym, int intvalue);
void dumpAST(struct ASTnode *n, int label, int level);
// gen.c
int genlabel(void);
int genAST(struct ASTnode *n, int iflabel, int looptoplabel,
int loopendlabel, int parentASTop);
void genpreamble(char *filename);
void genpostamble();
void genfreeregs(int keepreg);
void genglobsym(struct symtable *node);
int genglobstr(char *strvalue, int append);
void genglobstrend(void);
int genprimsize(int type);
int genalign(int type, int offset, int direction);
void genreturn(int reg, int id);
// cg.c
int cgprimsize(int type);
int cgalign(int type, int offset, int direction);
void cgtextseg();
void cgdataseg();
int cgallocreg(void);
void cgfreeallregs(int keepreg);
void cgfreereg(int reg);
void cgspillregs(void);
void cgpreamble(char *filename);
void cgpostamble();
void cgfuncpreamble(struct symtable *sym);
void cgfuncpostamble(struct symtable *sym);
int cgloadint(int value, int type);
int cgloadvar(struct symtable *sym, int op);
int cgloadglobstr(int label);
int cgadd(int r1, int r2);
int cgsub(int r1, int r2);
int cgmul(int r1, int r2);
int cgdivmod(int r1, int r2, int op);
int cgshlconst(int r, int val);
int cgcall(struct symtable *sym, int numargs);
void cgcopyarg(int r, int argposn);
int cgstorglob(int r, struct symtable *sym);
int cgstorlocal(int r, struct symtable *sym);
void cgglobsym(struct symtable *node);
void cgglobstr(int l, char *strvalue, int append);
void cgglobstrend(void);
int cgcompare_and_set(int ASTop, int r1, int r2, int type);
int cgcompare_and_jump(int ASTop, int r1, int r2, int label, int type);
void cglabel(int l);
void cgjump(int l);
int cgwiden(int r, int oldtype, int newtype);
void cgreturn(int reg, struct symtable *sym);
int cgaddress(struct symtable *sym);
int cgderef(int r, int type);
int cgstorderef(int r1, int r2, int type);
int cgnegate(int r);
int cginvert(int r);
int cglognot(int r);
void cgloadboolean(int r, int val);
int cgboolean(int r, int op, int label);
int cgand(int r1, int r2);
int cgor(int r1, int r2);
int cgxor(int r1, int r2);
int cgshl(int r1, int r2);
int cgshr(int r1, int r2);
void cgswitch(int reg, int casecount, int toplabel,
int *caselabel, int *caseval, int defaultlabel);
void cgmove(int r1, int r2);
void cglinenum(int line);
// expr.c
struct ASTnode *expression_list(int endtoken);
struct ASTnode *binexpr(int ptp);
// stmt.c
struct ASTnode *compound_statement(int inswitch);
// misc.c
void match(int t, char *what);
void semi(void);
void lbrace(void);
void rbrace(void);
void lparen(void);
void rparen(void);
void ident(void);
void comma(void);
void fatal(char *s);
void fatals(char *s1, char *s2);
void fatald(char *s, int d);
void fatalc(char *s, int c);
// sym.c
void appendsym(struct symtable **head, struct symtable **tail,
struct symtable *node);
struct symtable *newsym(char *name, int type, struct symtable *ctype,
int stype, int class, int nelems, int posn);
struct symtable *addglob(char *name, int type, struct symtable *ctype,
int stype, int class, int nelems, int posn);
struct symtable *addlocl(char *name, int type, struct symtable *ctype,
int stype, int nelems);
struct symtable *addparm(char *name, int type, struct symtable *ctype,
int stype);
struct symtable *addstruct(char *name);
struct symtable *addunion(char *name);
struct symtable *addmemb(char *name, int type, struct symtable *ctype,
int stype, int nelems);
struct symtable *addenum(char *name, int class, int value);
struct symtable *addtypedef(char *name, int type, struct symtable *ctype);
struct symtable *findglob(char *s);
struct symtable *findlocl(char *s);
struct symtable *findsymbol(char *s);
struct symtable *findmember(char *s);
struct symtable *findstruct(char *s);
struct symtable *findunion(char *s);
struct symtable *findenumtype(char *s);
struct symtable *findenumval(char *s);
struct symtable *findtypedef(char *s);
void clear_symtable(void);
void freeloclsyms(void);
void freestaticsyms(void);
void dumptable(struct symtable *head, char *name, int indent);
void dumpsymtables(void);
// decl.c
int parse_type(struct symtable **ctype, int *class);
int parse_stars(int type);
int parse_cast(struct symtable **ctype);
int declaration_list(struct symtable **ctype, int class, int et1, int et2,
struct ASTnode **gluetree);
void global_declarations(void);
// types.c
int inttype(int type);
int ptrtype(int type);
int pointer_to(int type);
int value_at(int type);
int typesize(int type, struct symtable *ctype);
struct ASTnode *modify_type(struct ASTnode *tree, int rtype,
struct symtable *rctype, int op);
// opt.c
struct ASTnode *optimise(struct ASTnode *n);