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