1: /*
2: * C code generator header
3: */
4:
5: #include <stdio.h>
6: #include <setjmp.h>
7:
8: #define LTYPE long /* change to int for no long consts */
9: #define NULL 0
10: #define TNULL (union tree *)NULL
11: #define UNS(x) ((unsigned short)(x))
12:
13: /*
14: * Tree node for unary and binary
15: */
16: struct tnode {
17: int op;
18: int type;
19: int degree;
20: union tree *tr1;
21: union tree *tr2;
22: };
23:
24: /*
25: * tree names for locals
26: */
27: struct tname {
28: int op;
29: int type;
30: char class;
31: char regno;
32: int offset;
33: int nloc;
34: };
35:
36: /*
37: * tree names for externals
38: */
39: struct xtname {
40: int op;
41: int type;
42: char class;
43: char regno;
44: int offset;
45: char *name;
46: };
47:
48: /*
49: * short constants
50: */
51: struct tconst {
52: int op;
53: int type;
54: int value;
55: };
56:
57: /*
58: * long constants
59: */
60: struct lconst {
61: int op;
62: int type;
63: LTYPE lvalue;
64: };
65:
66: /*
67: * Floating constants
68: */
69: struct ftconst {
70: int op;
71: int type;
72: int value;
73: double fvalue;
74: };
75:
76: /*
77: * Node used for field assignments
78: */
79: struct fasgn {
80: int op;
81: int type;
82: int degree;
83: union tree *tr1;
84: union tree *tr2;
85: int mask;
86: };
87:
88: union tree {
89: struct tnode t;
90: struct tname n;
91: struct xtname x;
92: struct tconst c;
93: struct lconst l;
94: struct ftconst f;
95: struct fasgn F;
96: };
97:
98: struct optab {
99: char tabdeg1;
100: char tabtyp1;
101: char tabdeg2;
102: char tabtyp2;
103: char *tabstring;
104: };
105:
106: struct table {
107: int tabop;
108: struct optab *tabp;
109: };
110:
111: struct instab {
112: int iop;
113: char *str1;
114: char *str2;
115: };
116:
117: struct swtab {
118: int swlab;
119: int swval;
120: };
121:
122: char maprel[];
123: char notrel[];
124: int nreg;
125: int isn;
126: int line;
127: int nerror; /* number of hard errors */
128: struct table cctab[];
129: struct table efftab[];
130: struct table regtab[];
131: struct table sptab[];
132: struct table lsptab[1];
133: struct instab instab[];
134: struct instab branchtab[];
135: int opdope[];
136: char *opntab[];
137: int nstack;
138: int nfloat;
139: struct tname sfuncr;
140: char *funcbase;
141: char *curbase;
142: char *coremax;
143: struct tconst czero, cone;
144: long totspace;
145: int regpanic; /* set when SU register alg. fails */
146: int panicposs; /* set when there might be need for regpanic */
147: jmp_buf jmpbuf;
148: long ftell();
149: char *sbrk();
150: struct optab *match();
151: union tree *optim();
152: union tree *unoptim();
153: union tree *pow2();
154: union tree *tnode();
155: union tree *sdelay();
156: union tree *ncopy();
157: union tree *getblk();
158: union tree *strfunc();
159: union tree *isconstant();
160: union tree *tconst();
161: union tree *hardlongs();
162: union tree *lconst();
163: union tree *acommute();
164: union tree *lvfield();
165: union tree *paint();
166: long ftell();
167:
168: /*
169: * Some special stuff for long comparisons
170: */
171: int xlab1, xlab2, xop, xzero;
172:
173: /*
174: operators
175: */
176: #define EOFC 0
177: #define SEMI 1
178: #define LBRACE 2
179: #define RBRACE 3
180: #define LBRACK 4
181: #define RBRACK 5
182: #define LPARN 6
183: #define RPARN 7
184: #define COLON 8
185: #define COMMA 9
186: #define FSEL 10
187: #define FSELR 11
188: #define FSELT 12
189: #define FSELA 16
190: #define ULSH 17
191: #define ASULSH 18
192:
193: #define KEYW 19
194: #define NAME 20
195: #define CON 21
196: #define STRING 22
197: #define FCON 23
198: #define SFCON 24
199: #define LCON 25
200: #define SLCON 26
201:
202: #define AUTOI 27
203: #define AUTOD 28
204: #define NULLOP 218
205: #define INCBEF 30
206: #define DECBEF 31
207: #define INCAFT 32
208: #define DECAFT 33
209: #define EXCLA 34
210: #define AMPER 35
211: #define STAR 36
212: #define NEG 37
213: #define COMPL 38
214:
215: #define DOT 39
216: #define PLUS 40
217: #define MINUS 41
218: #define TIMES 42
219: #define DIVIDE 43
220: #define MOD 44
221: #define RSHIFT 45
222: #define LSHIFT 46
223: #define AND 47
224: #define ANDN 55
225: #define OR 48
226: #define EXOR 49
227: #define ARROW 50
228: #define ITOF 51
229: #define FTOI 52
230: #define LOGAND 53
231: #define LOGOR 54
232: #define FTOL 56
233: #define LTOF 57
234: #define ITOL 58
235: #define LTOI 59
236: #define ITOP 13
237: #define PTOI 14
238: #define LTOP 15
239:
240: #define EQUAL 60
241: #define NEQUAL 61
242: #define LESSEQ 62
243: #define LESS 63
244: #define GREATEQ 64
245: #define GREAT 65
246: #define LESSEQP 66
247: #define LESSP 67
248: #define GREATQP 68
249: #define GREATP 69
250:
251: #define ASPLUS 70
252: #define ASMINUS 71
253: #define ASTIMES 72
254: #define ASDIV 73
255: #define ASMOD 74
256: #define ASRSH 75
257: #define ASLSH 76
258: #define ASAND 77
259: #define ASOR 78
260: #define ASXOR 79
261: #define ASSIGN 80
262: #define TAND 81
263: #define LTIMES 82
264: #define LDIV 83
265: #define LMOD 84
266: #define ASANDN 85
267: #define LASTIMES 86
268: #define LASDIV 87
269: #define LASMOD 88
270:
271: #define QUEST 90
272: /* #define MAX 93 /* not used; wanted macros in param.h */
273: #define MAXP 94
274: /* #define MIN 95 /* not used; wanted macros in param.h */
275: #define MINP 96
276: #define LLSHIFT 91
277: #define ASLSHL 92
278: #define SEQNC 97
279: #define CALL1 98
280: #define CALL2 99
281: #define CALL 100
282: #define MCALL 101
283: #define JUMP 102
284: #define CBRANCH 103
285: #define INIT 104
286: #define SETREG 105
287: #define LOAD 106
288: #define PTOI1 107
289: #define ITOC 109
290: #define RFORCE 110
291:
292: /*
293: * Intermediate code operators
294: */
295: #define BRANCH 111
296: #define LABEL 112
297: #define NLABEL 113
298: #define RLABEL 114
299: #define STRASG 115
300: #define STRSET 116
301: #define UDIV 117
302: #define UMOD 118
303: #define ASUDIV 119
304: #define ASUMOD 120
305: #define ULTIMES 121 /* present for symmetry */
306: #define ULDIV 122
307: #define ULMOD 123
308: #define ULASTIMES 124 /* present for symmetry */
309: #define ULASDIV 125
310: #define ULASMOD 126
311: #define ULTOF 127
312: #define ULLSHIFT 128 /* << for unsigned long */
313: #define UASLSHL 129 /* <<= for unsigned long */
314:
315: #define BDATA 200
316: #define PROG 202
317: #define DATA 203
318: #define BSS 204
319: #define CSPACE 205
320: #define SSPACE 206
321: #define SYMDEF 207
322: #define SAVE 208
323: #define RETRN 209
324: #define EVEN 210
325: #define PROFIL 212
326: #define SWIT 213
327: #define EXPR 214
328: #define SNAME 215
329: #define RNAME 216
330: #define ANAME 217
331: #define SETSTK 219
332: #define SINIT 220
333: #define GLOBAL 221
334: #define C3BRANCH 222
335: #define ASSEM 223
336:
337: /*
338: * types
339: */
340: #define INT 0
341: #define CHAR 1
342: #define FLOAT 2
343: #define DOUBLE 3
344: #define STRUCT 4
345: #define RSTRUCT 5
346: #define LONG 6
347: #define UNSIGN 7
348: #define UNCHAR 8
349: #define UNLONG 9
350: #define VOID 10
351:
352: #define TYLEN 2
353: #define TYPE 017
354: #define XTYPE (03<<4)
355: #define PTR 020
356: #define FUNC 040
357: #define ARRAY 060
358:
359: /*
360: storage classes
361: */
362: #define KEYWC 1
363: #define MOS 10
364: #define AUTO 11
365: #define EXTERN 12
366: #define STATIC 13
367: #define REG 14
368: #define STRTAG 15
369: #define ARG 16
370: #define OFFS 20
371: #define XOFFS 21
372: #define SOFFS 22
373:
374: /*
375: Flag bits
376: */
377:
378: #define BINARY 01
379: #define LVALUE 02
380: #define RELAT 04
381: #define ASSGOP 010
382: #define LWORD 020
383: #define RWORD 040
384: #define COMMUTE 0100
385: #define RASSOC 0200
386: #define LEAF 0400
387: #define CNVRT 01000
Defined variables
cctab
defined in line
128; used 17 times
- in /usr/src/lib/ccom/c10.c line
216,
274,
382,
395,
407,
421,
484,
494,
574,
725,
840,
927,
1021
- in /usr/src/lib/ccom/c11.c line
634,
676,
699,
990
cone
defined in line
143; used 2 times
efftab
defined in line
129; used 16 times
- in /usr/src/lib/ccom/c10.c line
210,
224,
263,
332,
386,
399,
577,
1001,
1023
- in /usr/src/lib/ccom/c11.c line
599,
984-987(2),
1140,
1156,
1178,
1193
isn
defined in line
125; used 29 times
- in /usr/src/lib/ccom/c10.c line
485-490(3),
496-500(2),
1221-1222(3)
- in /usr/src/lib/ccom/c11.c line
230,
379,
389-390(3),
428-435(4),
574,
588,
608-609(2),
754,
1046,
1146,
1187-1188(3)
- in /usr/src/lib/ccom/c12.c line
344,
357
line
defined in line
126; used 4 times
nreg
defined in line
124; used 10 times
opdope
defined in line
135; used 34 times
- in /usr/src/lib/ccom/c10.c line
113,
128-135(4),
152,
214,
383,
407,
429,
479,
592,
622,
743,
919-923(2),
951,
961,
1070
- in /usr/src/lib/ccom/c11.c line
21-24(2),
264,
279,
620,
630,
636,
679,
1097
- in /usr/src/lib/ccom/c12.c line
26,
79,
277,
511,
586,
771
regtab
defined in line
130; used 15 times
- in /usr/src/lib/ccom/c10.c line
254,
328-332(2),
407-408(2),
437,
557,
622,
710,
726,
748,
921-924(2),
1212
- in /usr/src/lib/ccom/c11.c line
700
xop
defined in line
171; used 4 times
Defined struct's
fasgn
defined in line
79; used 6 times
lconst
defined in line
60; used 12 times
optab
defined in line
98; used 10 times
swtab
defined in line
117; used 14 times
table
defined in line
106; used 30 times
tconst
defined in line
51; used 10 times
tname
defined in line
27; used 8 times
tnode
defined in line
16; used 6 times
Defined union's
tree
defined in line
88; used 224 times
- in line 20-21(2),
83-84(2),
151-165(30)
- in /usr/src/lib/ccom/c10.c line
97(2),
103-104(4),
188-193(4),
465-471(6),
486-489(4),
911-915(4),
945-948(4),
1042-1045(4),
1086-1090(6),
1109-1111(4),
1140-1144(6),
1164(2),
1175(2),
1186(2),
1239-1241(4),
1254(2),
1352(2)
- in /usr/src/lib/ccom/c11.c line
8-10(4),
33(2),
114(2),
124(2),
141-143(4),
182(2),
241(2),
261(2),
274(2),
488(2),
500-502(4),
561-565(4),
668-672(4),
827-828(4),
1132-1134(4),
1150(2)
- in /usr/src/lib/ccom/c12.c line
8-14(6),
282-284(4),
298-302(6),
601-605(6),
647-658(12),
765(2),
802-806(8),
866-868(4),
973-975(4),
1067-1072(4),
1113-1117(6),
1128-1131(4),
1140-1147(6),
1165-1167(4),
1176-1178(4),
1211(2)
Defined macros
AMPER
defined in line
210; used 14 times
- in /usr/src/lib/ccom/c10.c line
351,
826,
1122,
1209,
1287
- in /usr/src/lib/ccom/c11.c line
16,
254,
1173-1174(2)
- in /usr/src/lib/ccom/c12.c line
307,
465,
493,
698,
1198
AND
defined in line
223; used 6 times
ANDN
defined in line
224; used 4 times
ARG
defined in line
369;
never used
ASOR
defined in line
259; used 2 times
AUTO
defined in line
364; used 1 times
BSS
defined in line
318;
never used
CALL
defined in line
281; used 2 times
CHAR
defined in line
341; used 22 times
- in /usr/src/lib/ccom/c10.c line
535-536(2),
623,
677,
686(2),
970,
1117-1119(2),
1260
- in /usr/src/lib/ccom/c11.c line
25,
131,
150,
195,
207
- in /usr/src/lib/ccom/c12.c line
42,
137-140(2),
382,
518,
551,
692
CON
defined in line
195; used 53 times
- in /usr/src/lib/ccom/c10.c line
30-31(2),
214,
525,
823,
1276,
1282-1285(2),
1297,
1333
- in /usr/src/lib/ccom/c11.c line
14,
172,
254,
492,
640,
693
- in /usr/src/lib/ccom/c12.c line
99,
111,
137,
150-155(2),
198,
220,
231,
239,
251,
266(2),
277,
322,
353,
375,
391,
449,
486,
502,
522,
531,
555,
563,
672(2),
698,
705,
813-817(2),
981,
990,
1086-1087(2),
1134,
1169-1171(2)
DATA
defined in line
317;
never used
DOT
defined in line
215;
never used
EOFC
defined in line
176;
never used
EQUAL
defined in line
240; used 18 times
EVEN
defined in line
324;
never used
EXOR
defined in line
226; used 2 times
EXPR
defined in line
327; used 1 times
FCON
defined in line
197; used 11 times
FSEL
defined in line
186; used 3 times
FTOI
defined in line
229; used 1 times
FTOL
defined in line
232; used 2 times
FUNC
defined in line
356;
never used
GREAT
defined in line
245; used 12 times
INIT
defined in line
285;
never used
INT
defined in line
340; used 38 times
- in /usr/src/lib/ccom/c10.c line
30-31(2),
212,
347,
363,
1117,
1198,
1210,
1264-1267(2)
- in /usr/src/lib/ccom/c11.c line
195-197(2),
522,
1030,
1054(3),
1164
- in /usr/src/lib/ccom/c12.c line
43,
61,
68,
200,
209,
322,
381,
404,
450,
519,
552,
634-635(3),
671,
927,
945,
960,
982,
991
ITOC
defined in line
289;
never used
ITOF
defined in line
228; used 1 times
ITOL
defined in line
234; used 19 times
- in /usr/src/lib/ccom/c10.c line
344,
360,
514,
728,
1332
- in /usr/src/lib/ccom/c11.c line
18,
621(2),
693,
1030
- in /usr/src/lib/ccom/c12.c line
98,
111,
365,
530,
545,
563,
981,
990,
1171
ITOP
defined in line
236; used 1 times
JUMP
defined in line
283;
never used
KEYW
defined in line
193;
never used
LCON
defined in line
199; used 16 times
- in /usr/src/lib/ccom/c10.c line
1278,
1304,
1339
- in /usr/src/lib/ccom/c11.c line
1034
- in /usr/src/lib/ccom/c12.c line
112,
324,
340,
526,
533,
559,
565,
687,
979,
988,
1055-1060(2)
LDIV
defined in line
264; used 1 times
LEAF
defined in line
386; used 12 times
LESS
defined in line
243; used 12 times
LESSP
defined in line
247; used 14 times
LMOD
defined in line
265; used 1 times
LOAD
defined in line
287; used 9 times
LONG
defined in line
346; used 42 times
- in /usr/src/lib/ccom/c10.c line
342,
351,
359,
413,
513(2),
574,
756,
871,
1202,
1228,
1359
- in /usr/src/lib/ccom/c11.c line
173-176(2),
248,
280,
528,
629-630(2),
697,
986,
1030-1035(2),
1166
- in /usr/src/lib/ccom/c12.c line
67,
98,
124,
200,
216,
245,
275,
325,
334,
365,
479,
534,
546,
566,
745,
1061,
1160,
1198
LTOF
defined in line
233; used 2 times
LTOI
defined in line
235; used 12 times
LTOP
defined in line
238;
never used
LTYPE
defined in line
8; used 1 times
MAXP
defined in line
273;
never used
MINP
defined in line
275;
never used
MOD
defined in line
220; used 4 times
MOS
defined in line
363;
never used
NAME
defined in line
194; used 27 times
- in /usr/src/lib/ccom/c10.c line
33,
308,
325,
395-399(2),
552,
966,
992,
998,
1050,
1094,
1205
- in /usr/src/lib/ccom/c11.c line
92,
172,
207,
1013,
1168-1169(2)
- in /usr/src/lib/ccom/c12.c line
21,
131(2),
381,
446,
471,
480-485(2),
501
NEG
defined in line
212; used 2 times
NULL
defined in line
9; used 1 times
OFFS
defined in line
370; used 7 times
OR
defined in line
225; used 2 times
PLUS
defined in line
216; used 23 times
- in /usr/src/lib/ccom/c10.c line
524-527(2),
953-958(2),
1003,
1098-1101(2),
1210
- in /usr/src/lib/ccom/c11.c line
252
- in /usr/src/lib/ccom/c12.c line
69,
404,
447,
485,
684,
698,
722,
748,
821,
847,
1087,
1095-1097(2)
- in /usr/src/lib/ccom/c13.c line
356
PROG
defined in line
316;
never used
PTOI
defined in line
237; used 3 times
PTR
defined in line
355; used 15 times
REG
defined in line
367; used 12 times
RELAT
defined in line
380; used 14 times
- in /usr/src/lib/ccom/c10.c line
214,
407,
484,
513
- in /usr/src/lib/ccom/c11.c line
264,
279,
620,
630,
636,
679
- in /usr/src/lib/ccom/c12.c line
129,
274-277(2),
511
SAVE
defined in line
322;
never used
SEMI
defined in line
177;
never used
STAR
defined in line
211; used 16 times
- in /usr/src/lib/ccom/c10.c line
148,
154,
733,
819,
958,
1098,
1124,
1169,
1205,
1246
- in /usr/src/lib/ccom/c11.c line
247,
1168-1169(2)
- in /usr/src/lib/ccom/c12.c line
138,
307,
444
SWIT
defined in line
326;
never used
TAND
defined in line
262; used 3 times
TIMES
defined in line
218; used 14 times
TNULL
defined in line
10; used 37 times
- in /usr/src/lib/ccom/c10.c line
276,
347-351(2),
363,
430,
537,
555,
956,
1092-1093(2),
1120,
1209,
1246
- in /usr/src/lib/ccom/c11.c line
522,
529,
697,
987,
1030,
1052,
1071(2),
1105,
1173-1174(2)
- in /usr/src/lib/ccom/c12.c line
52,
61,
105,
119,
200,
256,
335,
365,
416-419(2),
693,
739,
1198
TYPE
defined in line
353; used 8 times
UDIV
defined in line
301; used 5 times
ULSH
defined in line
190; used 3 times
UMOD
defined in line
302; used 1 times
UNCHAR
defined in line
348; used 16 times
- in /usr/src/lib/ccom/c10.c line
429,
535-536(2),
554,
677,
687(2),
1053,
1119,
1260
- in /usr/src/lib/ccom/c11.c line
25,
131,
150,
191
- in /usr/src/lib/ccom/c12.c line
692,
1216
UNLONG
defined in line
349; used 29 times
- in /usr/src/lib/ccom/c10.c line
342,
359,
413,
513(2),
574,
757,
871,
1228,
1359
- in /usr/src/lib/ccom/c11.c line
173-176(2),
248,
280,
629-630(2),
986
- in /usr/src/lib/ccom/c12.c line
98,
124,
216,
245,
275,
348,
479,
745,
1160,
1185,
1194,
1216
UNS
defined in line
11; used 21 times
- in /usr/src/lib/ccom/c10.c line
888,
1220,
1286,
1344(2)
- in /usr/src/lib/ccom/c11.c line
41-42(2),
388-389(2),
429,
452,
787,
850,
860,
893-897(2),
914,
936,
1036,
1148,
1186
UNSIGN
defined in line
347; used 19 times
- in /usr/src/lib/ccom/c10.c line
430,
555,
975
- in /usr/src/lib/ccom/c11.c line
192-197(3)
- in /usr/src/lib/ccom/c12.c line
101-105(2),
335,
435,
612,
636,
671(3),
905-908(2),
952,
1216
VOID
defined in line
350; used 1 times
Usage of this include