Add tests, fixes for tests, reinstate and type-convert stuff marked "bitrot"
[ccom.git] / c0.h
1 /*
2  *      C compiler-- first pass header
3  */
4
5 #ifndef _C0_H
6 #define _C0_H 1
7
8 #include "ccom.h"
9
10 /*
11  * This parameter is the _only_ one which affects the recognized length
12  * of symbols.  Symbol names are dynamically allocated and null terminated
13  * now, the define below is the 'cutoff' or maximum length to permit.
14  *
15  * NOTE: there are _exactly_ 4 references to this in all of c0.  There are
16  * _NO_ references to it in c1.  Just make sure that the value is less than
17  * 79 and c1 will be oblivious to the length of a symbol name.
18  *
19  * NOTE: The optimizer (c2) needs to be updated if the size of a symbol
20  * changes.  See the file c2.h
21 */
22
23 #define MAXCPS  32      /* # chars per symbol */
24
25 #define MAXINT  077777  /* Largest positive short integer */
26 #define MAXUINT 0177777 /* largest unsigned integer */
27 #define HSHSIZ  300     /* # entries in hash table for names */
28 #define CMSIZ   40      /* size of expression stack */
29 #define SSIZE   40      /* size of other expression stack */
30 #define SWSIZ   300     /* size of switch table */
31 #define NMEMS   128     /* Number of members in a structure */
32 #define NBPW    16      /* bits per word, object machine */
33 #define NBPC    8       /* bits per character, object machine */
34 #define NCPW    2       /* chars per word, object machine */
35 #define LNCPW   2       /* chars per word, compiler's machine */
36 #define LNBPW   16      /* bits per word, compiler's machine */
37 /* dlf change
38 #define STAUTO  (-6)     offset of first auto variable */
39 int     STAUTO;
40 #define STARG   4       /* offset of first argument */
41 #define DCLSLOP 512     /* Amount trees lie above declaration stuff */
42
43 /* Nick */
44 #ifdef pdp11
45 #define MAXPATHLEN 64
46 #else
47 #define MAXPATHLEN 1024
48 #endif
49
50
51 /*
52  * # bytes in primitive types
53  */
54 #define SZCHAR  1
55 #define SZINT   2
56 #define SZPTR   2
57 #define SZFLOAT 4
58 #define SZLONG  4
59 #define SZDOUB  8
60
61 extern char cvtab[4][4];
62 extern char filename[MAXPATHLEN]; /* Nick */
63 extern int opdope0[];
64 extern char ctab[];
65 extern char symbuf[MAXCPS+2];
66 extern struct nmlist    *hshtab[HSHSIZ];
67 extern int kwhash[(HSHSIZ+LNBPW-1)/LNBPW];
68 extern struct node **cp;
69 extern int isn0;
70 extern struct swtab swtab[SWSIZ];
71 extern int unscflg;
72 extern struct swtab *swp;
73 extern int contlab;
74 extern int brklab;
75 extern int retlab;
76 extern int deflab;
77 extern unsigned autolen;        /* make these int if necessary */
78 extern unsigned maxauto;        /* ... will only cause trouble rarely */
79 extern int peeksym;
80 extern int peekc;
81 extern int eof;
82 extern int line;
83 extern char *locbase;
84 extern char *treebase;
85 extern char *treebot;
86 extern char *coremax;
87 extern struct nmlist *defsym;
88 extern struct nmlist *funcsym;
89 extern int proflg;
90 extern int Wflag;
91 extern struct nmlist *csym;
92 extern int cval;
93 extern _LONG lcval;
94 extern _DOUBLE fcval;
95 extern int nchstr;
96 extern int nerror;
97 extern struct nmlist *paraml;
98 extern struct nmlist *parame;
99 #if 0
100 extern int strflg;
101 #endif
102 extern int mosflg;
103 extern int initflg;
104 #if 0
105 extern char sbuf[BUFSIZ];
106 extern FILE *sbufp;
107 #endif
108 extern int regvar;
109 extern int bitoffs;
110 extern struct locnnode funcblk;
111 extern char cvntab[];
112 extern char numbuf[64];
113 extern struct nmlist **memlist;
114 extern union str *sparent;
115 extern int nmems;
116 extern struct nmlist structhole;
117 extern int blklev;
118 extern int mossym;
119
120 /*
121   keywords
122 */
123 #define GOTO    20
124 #define RETURN  21
125 #define IF      22
126 #define WHILE   23
127 #define ELSE    24
128 #define SWITCH  25
129 #define CASE    26
130 #define BREAK   27
131 #define CONTIN  28
132 #define DO      29
133 #define DEFAULT 30
134 #define FOR     31
135 #define ENUM    32
136 #define ASM     33
137
138 /*
139   characters
140 */
141 #define BSLASH  117
142 #define SHARP   118
143 #define INSERT  119
144 #define PERIOD  120
145 #define SQUOTE  121
146 #define DQUOTE  122
147 #define LETTER  123
148 #define DIGIT   124
149 #define NEWLN   125
150 #define SPACE   126
151 #define UNKN    127
152
153 /*
154  * Conversion codes
155  */
156 #define ITF     1
157 #define ITL     2
158 #define LTF     3
159 #define ITP     4
160 #define PTI     5
161 #define FTI     6
162 #define LTI     7
163 #define FTL     8
164 #define LTP     9
165 #define ITC     10
166 #define XX      15
167
168 /*
169  * symbol table flags
170  */
171
172 #define FMOS    01
173 #define FTAG    02
174 #define FENUM   03
175 #define FUNION  04
176 #define FKIND   07
177 /*#define       FFIELD  020*/
178 #define FINIT   040
179 #define FLABL   0100
180
181 extern struct kwtab {
182         char    *kwname;
183         int     kwval;
184 } kwtab[];
185
186 #ifndef __P
187 #ifdef __STDC__
188 #define __P(args) args
189 #else
190 #define __P(args) ()
191 #endif
192 #endif
193
194 /* c00.c */
195 int main __P((int argc, char *argv[]));
196 int lookup __P((void));
197 int findkw __P((void));
198 int symbol __P((void));
199 int getnum __P((void));
200 int subseq __P((int c, int a, int b));
201 void putstr __P((int lab, register int max));
202 void cntstr __P((void));
203 int getcc __P((void));
204 int mapch __P((int ac));
205 struct node *tree __P((/*int eflag*/));
206 struct tnode *xprtype __P((void));
207 char *copnum __P((int len));
208
209 /* c01.c */
210 void build __P((int op));
211 void structident __P((register struct node *p1, register struct nnode *p2));
212 struct node *convert __P((struct node *p, int t, int cvn, int len));
213 void setype __P((register struct node *p, register int t, register struct node *newp));
214 struct node *chkfun __P((register struct node *p));
215 struct node *disarray __P((register struct node *p));
216 void chkw __P((struct node *p, int okt));
217 int lintyp __P((int t));
218 void werror0 __P((char *s, ...));
219 void error0 __P((char *s, ...));
220 struct tnode *block __P((int op, int t, int *subs, union str *str, struct node *p1, struct node *p2));
221 struct nnode *nblock __P((register struct nmlist *ds));
222 struct cnode *cblock __P((_INT value));
223 struct lnode *lblock __P((_LONG lvalue));
224 struct fnode *fblock __P((int value, _DOUBLE fvalue));
225 char *Tblock __P((int n));
226 char *starttree __P((void));
227 void endtree __P((char *tp));
228 char *Dblock __P((int n));
229 void chklval __P((register struct node *p));
230 int fold __P((int op, register struct node *p1, struct node *p2));
231 int conexp __P((void));
232 void assignop __P((int op, register struct node *p1, register struct node *p2));
233 struct nmlist *gentemp __P((int type));
234
235 /* c02.c */
236 void extdef __P((void));
237 void cfunc __P((void));
238 int cinit __P((struct nmlist *anp, int flex, int sclass));
239 void strinit __P((struct nmlist *np, int sclass));
240 void setinit __P((register struct nmlist *np));
241 void statement __P((void));
242 int forstmt __P((void));
243 struct node *pexpr __P((/*int eflag*/));
244 void pswitch0 __P((void));
245 void funchead __P((void));
246 void blockhead __P((void));
247 void blkend __P((void));
248 void nameconflict __P((register struct nmlist *ocs, register struct nmlist *cs));
249 void prste __P((struct nmlist *cs));
250 void errflush __P((int ao));
251
252 /* c03.c */
253 int declist __P((int sclass));
254 /*int*/struct type *getkeywords __P((int *scptr/*, struct nmlist *tptr*/));
255 /*union str*/struct stype *strdec __P((int mosf, int kind));
256 int declare __P((int askw, struct /*nmlist*/type *tptr, int offset));
257 void XXXdumptype __P((struct type *dtype));
258 int XXXoldtype __P((struct type *dtype, struct tdim *dimp, struct SS **strp));
259 int decl1 __P((int askw, struct /*nmlist*/type *atptr, int offset, struct nmlist *absname));
260 struct nmlist *pushdecl __P((register struct nmlist *sp));
261 /*int getype __P((register struct tdim *dimp, struct nmlist *absname));*/
262 struct rtype *getype __P((struct rtype *tail, int anonok));
263 void typov __P((void));
264 int align __P((/*int*/struct type *type, int offset, int aflen));
265 void decsyn __P((int o));
266 void redec __P((void));
267 int goodreg __P((struct nmlist *hp));
268
269 /* c04.c */
270 int decref0 __P((register int t));
271 int incref0 __P((register int t));
272 void cbranch0 __P((struct node *t, int lbl, int cond));
273 void rcexpr0 __P((register struct node *tp));
274 void treeout __P((register struct node *tp, int isstruct));
275 void branch0 __P((int lab));
276 void label0 __P((int l));
277 int XXXlength __P((struct node *cs));
278 int plength __P((register struct node *p));
279 int length __P((struct /*node*/type *cs));
280 int rlength __P((struct /*node*/type *cs));
281 int simplegoto __P((void));
282 int nextchar __P((void));
283 int spnextchar __P((void));
284 void chconbrk __P((int l));
285 void dogoto __P((void));
286 void doret __P((void));
287 void outcode __P((char *s, ...));
288 unsigned int hash __P((register char *sp));
289
290 #endif