catch DECLARATOR / SPECIFIER abuse
[fw/sdcc] / src / SDCCsymt.h
1 /*-------------------------------------------------------------------------
2   SDCCsymt.h - Header file for Symbols table related structures and MACRO's.              
3               Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1998)
4
5    This program is free software; you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by the
7    Free Software Foundation; either version 2, or (at your option) any
8    later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18    
19    In other words, you are welcome to use, share and improve this program.
20    You are forbidden to forbid anyone else to use, share and improve
21    what you give them.   Help stamp out software-hoarding!  
22 -------------------------------------------------------------------------*/
23
24 #ifndef  SDCCSYMT_H
25 #define  SDCCSYMT_H
26
27 #define MAX_NEST_LEVEL  256
28 #define SDCC_SYMNAME_MAX 64
29 #define SDCC_NAME_MAX  3*SDCC_SYMNAME_MAX // big enough for _<func>_<var>_etc
30 #include "SDCChasht.h"
31 #include "SDCCglobl.h"
32
33 enum {
34     TYPEOF_INT=1,
35     TYPEOF_SHORT,
36     TYPEOF_CHAR,
37     TYPEOF_LONG,
38     TYPEOF_FLOAT,
39     TYPEOF_BIT,
40     TYPEOF_SBIT,
41     TYPEOF_SFR,
42     TYPEOF_VOID,
43     TYPEOF_STRUCT,
44     TYPEOF_ARRAY,
45     TYPEOF_FUNCTION,
46     TYPEOF_POINTER,
47     TYPEOF_FPOINTER,
48     TYPEOF_CPOINTER,
49     TYPEOF_GPOINTER,
50     TYPEOF_PPOINTER,
51     TYPEOF_IPOINTER,
52     TYPEOF_EEPPOINTER
53 };
54
55 // values for first byte of generic pointer.
56 #define GPTYPE_NEAR     0
57 #define GPTYPE_FAR      1
58 #define GPTYPE_CODE     2
59 #define GPTYPE_XSTACK   3
60 #define GPTYPE_GPTR     4       // Never used?
61 #define GPTYPE_IDATA    5
62
63 #define HASHTAB_SIZE 256
64
65 /* hash table bucket */
66 typedef struct bucket
67   {
68     void *sym;                  /* pointer to the object   */
69     char name[SDCC_NAME_MAX + 1];       /* name of this symbol          */
70     int level;                  /* nest level for this symbol   */
71     int block;                  /* belongs to which block */
72     struct bucket *prev;        /* ptr 2 previous bucket   */
73     struct bucket *next;        /* ptr 2 next bucket       */
74   }
75 bucket;
76
77 typedef struct structdef
78   {
79     char tag[SDCC_NAME_MAX + 1];        /* tag part of structure      */
80     unsigned char level;        /* Nesting level         */
81     struct symbol *fields;      /* pointer to fields     */
82     unsigned size;              /* sizeof the table in bytes  */
83   }
84 structdef;
85
86 /* noun definitions */
87 typedef enum
88   {
89     V_INT = 1,
90     V_FLOAT,
91     V_CHAR,
92     V_VOID,
93     V_STRUCT,
94     V_LABEL,
95     V_BIT,
96     V_SBIT,
97     V_DOUBLE
98   }
99 NOUN;
100
101 /* storage class    */
102 typedef enum
103   {
104     S_FIXED = 0,
105     S_AUTO,
106     S_REGISTER,
107     S_SFR,
108     S_SBIT,
109     S_CODE,
110     S_XDATA,
111     S_DATA,
112     S_IDATA,
113     S_PDATA,
114     S_LITERAL,
115     S_STACK,
116     S_XSTACK,
117     S_BIT,
118     S_EEPROM
119   }
120 STORAGE_CLASS;
121
122 /* specifier is the last in the type-chain */
123 typedef struct specifier
124   {
125     NOUN noun;                  /* CHAR INT STRUCTURE LABEL   */
126     STORAGE_CLASS sclass;       /* REGISTER,AUTO,FIX,CONSTANT */
127     struct memmap *oclass;      /* output storage class       */
128     unsigned _long:1;           /* 1=long            */
129     unsigned _short:1;          /* 1=short int    */
130     unsigned _unsigned:1;       /* 1=unsigned, 0=signed       */
131     unsigned _signed:1;         /* just for sanity checks only*/
132     unsigned _static:1;         /* 1=static keyword found     */
133     unsigned _extern:1;         /* 1=extern found             */
134     unsigned _absadr:1;         /* absolute address specfied  */
135     unsigned _volatile:1;       /* is marked as volatile      */
136     unsigned _const:1;          /* is a constant              */
137     unsigned _typedef:1;        /* is typedefed               */
138     unsigned _isregparm:1;      /* is the first parameter     */
139     unsigned _isenum:1;         /* is an enumerated type      */
140     unsigned _addr;             /* address of symbol          */
141     unsigned _stack;            /* stack offset for stacked v */
142     unsigned _bitStart;         /* bit start position         */
143     int _bitLength;             /* bit length                 */
144     int argreg;                 /* reg no for regparm         */
145     union
146       {                         /* Values if constant or enum */
147         TYPE_WORD   v_int;      /* 2 bytes: int and char values        */
148         char       *v_char;     /*          character string           */
149         TYPE_UWORD  v_uint;     /* 2 bytes: unsigned int const value   */
150         TYPE_DWORD  v_long;     /* 4 bytes: long constant value        */
151         TYPE_UDWORD v_ulong;    /* 4 bytes: unsigned long constant val */
152         double      v_float;    /*          floating point constant value */
153         struct symbol *v_enum;  /* ptr 2 enum_list if enum==1 */
154       }
155     const_val;
156     struct structdef *v_struct; /* structure pointer      */
157   }
158 specifier;
159
160 /* types of declarators */
161 typedef enum
162   {
163     POINTER = 0,                /* pointer to near data */
164     FPOINTER,                   /* pointer to far data  */
165     CPOINTER,                   /* pointer to code space */
166     GPOINTER,                   /* _generic pointer     */
167     PPOINTER,                   /* paged area pointer   */
168     IPOINTER,                   /* pointer to upper 128 bytes */
169     UPOINTER,                   /* unknown pointer used only when parsing */
170     EEPPOINTER,                 /* pointer to eeprom     */
171     ARRAY,
172     FUNCTION
173   }
174 DECLARATOR_TYPE;
175
176 typedef struct declarator
177   {
178     DECLARATOR_TYPE dcl_type;   /* POINTER,ARRAY or FUNCTION  */
179     unsigned int num_elem;      /* # of elems if type==array  */
180     unsigned ptr_const:1;       /* pointer is constant        */
181     unsigned ptr_volatile:1;    /* pointer is volatile        */
182     struct sym_link *tspec;     /* pointer type specifier     */
183   }
184 declarator;
185
186 typedef enum {
187   DECLARATOR=1,
188   SPECIFIER
189 } SYM_LINK_CLASS;
190 #define DECLSPEC2TXT(select) (select==DECLARATOR?"DECLARATOR":select==SPECIFIER?"SPECIFIER":"UNKNOW")
191
192 typedef struct sym_link
193   {
194     SYM_LINK_CLASS class;       /* DECLARATOR or SPECIFIER    */
195     unsigned tdef:1;            /* current link created by    */
196     /* typedef if this flag is set */
197     union
198       {
199         specifier s;            /* if CLASS == SPECIFIER      */
200         declarator d;           /* if CLASS == DECLARATOR     */
201       } select;
202
203     /* function attributes */
204     struct {
205       struct value *args;       /* the defined arguments      */
206       unsigned hasVargs:1;      /* functions has varargs      */
207       unsigned calleeSaves:1;   /* functions uses callee save */
208       unsigned hasbody:1;       /* function body defined      */
209       unsigned hasFcall:1;      /* does it call other functions */
210       unsigned reent:1;         /* function is reentrant      */
211       unsigned naked:1;         /* naked function             */
212
213       unsigned nonbanked:1;     /* function has the nonbanked attribute */
214       unsigned banked:1;        /* function has the banked attribute */
215       unsigned critical:1;      /* critical function          */
216       unsigned intrtn:1;        /* this is an interrupt routin */
217       unsigned rbank:1;         /* seperate register bank     */
218       unsigned intno;           /* 1=Interrupt svc routine    */
219       unsigned regbank;         /* register bank 2b used      */
220       unsigned builtin;         /* is a builtin function      */
221       unsigned javaNative;      /* is a JavaNative Function (TININative ONLY) */
222       unsigned overlay;         /* force parameters & locals into overlay segment */
223       unsigned hasStackParms;   /* function has parameters on stack */
224     } funcAttrs;
225
226     struct sym_link *next;      /* next element on the chain  */
227   }
228 sym_link;
229
230 typedef struct symbol
231   {
232     char name[SDCC_SYMNAME_MAX + 1];    /* Input Variable Name     */
233     char rname[SDCC_NAME_MAX + 1];      /* internal name           */
234
235     short level;                /* declration lev,fld offset */
236     short block;                /* sequential block # of defintion */
237     int key;
238     unsigned implicit:1;        /* implicit flag                     */
239     unsigned undefined:1;       /* undefined variable                */
240     unsigned _isparm:1;         /* is a parameter          */
241     unsigned ismyparm:1;        /* is parameter of the function being generated */
242     unsigned isitmp:1;          /* is an intermediate temp */
243     unsigned islbl:1;           /* is a temporary label */
244     unsigned isref:1;           /* has been referenced  */
245     unsigned isind:1;           /* is a induction variable */
246     unsigned isinvariant:1;     /* is a loop invariant  */
247     unsigned cdef:1;            /* compiler defined symbol */
248     unsigned addrtaken:1;       /* address of the symbol was taken */
249     unsigned isreqv:1;          /* is the register quivalent of a symbol */
250     unsigned udChked:1;         /* use def checking has been already done */
251
252     /* following flags are used by the backend
253        for code generation and can be changed
254        if a better scheme for backend is thought of */
255     unsigned isLiveFcall:1;     /* is live at or across a function call */
256     unsigned isspilt:1;         /* has to be spilt */
257     unsigned spillA:1;          /* spilt be register allocator */
258     unsigned remat:1;           /* can be remateriazed */
259     unsigned isptr:1;           /* is a pointer */
260     unsigned uptr:1;            /* used as a pointer */
261     unsigned isFree:1;          /* used by register allocator */
262     unsigned islocal:1;         /* is a local variable        */
263     unsigned blockSpil:1;       /* spilt at block level       */
264     unsigned remainSpil:1;      /* spilt because not used in remainder */
265     unsigned stackSpil:1;       /* has been spilt on temp stack location */
266     unsigned onStack:1;         /* this symbol allocated on the stack */
267     unsigned iaccess:1;         /* indirect access      */
268     unsigned ruonly:1;          /* used in return statement only */
269     unsigned spildir:1;         /* spilt in direct space */
270     unsigned ptrreg:1;          /* this symbol assigned to a ptr reg */
271     unsigned noSpilLoc:1;       /* cannot be assigned a spil location */
272     unsigned isstrlit;          /* is a string literal and it's usage count  */
273     unsigned accuse;            /* can be left in the accumulator
274                                    On the Z80 accuse is devided into
275                                    ACCUSE_A and ACCUSE_HL as the idea
276                                    is quite similar.
277                                  */
278     unsigned dptr;              /* 8051 variants with multiple DPTRS
279                                    currently implemented in DS390 only
280                                 */
281     int allocreq ;              /* allocation is required for this variable */
282     int stack;                  /* offset on stack      */
283     int xstack;                 /* offset on xternal stack */
284     short nRegs;                /* number of registers required */
285     short regType;              /* type of register required    */
286
287     struct regs *regs[4];       /* can have at the most 4 registers */
288     struct asmop *aop;          /* asmoperand for this symbol */
289     struct iCode *fuse;         /* furthest use */
290     struct iCode *rematiCode;   /* rematerialse with which instruction */
291     struct operand *reqv;       /* register equivalent of a local variable */
292     union
293       {
294         struct symbol *spillLoc;        /* register spil location */
295         struct set *itmpStack;  /* symbols spilt @ this stack location */
296       }
297     usl;
298     short bitVar;               /* this is a bit variable    */
299     unsigned offset;            /* offset from top if struct */
300
301     int lineDef;                /* defined line number        */
302     int lastLine;               /* for functions the last line */
303     struct sym_link *type;      /* 1st link to declator chain */
304     struct sym_link *etype;     /* last link to declarator chn */
305     struct symbol *next;        /* crosslink to next symbol   */
306     struct symbol *localof;     /* local variable of which function */
307     struct initList *ival;      /* ptr to initializer if any  */
308     struct bitVect *defs;       /* bit vector for definitions */
309     struct bitVect *uses;       /* bit vector for uses        */
310     struct bitVect *regsUsed;   /* for functions registers used */
311     int liveFrom;               /* live from iCode sequence number */
312     int liveTo;                 /* live to sequence number */
313     int used;                   /* no. of times this was used */
314     int recvSize;               /* size of first argument  */
315     struct bitVect *clashes;    /* overlaps with what other symbols */
316   }
317 symbol;
318
319 extern sym_link *validateLink(sym_link  *l, 
320                                const char       *macro,
321                                const char       *args,
322                                const char       select,
323                                const char       *file, 
324                                unsigned         line);
325 /* Easy Access Macros */
326 #define DCL_TYPE(l)  validateLink(l, "DCL_TYPE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.dcl_type
327 #define DCL_ELEM(l)  validateLink(l, "DCL_ELEM", #l, DECLARATOR, __FILE__, __LINE__)->select.d.num_elem
328 #define DCL_PTR_CONST(l) validateLink(l, "DCL_PTR_CONST", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_const
329 #define DCL_PTR_VOLATILE(l) validateLink(l, "DCL_PTR_VOLATILE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_volatile
330 #define DCL_TSPEC(l) validateLink(l, "DCL_TSPEC", #l, DECLARATOR, __FILE__, __LINE__)->select.d.tspec
331
332 #define FUNC_DEBUG //assert(IS_FUNC(x));
333 #define FUNC_HASVARARGS(x) (x->funcAttrs.hasVargs)
334 #define IFFUNC_HASVARARGS(x) (IS_FUNC(x) && FUNC_HASVARARGS(x))
335 #define FUNC_ARGS(x) (x->funcAttrs.args)
336 #define IFFUNC_ARGS(x) (IS_FUNC(x) && FUNC_ARGS(x))
337 #define FUNC_HASFCALL(x) (x->funcAttrs.hasFcall)
338 #define IFFUNC_HASFCALL(x) (IS_FUNC(x) && FUNC_HASFCALL(x))
339 #define FUNC_HASBODY(x) (x->funcAttrs.hasbody)
340 #define IFFUNC_HASBODY(x) (IS_FUNC(x) && FUNC_HASBODY(x))
341 #define FUNC_CALLEESAVES(x) (x->funcAttrs.calleeSaves)
342 #define IFFUNC_CALLEESAVES(x) (IS_FUNC(x) && FUNC_CALLEESAVES(x))
343 #define FUNC_ISISR(x) (x->funcAttrs.intrtn)
344 #define IFFUNC_ISISR(x) (IS_FUNC(x) && FUNC_ISISR(x))
345 #define IFFUNC_RBANK(x) (IS_FUNC(x) && FUNC_RBANK(x))
346 #define FUNC_INTNO(x) (x->funcAttrs.intno)
347 #define FUNC_REGBANK(x) (x->funcAttrs.regbank)
348 #define FUNC_HASSTACKPARM(x) (x->funcAttrs.hasStackParms)
349
350 #define FUNC_ISREENT(x) (x->funcAttrs.reent)
351 #define IFFUNC_ISREENT(x) (IS_FUNC(x) && FUNC_ISREENT(x))
352 #define FUNC_ISNAKED(x) (x->funcAttrs.naked)
353 #define IFFUNC_ISNAKED(x) (IS_FUNC(x) && FUNC_ISNAKED(x))
354 #define FUNC_NONBANKED(x) (x->funcAttrs.nonbanked)
355 #define IFFUNC_NONBANKED(x) (IS_FUNC(x) && FUNC_NONBANKED(x))
356 #define FUNC_BANKED(x) (x->funcAttrs.banked)
357 #define IFFUNC_BANKED(x) (IS_FUNC(x) && FUNC_BANKED(x))
358 #define FUNC_ISCRITICAL(x) (x->funcAttrs.critical)
359 #define IFFUNC_ISCRITICAL(x) (IS_FUNC(x) && FUNC_ISCRITICAL(x))
360 #define FUNC_ISBUILTIN(x) (x->funcAttrs.builtin)
361 #define IFFUNC_ISBUILTIN(x) (IS_FUNC(x) && FUNC_ISBUILTIN(x))
362 #define FUNC_ISJAVANATIVE(x) (x->funcAttrs.javaNative)
363 #define IFFUNC_ISJAVANATIVE(x) (IS_FUNC(x) && FUNC_ISJAVANATIVE(x))
364 #define FUNC_ISOVERLAY(x) (x->funcAttrs.overlay)
365 #define IFFUNC_ISOVERLAY(x) (IS_FUNC(x) && FUNC_ISOVERLAY(x))
366
367
368 // jwk: I am not sure about this
369 #define IFFUNC_ISBANKEDCALL(x) (!IFFUNC_NONBANKED(x) && \
370   (options.model == MODEL_LARGE || \
371    options.model == MODEL_MEDIUM || \
372   IFFUNC_BANKED(x)))
373
374 #define SPEC_NOUN(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.noun
375 #define SPEC_LONG(x) validateLink(x, "SPEC_LONG", #x, SPECIFIER, __FILE__, __LINE__)->select.s._long
376 #define SPEC_USIGN(x) validateLink(x, "SPEC_USIGN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._unsigned
377 #define SPEC_SCLS(x) validateLink(x, "SPEC_SCLS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.sclass
378 #define SPEC_ENUM(x) validateLink(x, "SPEC_ENUM", #x, SPECIFIER, __FILE__, __LINE__)->select.s._isenum
379 #define SPEC_OCLS(x) validateLink(x, "SPEC_OCLS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.oclass
380 #define SPEC_STAT(x) validateLink(x, "SPEC_STAT", #x, SPECIFIER, __FILE__, __LINE__)->select.s._static
381 #define SPEC_EXTR(x) validateLink(x, "SPEC_EXTR", #x, SPECIFIER, __FILE__, __LINE__)->select.s._extern
382 #define SPEC_CODE(x) validateLink(x, "SPEC_CODE", #x, SPECIFIER, __FILE__, __LINE__)->select.s._codesg
383 #define SPEC_ABSA(x) validateLink(x, "SPEC_ABSA", #x, SPECIFIER, __FILE__, __LINE__)->select.s._absadr
384 #define SPEC_BANK(x) validateLink(x, "SPEC_BANK", #x, SPECIFIER, __FILE__, __LINE__)->select.s._regbank
385 #define SPEC_ADDR(x) validateLink(x, "SPEC_ADDR", #x, SPECIFIER, __FILE__, __LINE__)->select.s._addr
386 #define SPEC_STAK(x) validateLink(x, "SPEC_STAK", #x, SPECIFIER, __FILE__, __LINE__)->select.s._stack
387 #define SPEC_CVAL(x) validateLink(x, "SPEC_CVAL", #x, SPECIFIER, __FILE__, __LINE__)->select.s.const_val
388 #define SPEC_BSTR(x) validateLink(x, "SPEC_BSTR", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
389 #define SPEC_BLEN(x) validateLink(x, "SPEC_BLEN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitLength
390
391 /* Sleaze: SPEC_ISR_SAVED_BANKS is only used on 
392  * function type symbols, which obviously cannot
393  * be of BIT type. Therefore, we recycle the 
394  * _bitStart field instead of defining a new field.
395  */
396 #define SPEC_ISR_SAVED_BANKS(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
397 #define SPEC_VOLATILE(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._volatile
398 #define SPEC_CONST(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._const
399 #define SPEC_STRUCT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.v_struct
400 #define SPEC_TYPEDEF(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._typedef
401 #define SPEC_REGPARM(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._isregparm
402 #define SPEC_ARGREG(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.argreg
403
404 /* type check macros */
405 #define IS_DECL(x)   ( x && x->class == DECLARATOR      )
406 #define IS_SPEC(x)   ( x && x->class == SPECIFIER  )
407 #define IS_ARRAY(x)  (IS_DECL(x) && DCL_TYPE(x) == ARRAY)
408 #define IS_DATA_PTR(x) (IS_DECL(x) && DCL_TYPE(x) == POINTER)
409 #define IS_PTR(x)    (IS_DECL(x) && (DCL_TYPE(x) == POINTER    ||    \
410                                      DCL_TYPE(x) == FPOINTER   ||    \
411                                      DCL_TYPE(x) == GPOINTER   ||    \
412                                      DCL_TYPE(x) == IPOINTER   ||    \
413                                      DCL_TYPE(x) == PPOINTER   ||    \
414                                      DCL_TYPE(x) == EEPPOINTER ||    \
415                                      DCL_TYPE(x) == CPOINTER   ||    \
416                                      DCL_TYPE(x) == UPOINTER  ))
417 #define IS_PTR_CONST(x) (IS_PTR(x) && DCL_PTR_CONST(x))
418 #define IS_FARPTR(x) (IS_DECL(x) && DCL_TYPE(x) == FPOINTER)
419 #define IS_CODEPTR(x) (IS_DECL(x) && DCL_TYPE(x) == CPOINTER)
420 #define IS_GENPTR(x) (IS_DECL(x) && DCL_TYPE(x) == GPOINTER)
421 #define IS_FUNC(x)   (IS_DECL(x) && DCL_TYPE(x) == FUNCTION)
422 #define IS_LONG(x)   (IS_SPEC(x) && x->select.s._long)
423 #define IS_UNSIGNED(x) (IS_SPEC(x) && x->select.s._unsigned)
424 #define IS_TYPEDEF(x)(IS_SPEC(x) && x->select.s._typedef)
425 #define IS_CONSTANT(x)  (!x ? 0 : \
426                            IS_SPEC(x) ? \
427                            x->select.s._const : \
428                            x->select.d.ptr_const)
429 #define IS_STRUCT(x) (IS_SPEC(x) && x->select.s.noun == V_STRUCT)
430 #define IS_ABSOLUTE(x)  (IS_SPEC(x) && x->select.s._absadr )
431 #define IS_REGISTER(x)  (IS_SPEC(x) && SPEC_SCLS(x) == S_REGISTER)
432 #define IS_RENT(x)   (IS_SPEC(x) && x->select.s._reent )
433 #define IS_STATIC(x) (IS_SPEC(x) && SPEC_STAT(x))
434 #define IS_INT(x)    (IS_SPEC(x) && x->select.s.noun == V_INT)
435 #define IS_VOID(x)   (IS_SPEC(x) && x->select.s.noun == V_VOID)
436 #define IS_CHAR(x)   (IS_SPEC(x) && x->select.s.noun == V_CHAR)
437 #define IS_EXTERN(x)    (IS_SPEC(x) && x->select.s._extern)
438 #define IS_VOLATILE(x)  (!x ? 0 : \
439                            IS_SPEC(x) ? \
440                            x->select.s._volatile : \
441                            x->select.d.ptr_volatile)
442 #define IS_INTEGRAL(x) (IS_SPEC(x) && (x->select.s.noun == V_INT ||  \
443                                        x->select.s.noun == V_CHAR || \
444                                        x->select.s.noun == V_BIT ||  \
445                                        x->select.s.noun == V_SBIT ))
446 #define IS_BITFIELD(x) (IS_SPEC(x) && (x->select.s.noun == V_BIT))
447 #define IS_BITVAR(x) (IS_SPEC(x) && (x->select.s.noun  == V_BIT ||   \
448                                      x->select.s.noun == V_SBIT ))
449 #define IS_FLOAT(x)  (IS_SPEC(x) && x->select.s.noun == V_FLOAT)
450 #define IS_ARITHMETIC(x) (IS_INTEGRAL(x) || IS_FLOAT(x))
451 #define IS_AGGREGATE(x) (IS_ARRAY(x) || IS_STRUCT(x))
452 #define IS_LITERAL(x)   (IS_SPEC(x)  && x->select.s.sclass == S_LITERAL)
453 #define IS_CODE(x)      (IS_SPEC(x)  && SPEC_SCLS(x) == S_CODE)
454 #define IS_REGPARM(x)   (IS_SPEC(x) && SPEC_REGPARM(x))
455
456 /* forward declaration for the global vars */
457 extern bucket *SymbolTab[];
458 extern bucket *StructTab[];
459 extern bucket *TypedefTab[];
460 extern bucket *LabelTab[];
461 extern bucket *enumTab[];
462 extern symbol *__fsadd;
463 extern symbol *__fssub;
464 extern symbol *__fsmul;
465 extern symbol *__fsdiv;
466 extern symbol *__fseq;
467 extern symbol *__fsneq;
468 extern symbol *__fslt;
469 extern symbol *__fslteq;
470 extern symbol *__fsgt;
471 extern symbol *__fsgteq;
472
473 /* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
474 extern symbol *__muldiv[3][3][2];
475 /* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */
476 extern sym_link *__multypes[3][2];
477 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
478 extern symbol *__conv[2][3][2];
479 /* Dims: shift left/shift right, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
480 extern symbol *__rlrr[2][3][2];
481
482 #define CHARTYPE        __multypes[0][0]
483 #define UCHARTYPE       __multypes[0][1]
484 #define INTTYPE         __multypes[1][0]
485 #define UINTTYPE        __multypes[1][1]
486 #define LONGTYPE        __multypes[2][0]
487 #define ULONGTYPE       __multypes[2][1]
488
489
490 extern sym_link *floatType;
491
492 #include "SDCCval.h"
493
494 /* forward definitions for the symbol table related functions */
495 void initSymt ();
496 symbol *newSymbol (char *, int);
497 sym_link *newLink (SYM_LINK_CLASS);
498 sym_link *newFloatLink ();
499 structdef *newStruct (char *);
500 void addDecl (symbol *, int, sym_link *);
501 sym_link *mergeSpec (sym_link *, sym_link *, char *name);
502 symbol *reverseSyms (symbol *);
503 sym_link *reverseLink (sym_link *);
504 symbol *copySymbol (symbol *);
505 symbol *copySymbolChain (symbol *);
506 void printSymChain (symbol *, int);
507 void printStruct (structdef *, int);
508 char *genSymName (int);
509 sym_link *getSpec (sym_link *);
510 char *genSymName (int);
511 int compStructSize (int, structdef *);
512 sym_link *copyLinkChain (sym_link *);
513 int checkDecl (symbol *, int);
514 void checkBasic (sym_link *, sym_link *);
515 value *checkPointerIval (sym_link *, value *);
516 value *checkStructIval (symbol *, value *);
517 value *checkArrayIval (sym_link *, value *);
518 value *checkIval (sym_link *, value *);
519 unsigned int getSize (sym_link *);
520 unsigned int bitsForType (sym_link *);
521 sym_link *newIntLink ();
522 sym_link *newCharLink ();
523 sym_link *newLongLink ();
524 int compareType (sym_link *, sym_link *);
525 int checkFunction (symbol *, symbol *);
526 void cleanUpLevel (bucket **, int);
527 void cleanUpBlock (bucket **, int);
528 int funcInChain (sym_link *);
529 void addSymChain (symbol *);
530 sym_link *structElemType (sym_link *, value *);
531 symbol *getStructElement (structdef *, symbol *);
532 sym_link *computeType (sym_link *, sym_link *);
533 void processFuncArgs (symbol *);
534 int isSymbolEqual (symbol *, symbol *);
535 int powof2 (unsigned long);
536 void printTypeChain (sym_link *, FILE *);
537 void initCSupport ();
538 void initBuiltIns ();
539 void pointerTypes (sym_link *, sym_link *);
540 void cdbTypeInfo (sym_link *, FILE *);
541 void cdbSymbol (symbol *, FILE *, int, int);
542 void cdbStructBlock (int, FILE *);
543 void initHashT ();
544 bucket *newBucket ();
545 void addSym (bucket **, void *, char *, int, int, int checkType);
546 void deleteSym (bucket **, void *, char *);
547 void *findSym (bucket **, void *, const char *);
548 void *findSymWithLevel (bucket **, struct symbol *);
549 void *findSymWithBlock (bucket **, struct symbol *, int);
550 void changePointer (symbol * sym);
551 void checkTypeSanity(sym_link *etype, char *name);
552 sym_link *typeFromStr (char *) ;
553
554
555 extern char *nounName(sym_link *); /* noun strings */
556 extern void printFromToType (sym_link *, sym_link *);
557
558 #endif