Commit | Line | Data |
---|---|---|
85448fe7 DR |
1 | /* |
2 | * C code generator header | |
3 | */ | |
4 | ||
5 | #include <stdio.h> | |
6 | ||
7 | #define LTYPE long /* change to int for no long consts */ | |
8 | #define NCPS 8 | |
9 | #define NULL 0 | |
10 | ||
11 | /* | |
12 | * Tree node for unary and binary | |
13 | */ | |
14 | struct tnode { | |
15 | int op; | |
16 | int type; | |
17 | int degree; | |
18 | struct tnode *tr1, *tr2; | |
19 | }; | |
20 | ||
21 | /* | |
22 | * tree names for locals | |
23 | */ | |
24 | struct tname { | |
25 | int op; | |
26 | int type; | |
27 | char class; | |
28 | char regno; | |
29 | int offset; | |
30 | int nloc; | |
31 | }; | |
32 | ||
33 | /* | |
34 | * tree names for externals | |
35 | */ | |
36 | struct xtname { | |
37 | int op; | |
38 | int type; | |
39 | char class; | |
40 | char regno; | |
41 | int offset; | |
42 | char name[NCPS]; | |
43 | }; | |
44 | ||
45 | struct tconst { | |
46 | int op; | |
47 | int type; | |
48 | int value; | |
49 | }; | |
50 | ||
51 | /* | |
52 | * long constants | |
53 | */ | |
54 | struct lconst { | |
55 | int op; | |
56 | int type; | |
57 | LTYPE lvalue; | |
58 | }; | |
59 | ||
60 | struct ftconst { | |
61 | int op; | |
62 | int type; | |
63 | int value; | |
64 | double fvalue; | |
65 | }; | |
66 | ||
67 | /* | |
68 | * Node used for field assignemnts | |
69 | */ | |
70 | struct fasgn { | |
71 | int op; | |
72 | int type; | |
73 | int degree; | |
74 | struct tnode *tr1, *tr2; | |
75 | int mask; | |
76 | }; | |
77 | ||
78 | struct optab { | |
79 | char tabdeg1; | |
80 | char tabtyp1; | |
81 | char tabdeg2; | |
82 | char tabtyp2; | |
83 | char *tabstring; | |
84 | }; | |
85 | ||
86 | struct table { | |
87 | int tabop; | |
88 | struct optab *tabp; | |
89 | }; | |
90 | ||
91 | struct instab { | |
92 | int iop; | |
93 | char *str1; | |
94 | char *str2; | |
95 | }; | |
96 | ||
97 | struct swtab { | |
98 | int swlab; | |
99 | int swval; | |
100 | }; | |
101 | ||
102 | char maprel[]; | |
103 | char notrel[]; | |
104 | int nreg; | |
105 | int isn; | |
106 | int namsiz; | |
107 | int line; | |
108 | int nerror; | |
109 | struct table cctab[]; | |
110 | struct table efftab[]; | |
111 | struct table regtab[]; | |
112 | struct table sptab[]; | |
113 | struct table lsptab[1]; | |
114 | struct instab instab[]; | |
115 | struct instab branchtab[]; | |
116 | int opdope[]; | |
117 | char *opntab[]; | |
118 | int nstack; | |
119 | int nfloat; | |
120 | struct tname sfuncr; | |
121 | char *funcbase; | |
122 | char *curbase; | |
123 | char *coremax; | |
124 | struct tconst czero, cone; | |
125 | struct ftconst fczero; | |
126 | long totspace; | |
127 | /* | |
128 | * Some special stuff for long comparisons | |
129 | */ | |
130 | int xlab1, xlab2, xop, xzero; | |
131 | ||
132 | /* | |
133 | operators | |
134 | */ | |
135 | #define EOFC 0 | |
136 | #define SEMI 1 | |
137 | #define LBRACE 2 | |
138 | #define RBRACE 3 | |
139 | #define LBRACK 4 | |
140 | #define RBRACK 5 | |
141 | #define LPARN 6 | |
142 | #define RPARN 7 | |
143 | #define COLON 8 | |
144 | #define COMMA 9 | |
145 | #define FSEL 10 | |
146 | #define FSELR 11 | |
147 | #define FSELT 12 | |
148 | #define FSELA 16 | |
149 | #define ULSH 17 | |
150 | #define ASULSH 18 | |
151 | ||
152 | #define KEYW 19 | |
153 | #define NAME 20 | |
154 | #define CON 21 | |
155 | #define STRING 22 | |
156 | #define FCON 23 | |
157 | #define SFCON 24 | |
158 | #define LCON 25 | |
159 | #define SLCON 26 | |
160 | ||
161 | #define AUTOI 27 | |
162 | #define AUTOD 28 | |
163 | #define INCBEF 30 | |
164 | #define DECBEF 31 | |
165 | #define INCAFT 32 | |
166 | #define DECAFT 33 | |
167 | #define EXCLA 34 | |
168 | #define AMPER 35 | |
169 | #define STAR 36 | |
170 | #define NEG 37 | |
171 | #define COMPL 38 | |
172 | ||
173 | #define DOT 39 | |
174 | #define PLUS 40 | |
175 | #define MINUS 41 | |
176 | #define TIMES 42 | |
177 | #define DIVIDE 43 | |
178 | #define MOD 44 | |
179 | #define RSHIFT 45 | |
180 | #define LSHIFT 46 | |
181 | #define AND 47 | |
182 | #define ANDN 55 | |
183 | #define OR 48 | |
184 | #define EXOR 49 | |
185 | #define ARROW 50 | |
186 | #define ITOF 51 | |
187 | #define FTOI 52 | |
188 | #define LOGAND 53 | |
189 | #define LOGOR 54 | |
190 | #define FTOL 56 | |
191 | #define LTOF 57 | |
192 | #define ITOL 58 | |
193 | #define LTOI 59 | |
194 | #define ITOP 13 | |
195 | #define PTOI 14 | |
196 | #define LTOP 15 | |
197 | ||
198 | #define EQUAL 60 | |
199 | #define NEQUAL 61 | |
200 | #define LESSEQ 62 | |
201 | #define LESS 63 | |
202 | #define GREATEQ 64 | |
203 | #define GREAT 65 | |
204 | #define LESSEQP 66 | |
205 | #define LESSP 67 | |
206 | #define GREATQP 68 | |
207 | #define GREATP 69 | |
208 | ||
209 | #define ASPLUS 70 | |
210 | #define ASMINUS 71 | |
211 | #define ASTIMES 72 | |
212 | #define ASDIV 73 | |
213 | #define ASMOD 74 | |
214 | #define ASRSH 75 | |
215 | #define ASLSH 76 | |
216 | #define ASAND 77 | |
217 | #define ASOR 78 | |
218 | #define ASXOR 79 | |
219 | #define ASSIGN 80 | |
220 | #define TAND 81 | |
221 | #define LTIMES 82 | |
222 | #define LDIV 83 | |
223 | #define LMOD 84 | |
224 | #define ASANDN 85 | |
225 | #define LASTIMES 86 | |
226 | #define LASDIV 87 | |
227 | #define LASMOD 88 | |
228 | ||
229 | #define QUEST 90 | |
230 | #define MAX 93 | |
231 | #define MAXP 94 | |
232 | #define MIN 95 | |
233 | #define MINP 96 | |
234 | #define LLSHIFT 91 | |
235 | #define ASLSHL 92 | |
236 | #define SEQNC 97 | |
237 | #define CALL1 98 | |
238 | #define CALL2 99 | |
239 | #define CALL 100 | |
240 | #define MCALL 101 | |
241 | #define JUMP 102 | |
242 | #define CBRANCH 103 | |
243 | #define INIT 104 | |
244 | #define SETREG 105 | |
245 | #define LOAD 106 | |
246 | #define ITOC 109 | |
247 | #define RFORCE 110 | |
248 | ||
249 | /* | |
250 | * Intermediate code operators | |
251 | */ | |
252 | #define BRANCH 111 | |
253 | #define LABEL 112 | |
254 | #define NLABEL 113 | |
255 | #define RLABEL 114 | |
256 | #define STRASG 115 | |
257 | #define STRSET 116 | |
258 | #define BDATA 200 | |
259 | #define PROG 202 | |
260 | #define DATA 203 | |
261 | #define BSS 204 | |
262 | #define CSPACE 205 | |
263 | #define SSPACE 206 | |
264 | #define SYMDEF 207 | |
265 | #define SAVE 208 | |
266 | #define RETRN 209 | |
267 | #define EVEN 210 | |
268 | #define PROFIL 212 | |
269 | #define SWIT 213 | |
270 | #define EXPR 214 | |
271 | #define SNAME 215 | |
272 | #define RNAME 216 | |
273 | #define ANAME 217 | |
274 | #define NULLOP 218 | |
275 | #define SETSTK 219 | |
276 | #define SINIT 220 | |
277 | #define GLOBAL 221 | |
278 | #define C3BRANCH 222 | |
279 | ||
280 | /* | |
281 | * types | |
282 | */ | |
283 | #define INT 0 | |
284 | #define CHAR 1 | |
285 | #define FLOAT 2 | |
286 | #define DOUBLE 3 | |
287 | #define STRUCT 4 | |
288 | #define RSTRUCT 5 | |
289 | #define LONG 6 | |
290 | #define UNSIGN 7 | |
291 | ||
292 | #define TYLEN 2 | |
293 | #define TYPE 07 | |
294 | #define XTYPE (03<<3) | |
295 | #define PTR 010 | |
296 | #define FUNC 020 | |
297 | #define ARRAY 030 | |
298 | ||
299 | /* | |
300 | storage classes | |
301 | */ | |
302 | #define KEYWC 1 | |
303 | #define MOS 10 | |
304 | #define AUTO 11 | |
305 | #define EXTERN 12 | |
306 | #define STATIC 13 | |
307 | #define REG 14 | |
308 | #define STRTAG 15 | |
309 | #define ARG 16 | |
310 | #define OFFS 20 | |
311 | #define XOFFS 21 | |
312 | #define SOFFS 22 | |
313 | ||
314 | /* | |
315 | Flag bits | |
316 | */ | |
317 | ||
318 | #define BINARY 01 | |
319 | #define LVALUE 02 | |
320 | #define RELAT 04 | |
321 | #define ASSGOP 010 | |
322 | #define LWORD 020 | |
323 | #define RWORD 040 | |
324 | #define COMMUTE 0100 | |
325 | #define RASSOC 0200 | |
326 | #define LEAF 0400 | |
327 | #define CNVRT 01000 |