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