source: mainline/uspace/app/pcc/cc/ccom/pass1.h@ fae4d30

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fae4d30 was a7de7182, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 14 years ago

Added pcc source tree (contents of pcc-1.0.0.tgz)

  • Property mode set to 100644
File size: 15.9 KB
Line 
1/* $Id: pass1.h,v 1.215 2011/02/17 13:44:13 ragge Exp $ */
2/*
3 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * Redistributions of source code and documentation must retain the above
10 * copyright notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditionsand the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed or owned by Caldera
17 * International, Inc.
18 * Neither the name of Caldera International, Inc. nor the names of other
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27 * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#include "config.h"
37
38#include <sys/types.h>
39#include <stdarg.h>
40#include <string.h>
41#ifdef HAVE_STDINT_H
42#include <stdint.h>
43#endif
44
45#ifndef MKEXT
46#include "external.h"
47#else
48typedef unsigned int bittype; /* XXX - for basicblock */
49#endif
50#include "manifest.h"
51
52#include "ccconfig.h"
53
54/*
55 * Storage classes
56 */
57#define SNULL 0
58#define AUTO 1
59#define EXTERN 2
60#define STATIC 3
61#define REGISTER 4
62#define EXTDEF 5
63/* #define LABEL 6*/
64/* #define ULABEL 7*/
65#define MOS 8
66#define PARAM 9
67#define STNAME 10
68#define MOU 11
69#define UNAME 12
70#define TYPEDEF 13
71/* #define FORTRAN 14 */
72#define ENAME 15
73#define MOE 16
74/* #define UFORTRAN 17 */
75#define USTATIC 18
76
77 /* field size is ORed in */
78#define FIELD 0200
79#define FLDSIZ 0177
80extern char *scnames(int);
81
82/*
83 * Symbol table flags
84 */
85#define SNORMAL 0
86#define STAGNAME 01
87#define SLBLNAME 02
88#define SMOSNAME 03
89#define SSTRING 04
90#define NSTYPES 05
91#define SMASK 07
92
93/* #define SSET 00010 */
94/* #define SREF 00020 */
95#define SNOCREAT 00040 /* don't create a symbol in lookup() */
96#define STEMP 00100 /* Allocate symtab from temp or perm mem */
97#define SDYNARRAY 00200 /* symbol is dynamic array on stack */
98#define SINLINE 00400 /* function is of type inline */
99#define STNODE 01000 /* symbol shall be a temporary node */
100#define SASG 04000 /* symbol is assigned to already */
101#define SLOCAL1 010000
102#define SLOCAL2 020000
103#define SLOCAL3 040000
104
105 /* alignment of initialized quantities */
106#ifndef AL_INIT
107#define AL_INIT ALINT
108#endif
109
110struct rstack;
111struct symtab;
112union arglist;
113#ifdef GCC_COMPAT
114struct gcc_attr_pack;
115#endif
116
117/*
118 * Dimension/prototype information.
119 * ddim > 0 holds the dimension of an array.
120 * ddim < 0 is a dynamic array and refers to a tempnode.
121 * ...unless:
122 * ddim == NOOFFSET, an array without dimenston, "[]"
123 * ddim == -1, dynamic array while building before defid.
124 */
125union dimfun {
126 int ddim; /* Dimension of an array */
127 union arglist *dfun; /* Prototype index */
128};
129
130/*
131 * Argument list member info when storing prototypes.
132 */
133union arglist {
134 TWORD type;
135 union dimfun *df;
136 struct attr *sap;
137};
138#define TNULL INCREF(FARG) /* pointer to FARG -- impossible type */
139#define TELLIPSIS INCREF(INCREF(FARG))
140
141/*
142 * Symbol table definition.
143 */
144struct symtab {
145 struct symtab *snext; /* link to other symbols in the same scope */
146 int soffset; /* offset or value */
147 char sclass; /* storage class */
148 char slevel; /* scope level */
149 short sflags; /* flags, see below */
150 char *sname; /* Symbol name */
151 char *soname; /* Written-out name */
152 TWORD stype; /* type word */
153 TWORD squal; /* qualifier word */
154 union dimfun *sdf; /* ptr to the dimension/prototype array */
155 struct attr *sap; /* the base type attribute list */
156};
157
158struct attr2 {
159 struct attr *next;
160 int atype;
161 union aarg aa[2];
162};
163
164#define ISSOU(ty) ((ty) == STRTY || (ty) == UNIONTY)
165#define MKAP(type) ((struct attr *)&btattr[type])
166extern const struct attr2 btattr[];
167
168/*
169 * External definitions
170 */
171struct swents { /* switch table */
172 struct swents *next; /* Next struct in linked list */
173 CONSZ sval; /* case value */
174 int slab; /* associated label */
175};
176int mygenswitch(int, TWORD, struct swents **, int);
177
178extern int blevel;
179extern int instruct, got_type;
180extern int oldstyle;
181extern int oflag;
182
183extern int lineno, nerrors;
184
185extern char *ftitle;
186extern struct symtab *cftnsp;
187extern int autooff, maxautooff, argoff, strucoff;
188extern int brkflag;
189
190extern OFFSZ inoff;
191
192extern int reached;
193extern int isinlining;
194extern int xinline;
195
196extern int sdebug, idebug, pdebug;
197
198/* various labels */
199extern int brklab;
200extern int contlab;
201extern int flostat;
202extern int retlab;
203
204/* pragma globals */
205extern int pragma_allpacked, pragma_packed, pragma_aligned;
206extern char *pragma_renamed;
207
208/*
209 * Flags used in the (elementary) flow analysis ...
210 */
211#define FBRK 02
212#define FCONT 04
213#define FDEF 010
214#define FLOOP 020
215
216/* mark an offset which is undefined */
217
218#define NOOFFSET (-10201)
219
220/* declarations of various functions */
221extern NODE
222 *buildtree(int, NODE *, NODE *r),
223 *mkty(unsigned, union dimfun *, struct attr *),
224 *rstruct(char *, int),
225 *dclstruct(struct rstack *),
226 *strend(int gtype, char *),
227 *tymerge(NODE *, NODE *),
228 *stref(NODE *),
229 *offcon(OFFSZ, TWORD, union dimfun *, struct attr *),
230 *bcon(int),
231 *xbcon(CONSZ, struct symtab *, TWORD),
232 *bpsize(NODE *),
233 *convert(NODE *, int),
234 *pconvert(NODE *),
235 *oconvert(NODE *),
236 *ptmatch(NODE *),
237 *tymatch(NODE *),
238 *makety(NODE *, TWORD, TWORD, union dimfun *, struct attr *),
239 *block(int, NODE *, NODE *, TWORD, union dimfun *, struct attr *),
240 *doszof(NODE *),
241 *talloc(void),
242 *optim(NODE *),
243 *clocal(NODE *),
244 *ccopy(NODE *),
245 *tempnode(int, TWORD, union dimfun *, struct attr *),
246 *eve(NODE *),
247 *doacall(struct symtab *, NODE *, NODE *);
248NODE *intprom(NODE *);
249OFFSZ tsize(TWORD, union dimfun *, struct attr *),
250 psize(NODE *);
251NODE * typenode(NODE *new);
252void spalloc(NODE *, NODE *, OFFSZ);
253char *exname(char *);
254NODE *floatcon(char *);
255NODE *fhexcon(char *);
256NODE *bdty(int op, ...);
257extern struct rstack *rpole;
258
259int oalloc(struct symtab *, int *);
260void deflabel(char *, NODE *);
261void gotolabel(char *);
262unsigned int esccon(char **);
263void inline_start(struct symtab *);
264void inline_end(void);
265void inline_addarg(struct interpass *);
266void inline_ref(struct symtab *);
267void inline_prtout(void);
268void inline_args(struct symtab **, int);
269NODE *inlinetree(struct symtab *, NODE *, NODE *);
270void ftnarg(NODE *);
271struct rstack *bstruct(char *, int, NODE *);
272void moedef(char *);
273void beginit(struct symtab *);
274void simpleinit(struct symtab *, NODE *);
275struct symtab *lookup(char *, int);
276struct symtab *getsymtab(char *, int);
277char *addstring(char *);
278char *addname(char *);
279void symclear(int);
280struct symtab *hide(struct symtab *);
281void soumemb(NODE *, char *, int);
282int talign(unsigned int, struct attr *);
283void bfcode(struct symtab **, int);
284int chkftn(union arglist *, union arglist *);
285void branch(int);
286void cbranch(NODE *, NODE *);
287void extdec(struct symtab *);
288void defzero(struct symtab *);
289int falloc(struct symtab *, int, NODE *);
290TWORD ctype(TWORD);
291void ninval(CONSZ, int, NODE *);
292void infld(CONSZ, int, CONSZ);
293void zbits(CONSZ, int);
294void instring(struct symtab *);
295void inwstring(struct symtab *);
296void plabel(int);
297void bjobcode(void);
298void ejobcode(int);
299void calldec(NODE *, NODE *);
300int cisreg(TWORD);
301char *tmpsprintf(char *, ...);
302char *tmpvsprintf(char *, va_list);
303void asginit(NODE *);
304void desinit(NODE *);
305void endinit(void);
306void endictx(void);
307void sspinit(void);
308void sspstart(void);
309void sspend(void);
310void ilbrace(void);
311void irbrace(void);
312CONSZ scalinit(NODE *);
313void p1print(char *, ...);
314char *copst(int);
315int cdope(int);
316void myp2tree(NODE *);
317void lcommprint(void);
318void lcommdel(struct symtab *);
319NODE *funcode(NODE *);
320struct symtab *enumhd(char *);
321NODE *enumdcl(struct symtab *);
322NODE *enumref(char *);
323CONSZ icons(NODE *);
324CONSZ valcast(CONSZ v, TWORD t);
325int mypragma(char *);
326char *pragtok(char *);
327int eat(int);
328void fixdef(struct symtab *);
329int cqual(TWORD, TWORD);
330void defloc(struct symtab *);
331int fldchk(int);
332int nncon(NODE *);
333void cunput(char);
334NODE *nametree(struct symtab *sp);
335void *inlalloc(int size);
336void *blkalloc(int size);
337void pass1_lastchance(struct interpass *);
338void fldty(struct symtab *p);
339int getlab(void);
340struct suedef *sueget(struct suedef *p);
341void complinit(void);
342NODE *structref(NODE *p, int f, char *name);
343NODE *cxop(int op, NODE *l, NODE *r);
344NODE *imop(int op, NODE *l, NODE *r);
345NODE *cxelem(int op, NODE *p);
346NODE *cxconj(NODE *p);
347NODE *cxret(NODE *p, NODE *q);
348NODE *cast(NODE *p, TWORD t, TWORD q);
349NODE *ccast(NODE *p, TWORD t, TWORD u, union dimfun *df, struct attr *sue);
350int andable(NODE *);
351int conval(NODE *, int, NODE *);
352int ispow2(CONSZ);
353void defid(NODE *q, int class);
354void efcode(void);
355void ecomp(NODE *p);
356void cendarg(void);
357int fldal(unsigned int);
358int upoff(int size, int alignment, int *poff);
359void nidcl(NODE *p, int class);
360void eprint(NODE *, int, int *, int *);
361int uclass(int class);
362int notlval(NODE *);
363void ecode(NODE *p);
364void bccode(void);
365void ftnend(void);
366void dclargs(void);
367int suemeq(struct attr *s1, struct attr *s2);
368struct symtab *strmemb(struct attr *ap);
369int yylex(void);
370void yyerror(char *);
371int pragmas_gcc(char *t);
372
373NODE *builtin_check(NODE *f, NODE *a);
374
375#ifdef SOFTFLOAT
376typedef struct softfloat SF;
377SF soft_neg(SF);
378SF soft_cast(CONSZ v, TWORD);
379SF soft_plus(SF, SF);
380SF soft_minus(SF, SF);
381SF soft_mul(SF, SF);
382SF soft_div(SF, SF);
383int soft_cmp_eq(SF, SF);
384int soft_cmp_ne(SF, SF);
385int soft_cmp_ge(SF, SF);
386int soft_cmp_gt(SF, SF);
387int soft_cmp_le(SF, SF);
388int soft_cmp_lt(SF, SF);
389int soft_isz(SF);
390CONSZ soft_val(SF);
391#define FLOAT_NEG(sf) soft_neg(sf)
392#define FLOAT_CAST(v,t) soft_cast(v, t)
393#define FLOAT_PLUS(x1,x2) soft_plus(x1, x2)
394#define FLOAT_MINUS(x1,x2) soft_minus(x1, x2)
395#define FLOAT_MUL(x1,x2) soft_mul(x1, x2)
396#define FLOAT_DIV(x1,x2) soft_div(x1, x2)
397#define FLOAT_ISZERO(sf) soft_isz(sf)
398#define FLOAT_VAL(sf) soft_val(sf)
399#define FLOAT_EQ(x1,x2) soft_cmp_eq(x1, x2)
400#define FLOAT_NE(x1,x2) soft_cmp_ne(x1, x2)
401#define FLOAT_GE(x1,x2) soft_cmp_ge(x1, x2)
402#define FLOAT_GT(x1,x2) soft_cmp_gt(x1, x2)
403#define FLOAT_LE(x1,x2) soft_cmp_le(x1, x2)
404#define FLOAT_LT(x1,x2) soft_cmp_lt(x1, x2)
405#else
406#define FLOAT_NEG(p) -(p)
407#define FLOAT_CAST(p,v) (ISUNSIGNED(v) ? \
408 (long double)(U_CONSZ)(p) : (long double)(CONSZ)(p))
409#define FLOAT_PLUS(x1,x2) (x1) + (x2)
410#define FLOAT_MINUS(x1,x2) (x1) - (x2)
411#define FLOAT_MUL(x1,x2) (x1) * (x2)
412#define FLOAT_DIV(x1,x2) (x1) / (x2)
413#define FLOAT_ISZERO(p) (p) == 0.0
414#define FLOAT_VAL(p) (CONSZ)(p)
415#define FLOAT_EQ(x1,x2) (x1) == (x2)
416#define FLOAT_NE(x1,x2) (x1) != (x2)
417#define FLOAT_GE(x1,x2) (x1) >= (x2)
418#define FLOAT_GT(x1,x2) (x1) > (x2)
419#define FLOAT_LE(x1,x2) (x1) <= (x2)
420#define FLOAT_LT(x1,x2) (x1) < (x2)
421#endif
422
423enum { ATTR_NONE,
424
425 /* PCC used attributes */
426 ATTR_COMPLEX, /* Internal definition of complex */
427 ATTR_BASETYP, /* Internal; see below */
428 ATTR_QUALTYP, /* Internal; const/volatile, see below */
429 ATTR_STRUCT, /* Internal; element list */
430#define ATTR_MAX ATTR_STRUCT
431
432#ifdef GCC_COMPAT
433 /* type attributes */
434 GCC_ATYP_ALIGNED,
435 GCC_ATYP_PACKED,
436 GCC_ATYP_SECTION,
437 GCC_ATYP_TRANSP_UNION,
438 GCC_ATYP_UNUSED,
439 GCC_ATYP_DEPRECATED,
440 GCC_ATYP_MAYALIAS,
441
442 /* variable attributes */
443 GCC_ATYP_MODE,
444
445 /* function attributes */
446 GCC_ATYP_NORETURN,
447 GCC_ATYP_FORMAT,
448 GCC_ATYP_NONNULL,
449 GCC_ATYP_SENTINEL,
450 GCC_ATYP_WEAK,
451 GCC_ATYP_FORMATARG,
452 GCC_ATYP_GNU_INLINE,
453 GCC_ATYP_MALLOC,
454 GCC_ATYP_NOTHROW,
455 GCC_ATYP_CONST,
456 GCC_ATYP_PURE,
457 GCC_ATYP_CONSTRUCTOR,
458 GCC_ATYP_DESTRUCTOR,
459 GCC_ATYP_VISIBILITY,
460 GCC_ATYP_STDCALL,
461 GCC_ATYP_CDECL,
462 GCC_ATYP_WARN_UNUSED_RESULT,
463 GCC_ATYP_USED,
464 GCC_ATYP_NO_INSTR_FUN,
465 GCC_ATYP_NOINLINE,
466 GCC_ATYP_ALIAS,
467 GCC_ATYP_WEAKREF,
468 GCC_ATYP_ALLOCSZ,
469 GCC_ATYP_ALW_INL,
470 GCC_ATYP_TLSMODEL,
471 GCC_ATYP_ALIASWEAK,
472
473 /* other stuff */
474 GCC_ATYP_BOUNDED, /* OpenBSD extra boundary checks */
475
476 GCC_ATYP_MAX
477#endif
478};
479
480
481/*
482 * ATTR_BASETYP has the following layout:
483 * aa[0].iarg has size
484 * aa[1].iarg has alignment
485 * ATTR_QUALTYP has the following layout:
486 * aa[0].iarg has CON/VOL + FUN/ARY/PTR
487 * Not defined yet...
488 * aa[3].iarg is dimension for arrays (XXX future)
489 * aa[3].varg is function defs for functions.
490 */
491#define atypsz aa[0].iarg
492#define aalign aa[1].iarg
493
494/*
495 * ATTR_STRUCT member list.
496 */
497#define amlist aa[0].varg
498#define strattr(x) (attr_find(x, ATTR_STRUCT))
499
500#define iarg(x) aa[x].iarg
501#define sarg(x) aa[x].sarg
502#define varg(x) aa[x].varg
503
504void gcc_init(void);
505int gcc_keyword(char *, NODE **);
506struct attr *gcc_attr_parse(NODE *);
507void gcc_tcattrfix(NODE *);
508struct gcc_attrib *gcc_get_attr(struct suedef *, int);
509void dump_attr(struct attr *gap);
510
511struct attr *attr_add(struct attr *orig, struct attr *new);
512struct attr *attr_new(int, int);
513struct attr *attr_find(struct attr *, int);
514struct attr *attr_copy(struct attr *src, struct attr *dst, int nelem);
515struct attr *attr_dup(struct attr *ap, int n);
516
517#ifdef STABS
518void stabs_init(void);
519void stabs_file(char *);
520void stabs_efile(char *);
521void stabs_line(int);
522void stabs_rbrac(int);
523void stabs_lbrac(int);
524void stabs_func(struct symtab *);
525void stabs_newsym(struct symtab *);
526void stabs_chgsym(struct symtab *);
527void stabs_struct(struct symtab *, struct attr *);
528#endif
529
530#ifndef CHARCAST
531/* to make character constants into character connstants */
532/* this is a macro to defend against cross-compilers, etc. */
533#define CHARCAST(x) (char)(x)
534#endif
535
536/* sometimes int is smaller than pointers */
537#if SZPOINT(CHAR) <= SZINT
538#define INTPTR INT
539#elif SZPOINT(CHAR) <= SZLONG
540#define INTPTR LONG
541#elif SZPOINT(CHAR) <= SZLONGLONG
542#define INTPTR LONGLONG
543#else
544#error int size unknown
545#endif
546
547/*
548 * C compiler first pass extra defines.
549 */
550#define QUALIFIER (MAXOP+1)
551#define CLASS (MAXOP+2)
552#define RB (MAXOP+3)
553#define DOT (MAXOP+4)
554#define ELLIPSIS (MAXOP+5)
555#define TYPE (MAXOP+6)
556#define LB (MAXOP+7)
557#define COMOP (MAXOP+8)
558#define QUEST (MAXOP+9)
559#define COLON (MAXOP+10)
560#define ANDAND (MAXOP+11)
561#define OROR (MAXOP+12)
562#define NOT (MAXOP+13)
563#define CAST (MAXOP+14)
564#define STRING (MAXOP+15)
565
566/* The following must be in the same order as their NOASG counterparts */
567#define PLUSEQ (MAXOP+16)
568#define MINUSEQ (MAXOP+17)
569#define DIVEQ (MAXOP+18)
570#define MODEQ (MAXOP+19)
571#define MULEQ (MAXOP+20)
572#define ANDEQ (MAXOP+21)
573#define OREQ (MAXOP+22)
574#define EREQ (MAXOP+23)
575#define LSEQ (MAXOP+24)
576#define RSEQ (MAXOP+25)
577
578#define UNASG (-(PLUSEQ-PLUS))+
579
580#define INCR (MAXOP+26)
581#define DECR (MAXOP+27)
582#define SZOF (MAXOP+28)
583#define CLOP (MAXOP+29)
584#define ATTRIB (MAXOP+30)
585#define XREAL (MAXOP+31)
586#define XIMAG (MAXOP+32)
587#define TYMERGE (MAXOP+33)
588
589
590/*
591 * The following types are only used in pass1.
592 */
593#define SIGNED (MAXTYPES+1)
594#define BOOL (MAXTYPES+2)
595#define FIMAG (MAXTYPES+3)
596#define IMAG (MAXTYPES+4)
597#define LIMAG (MAXTYPES+5)
598#define FCOMPLEX (MAXTYPES+6)
599#define COMPLEX (MAXTYPES+7)
600#define LCOMPLEX (MAXTYPES+8)
601#define ENUMTY (MAXTYPES+9)
602
603#define ISFTY(x) ((x) >= FLOAT && (x) <= LDOUBLE)
604#define ISCTY(x) ((x) >= FCOMPLEX && (x) <= LCOMPLEX)
605#define ISITY(x) ((x) >= FIMAG && (x) <= LIMAG)
606#define ANYCX(p) (p->n_type == STRTY && attr_find(p->n_ap, ATTR_COMPLEX))
607
608#define coptype(o) (cdope(o)&TYFLG)
609#define clogop(o) (cdope(o)&LOGFLG)
610#define casgop(o) (cdope(o)&ASGFLG)
611
Note: See TracBrowser for help on using the repository browser.