Research V7 development
[unix-history] / usr / src / cmd / c / c0.h
CommitLineData
1a3b21a9
DR
1#
2/*
3* C compiler-- first pass header
4*/
5
6#include <stdio.h>
7
8/*
9 * parameters
10 */
11
12#define LTYPE long /* change to int if no long consts */
13#define MAXINT 077777 /* Largest positive short integer */
14#define MAXUINT 0177777 /* largest unsigned integer */
15#define NCPS 8 /* # chars per symbol */
16#define HSHSIZ 400 /* # entries in hash table for names */
17#define CMSIZ 40 /* size of expression stack */
18#define SSIZE 20 /* size of other expression stack */
19#define SWSIZ 230 /* size of switch table */
20#define NMEMS 128 /* Number of members in a structure */
21#define NBPW 16 /* bits per word, object machine */
22#define NBPC 8 /* bits per character, object machine */
23#define NCPW 2 /* chars per word, object machine */
24#define LNCPW 2 /* chars per word, compiler's machine */
25#define STAUTO (-6) /* offset of first auto variable */
26#define STARG 4 /* offset of first argument */
27
28
29/*
30 * # bytes in primitive types
31 */
32#define SZCHAR 1
33#define SZINT 2
34#define SZPTR 2
35#define SZFLOAT 4
36#define SZLONG 4
37#define SZDOUB 8
38
39/*
40 * format of a structure description
41 */
42struct str {
43 int ssize; /* structure size */
44 struct hshtab **memlist; /* member list */
45};
46
47/*
48 * For fields, strp points here instead.
49 */
50struct field {
51 int flen; /* field width in bits */
52 int bitoffs; /* shift count */
53};
54
55/*
56 * Structure of tree nodes for operators
57 */
58struct tnode {
59 int op; /* operator */
60 int type; /* data type */
61 int *subsp; /* subscript list (for arrays) */
62 struct str *strp; /* structure description for structs */
63 struct tnode *tr1; /* left operand */
64 struct tnode *tr2; /* right operand */
65};
66
67/*
68 * Tree node for constants
69 */
70struct cnode {
71 int op;
72 int type;
73 int *subsp;
74 struct str *strp;
75 int value;
76};
77
78/*
79 * Tree node for long constants
80 */
81struct lnode {
82 int op;
83 int type;
84 int *subsp;
85 struct str *strp;
86 LTYPE lvalue;
87};
88
89/*
90 * tree node for floating
91 * constants
92 */
93struct fnode {
94 int op;
95 int type;
96 int *subsp;
97 struct str *strp;
98 char *cstr;
99};
100
101/*
102 * Structure of namelist
103 */
104/*
105 * Pushed-down entry for block structure
106 */
107struct phshtab {
108 char hclass;
109 char hflag;
110 int htype;
111 int *hsubsp;
112 struct str *hstrp;
113 int hoffset;
114 struct phshtab *hpdown;
115 char hblklev;
116};
117
118/*
119 * Top-level namelist
120 */
121struct hshtab {
122 char hclass; /* storage class */
123 char hflag; /* various flags */
124 int htype; /* type */
125 int *hsubsp; /* subscript list */
126 struct str *hstrp; /* structure description */
127 int hoffset; /* post-allocation location */
128 struct phshtab *hpdown; /* Pushed-down name in outer block */
129 char hblklev; /* Block level of definition */
130 char name[NCPS]; /* ASCII name */
131};
132
133/*
134 * Place used to keep dimensions
135 * during declarations
136 */
137struct tdim {
138 int rank;
139 int dimens[5];
140};
141
142/*
143 * Table for recording switches.
144 */
145struct swtab {
146 int swlab;
147 int swval;
148};
149
150char cvtab[4][4];
151char filename[64];
152int opdope[];
153char ctab[];
154char symbuf[NCPS+2];
155int hshused;
156struct hshtab hshtab[HSHSIZ];
157struct tnode **cp;
158int isn;
159struct swtab swtab[SWSIZ];
160struct swtab *swp;
161int contlab;
162int brklab;
163int retlab;
164int deflab;
165unsigned autolen; /* make these int if necessary */
166unsigned maxauto; /* ... will only cause trouble rarely */
167int peeksym;
168int peekc;
169int eof;
170int line;
171char *funcbase;
172char *curbase;
173char *coremax;
174char *maxdecl;
175struct hshtab *defsym;
176struct hshtab *funcsym;
177int proflg;
178struct hshtab *csym;
179int cval;
180LTYPE lcval;
181int nchstr;
182int nerror;
183struct hshtab **paraml;
184struct hshtab **parame;
185int strflg;
186int mosflg;
187int initflg;
188int inhdr;
189char sbuf[BUFSIZ];
190FILE *sbufp;
191int regvar;
192int bitoffs;
193struct tnode funcblk;
194char cvntab[];
195char numbuf[64];
196struct hshtab **memlist;
197int nmems;
198struct hshtab structhole;
199int blklev;
200int mossym;
201
202/*
203 operators
204*/
205#define EOFC 0
206#define NULLOP 218
207#define SEMI 1
208#define LBRACE 2
209#define RBRACE 3
210#define LBRACK 4
211#define RBRACK 5
212#define LPARN 6
213#define RPARN 7
214#define COLON 8
215#define COMMA 9
216#define FSEL 10
217#define CAST 11
218#define ETYPE 12
219
220#define KEYW 19
221#define NAME 20
222#define CON 21
223#define STRING 22
224#define FCON 23
225#define SFCON 24
226#define LCON 25
227#define SLCON 26
228
229#define SIZEOF 91
230#define INCBEF 30
231#define DECBEF 31
232#define INCAFT 32
233#define DECAFT 33
234#define EXCLA 34
235#define AMPER 35
236#define STAR 36
237#define NEG 37
238#define COMPL 38
239
240#define DOT 39
241#define PLUS 40
242#define MINUS 41
243#define TIMES 42
244#define DIVIDE 43
245#define MOD 44
246#define RSHIFT 45
247#define LSHIFT 46
248#define AND 47
249#define OR 48
250#define EXOR 49
251#define ARROW 50
252#define ITOF 51
253#define FTOI 52
254#define LOGAND 53
255#define LOGOR 54
256#define FTOL 56
257#define LTOF 57
258#define ITOL 58
259#define LTOI 59
260#define ITOP 13
261#define PTOI 14
262#define LTOP 15
263
264#define EQUAL 60
265#define NEQUAL 61
266#define LESSEQ 62
267#define LESS 63
268#define GREATEQ 64
269#define GREAT 65
270#define LESSEQP 66
271#define LESSP 67
272#define GREATQP 68
273#define GREATP 69
274
275#define ASPLUS 70
276#define ASMINUS 71
277#define ASTIMES 72
278#define ASDIV 73
279#define ASMOD 74
280#define ASRSH 75
281#define ASLSH 76
282#define ASSAND 77
283#define ASOR 78
284#define ASXOR 79
285#define ASSIGN 80
286
287#define QUEST 90
288#define MAX 93
289#define MAXP 94
290#define MIN 95
291#define MINP 96
292#define SEQNC 97
293#define CALL 100
294#define MCALL 101
295#define JUMP 102
296#define CBRANCH 103
297#define INIT 104
298#define SETREG 105
299#define RFORCE 110
300#define BRANCH 111
301#define LABEL 112
302#define NLABEL 113
303#define RLABEL 114
304#define STRASG 115
305#define ITOC 109
306#define SEOF 200 /* stack EOF marker in expr compilation */
307
308/*
309 types
310*/
311#define INT 0
312#define CHAR 1
313#define FLOAT 2
314#define DOUBLE 3
315#define STRUCT 4
316#define LONG 6
317#define UNSIGN 7
318#define UNION 8 /* adjusted later to struct */
319
320#define ALIGN 01
321#define TYPE 07
322#define BIGTYPE 060000
323#define TYLEN 2
324#define XTYPE (03<<3)
325#define PTR 010
326#define FUNC 020
327#define ARRAY 030
328
329/*
330 storage classes
331*/
332#define KEYWC 1
333#define DEFXTRN 20
334#define TYPEDEF 9
335#define MOS 10
336#define AUTO 11
337#define EXTERN 12
338#define STATIC 13
339#define REG 14
340#define STRTAG 15
341#define ARG 16
342#define ARG1 17
343#define AREG 18
344#define MOU 21
345#define ENUMTAG 22
346#define ENUMCON 24
347
348/*
349 keywords
350*/
351#define GOTO 20
352#define RETURN 21
353#define IF 22
354#define WHILE 23
355#define ELSE 24
356#define SWITCH 25
357#define CASE 26
358#define BREAK 27
359#define CONTIN 28
360#define DO 29
361#define DEFAULT 30
362#define FOR 31
363#define ENUM 32
364
365/*
366 characters
367*/
368#define BSLASH 117
369#define SHARP 118
370#define INSERT 119
371#define PERIOD 120
372#define SQUOTE 121
373#define DQUOTE 122
374#define LETTER 123
375#define DIGIT 124
376#define NEWLN 125
377#define SPACE 126
378#define UNKN 127
379
380/*
381 * Special operators in intermediate code
382 */
383#define BDATA 200
384#define WDATA 201
385#define PROG 202
386#define DATA 203
387#define BSS 204
388#define CSPACE 205
389#define SSPACE 206
390#define SYMDEF 207
391#define SAVE 208
392#define RETRN 209
393#define EVEN 210
394#define PROFIL 212
395#define SWIT 213
396#define EXPR 214
397#define SNAME 215
398#define RNAME 216
399#define ANAME 217
400#define SETSTK 219
401#define SINIT 220
402
403/*
404 Flag bits
405*/
406
407#define BINARY 01
408#define LVALUE 02
409#define RELAT 04
410#define ASSGOP 010
411#define LWORD 020
412#define RWORD 040
413#define COMMUTE 0100
414#define RASSOC 0200
415#define LEAF 0400
416
417/*
418 * Conversion codes
419 */
420#define ITF 1
421#define ITL 2
422#define LTF 3
423#define ITP 4
424#define PTI 5
425#define FTI 6
426#define LTI 7
427#define FTL 8
428#define LTP 9
429#define ITC 10
430#define XX 15
431
432/*
433 * symbol table flags
434 */
435
436#define FMOS 01
437#define FKEYW 04
438#define FFIELD 020
439#define FINIT 040
440#define FLABL 0100
441
442/*
443 * functions
444 */
445char *sbrk();
446struct tnode *tree();
447char *copnum();
448struct tnode *convert();
449struct tnode *chkfun();
450struct tnode *disarray();
451struct tnode *block();
452struct cnode *cblock();
453struct fnode *fblock();
454char *gblock();
455struct tnode *pexpr();
456struct str *strdec();
457struct hshtab *xprtype();
458struct tnode *nblock();