1 /*-------------------------------------------------------------------------
2 SDCCsymt.h - Header file for Symbols table related structures and MACRO's.
3 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
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
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.
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.
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 -------------------------------------------------------------------------*/
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"
34 #define INTNO_MAX 255 /* maximum allowed interrupt number */
35 #define INTNO_UNSPEC (INTNO_MAX+1) /* interrupt number unspecified */
63 // values for first byte (or 3 most significant bits) of generic pointer.
65 #define GPTYPE_FAR 0x00
66 #define GPTYPE_NEAR 0x40
67 #define GPTYPE_XSTACK 0x60
68 #define GPTYPE_CODE 0x80
70 #define GPTYPE_FAR (port->gp_tags.tag_far)
71 #define GPTYPE_NEAR (port->gp_tags.tag_near)
72 #define GPTYPE_XSTACK (port->gp_tags.tag_xstack)
73 #define GPTYPE_CODE (port->gp_tags.tag_code)
76 #define HASHTAB_SIZE 256
78 /* hash table bucket */
81 void *sym; /* pointer to the object */
82 char name[SDCC_NAME_MAX + 1]; /* name of this symbol */
83 int level; /* nest level for this symbol */
84 int block; /* belongs to which block */
85 struct bucket *prev; /* ptr 2 previous bucket */
86 struct bucket *next; /* ptr 2 next bucket */
90 typedef struct structdef
92 char tag[SDCC_NAME_MAX + 1]; /* tag part of structure */
93 unsigned char level; /* Nesting level */
94 struct symbol *fields; /* pointer to fields */
95 unsigned size; /* sizeof the table in bytes */
96 int type; /* STRUCT or UNION */
97 bool b_flexArrayMember; /* has got an flexible array member,
98 only needed for syntax checks */
102 /* noun definitions */
140 #define TYPE_TARGET_CHAR TYPE_BYTE
141 #define TYPE_TARGET_INT TYPE_WORD
142 #define TYPE_TARGET_LONG TYPE_DWORD
143 #define TYPE_TARGET_UCHAR TYPE_UBYTE
144 #define TYPE_TARGET_UINT TYPE_UWORD
145 #define TYPE_TARGET_ULONG TYPE_UDWORD
147 /* specifier is the last in the type-chain */
148 typedef struct specifier
150 NOUN noun; /* CHAR INT STRUCTURE LABEL */
151 STORAGE_CLASS sclass; /* REGISTER,AUTO,FIX,CONSTANT */
152 struct memmap *oclass; /* output storage class */
153 unsigned b_long:1; /* 1=long */
154 unsigned b_short:1; /* 1=short int */
155 unsigned b_unsigned:1; /* 1=unsigned, 0=signed */
156 unsigned b_signed:1; /* just for sanity checks only*/
157 unsigned b_static:1; /* 1=static keyword found */
158 unsigned b_extern:1; /* 1=extern found */
159 unsigned b_inline:1; /* inline function requested */
160 unsigned b_absadr:1; /* absolute address specfied */
161 unsigned b_volatile:1; /* is marked as volatile */
162 unsigned b_const:1; /* is a constant */
163 unsigned b_restrict:1; /* is restricted */
164 unsigned b_typedef:1; /* is typedefed */
165 unsigned b_isregparm:1; /* is the first parameter */
166 unsigned b_isenum:1; /* is an enumerated type */
167 unsigned _addr; /* address of symbol */
168 unsigned _stack; /* stack offset for stacked v */
169 unsigned _bitStart; /* bit start position */
170 int _bitLength; /* bit length */
171 int argreg; /* reg no for regparm */
173 { /* Values if constant or enum */
174 TYPE_TARGET_INT v_int; /* 2 bytes: int and char values */
175 char *v_char; /* character string */
176 TYPE_TARGET_UINT v_uint; /* 2 bytes: unsigned int const value */
177 TYPE_TARGET_LONG v_long; /* 4 bytes: long constant value */
178 TYPE_TARGET_ULONG v_ulong; /* 4 bytes: unsigned long constant value */
179 double v_float; /* floating point constant value */
180 TYPE_TARGET_ULONG v_fixed16x16; /* 4 bytes: fixed floating point constant value */
181 struct symbol *v_enum; /* ptr to enum_list if enum==1 */
184 struct structdef *v_struct; /* structure pointer */
188 /* types of declarators */
191 POINTER = 0, /* pointer to near data */
192 FPOINTER, /* pointer to far data */
193 CPOINTER, /* pointer to code space */
194 GPOINTER, /* _generic pointer */
195 PPOINTER, /* paged area pointer */
196 IPOINTER, /* pointer to upper 128 bytes */
197 UPOINTER, /* unknown pointer used only when parsing */
198 EEPPOINTER, /* pointer to eeprom */
204 typedef struct declarator
206 DECLARATOR_TYPE dcl_type; /* POINTER,ARRAY or FUNCTION */
207 unsigned int num_elem; /* # of elems if type==array, */
208 /* always 0 for flexible arrays */
209 unsigned ptr_const:1; /* pointer is constant */
210 unsigned ptr_volatile:1; /* pointer is volatile */
211 unsigned ptr_restrict:1; /* pointer is resticted */
212 struct sym_link *tspec; /* pointer type specifier */
220 #define DECLSPEC2TXT(select) (select==DECLARATOR?"DECLARATOR":select==SPECIFIER?"SPECIFIER":"UNKNOWN")
222 typedef struct sym_link
224 SYM_LINK_CLASS class; /* DECLARATOR or SPECIFIER */
225 unsigned tdef:1; /* current link created by */
226 /* typedef if this flag is set */
229 specifier s; /* if CLASS == SPECIFIER */
230 declarator d; /* if CLASS == DECLARATOR */
233 /* function attributes */
235 struct value *args; /* the defined arguments */
236 unsigned hasVargs:1; /* functions has varargs */
237 unsigned calleeSaves:1; /* functions uses callee save */
238 unsigned hasbody:1; /* function body defined */
239 unsigned hasFcall:1; /* does it call other functions */
240 unsigned reent:1; /* function is reentrant */
241 unsigned naked:1; /* naked function */
243 unsigned shadowregs:1; /* function uses shadow registers (pic16 port) */
244 unsigned wparam:1; /* first byte of arguments is passed via WREG (pic16 port) */
245 unsigned nonbanked:1; /* function has the nonbanked attribute */
246 unsigned banked:1; /* function has the banked attribute */
247 unsigned critical:1; /* critical function */
248 unsigned intrtn:1; /* this is an interrupt routine */
249 unsigned rbank:1; /* seperate register bank */
250 unsigned inlinereq:1; /* inlining requested */
251 unsigned intno; /* 1=Interrupt svc routine */
252 short regbank; /* register bank 2b used */
253 unsigned builtin; /* is a builtin function */
254 unsigned javaNative; /* is a JavaNative Function (TININative ONLY) */
255 unsigned overlay; /* force parameters & locals into overlay segment */
256 unsigned hasStackParms; /* function has parameters on stack */
259 struct sym_link *next; /* next element on the chain */
263 typedef struct symbol
265 char name[SDCC_SYMNAME_MAX + 1]; /* Input Variable Name */
266 char rname[SDCC_NAME_MAX + 1]; /* internal name */
268 short level; /* declaration lev,fld offset */
269 short block; /* sequential block # of definition */
271 unsigned flexArrayLength; /* if the symbol specifies a struct
272 with a "flexible array member", then the additional length in bytes for
273 the "fam" is stored here. Because the length can be different from symbol
274 to symbol AND v_struct isn't copied in copyLinkChain(), it's located here
275 in the symbol and not in v_struct or the declarator */
276 unsigned implicit:1; /* implicit flag */
277 unsigned undefined:1; /* undefined variable */
278 unsigned infertype:1; /* type should be inferred from first assign */
279 unsigned _isparm:1; /* is a parameter */
280 unsigned ismyparm:1; /* is parameter of the function being generated */
281 unsigned isitmp:1; /* is an intermediate temp */
282 unsigned islbl:1; /* is a temporary label */
283 unsigned isref:1; /* has been referenced */
284 unsigned isind:1; /* is a induction variable */
285 unsigned isinvariant:1; /* is a loop invariant */
286 unsigned cdef:1; /* compiler defined symbol */
287 unsigned addrtaken:1; /* address of the symbol was taken */
288 unsigned isreqv:1; /* is the register equivalent of a symbol */
289 unsigned udChked:1; /* use def checking has been already done */
290 unsigned generated:1; /* code generated (function symbols only) */
292 /* following flags are used by the backend
293 for code generation and can be changed
294 if a better scheme for backend is thought of */
295 unsigned isLiveFcall:1; /* is live at or across a function call */
296 unsigned isspilt:1; /* has to be spilt */
297 unsigned spillA:1; /* spilt be register allocator */
298 unsigned remat:1; /* can be remateriazed */
299 unsigned isptr:1; /* is a pointer */
300 unsigned uptr:1; /* used as a pointer */
301 unsigned isFree:1; /* used by register allocator */
302 unsigned islocal:1; /* is a local variable */
303 unsigned blockSpil:1; /* spilt at block level */
304 unsigned remainSpil:1; /* spilt because not used in remainder */
305 unsigned stackSpil:1; /* has been spilt on temp stack location */
306 unsigned onStack:1; /* this symbol allocated on the stack */
307 unsigned iaccess:1; /* indirect access */
308 unsigned ruonly:1; /* used in return statement only */
309 unsigned spildir:1; /* spilt in direct space */
310 unsigned ptrreg:1; /* this symbol assigned to a ptr reg */
311 unsigned noSpilLoc:1; /* cannot be assigned a spil location */
312 unsigned isstrlit; /* is a string literal and it's usage count */
313 unsigned accuse; /* can be left in the accumulator
314 On the Z80 accuse is divided into
315 ACCUSE_A and ACCUSE_HL as the idea
318 unsigned dptr; /* 8051 variants with multiple DPTRS
319 currently implemented in DS390 only
321 int allocreq ; /* allocation is required for this variable */
322 int stack; /* offset on stack */
323 int xstack; /* offset on xternal stack */
324 short nRegs; /* number of registers required */
325 short regType; /* type of register required */
327 struct regs *regs[4]; /* can have at the most 4 registers */
328 struct asmop *aop; /* asmoperand for this symbol */
329 struct iCode *fuse; /* furthest use */
330 struct iCode *rematiCode; /* rematerialise with which instruction */
331 struct operand *reqv; /* register equivalent of a local variable */
332 struct symbol *prereqv; /* symbol before register equiv. substitution */
333 struct symbol *psbase; /* if pseudo symbol, the symbol it is based on */
336 struct symbol *spillLoc; /* register spil location */
337 struct set *itmpStack; /* symbols spilt @ this stack location */
340 short bitVar; /* this is a bit variable */
341 unsigned offset; /* offset from top if struct */
343 int lineDef; /* defined line number */
344 char *fileDef; /* defined filename */
345 int lastLine; /* for functions the last line */
346 struct sym_link *type; /* 1st link to declarator chain */
347 struct sym_link *etype; /* last link to declarator chain */
348 struct symbol *next; /* crosslink to next symbol */
349 struct symbol *localof; /* local variable of which function */
350 struct initList *ival; /* ptr to initializer if any */
351 struct bitVect *defs; /* bit vector for definitions */
352 struct bitVect *uses; /* bit vector for uses */
353 struct bitVect *regsUsed; /* for functions registers used */
354 int liveFrom; /* live from iCode sequence number */
355 int liveTo; /* live to sequence number */
356 int used; /* no. of times this was used */
357 int recvSize; /* size of first argument */
358 struct bitVect *clashes; /* overlaps with what other symbols */
359 struct ast * funcTree; /* function body ast if inlined */
363 extern sym_link *validateLink(sym_link *l,
369 /* Easy Access Macros */
370 #define IS_OP_RUONLY(x) (IS_SYMOP(x) && OP_SYMBOL(x) && OP_SYMBOL(x)->ruonly)
371 #define IS_OP_ACCUSE(x) (IS_SYMOP(x) && OP_SYMBOL(x) && OP_SYMBOL(x)->accuse)
373 #define DCL_TYPE(l) validateLink(l, "DCL_TYPE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.dcl_type
374 #define DCL_ELEM(l) validateLink(l, "DCL_ELEM", #l, DECLARATOR, __FILE__, __LINE__)->select.d.num_elem
375 #define DCL_PTR_CONST(l) validateLink(l, "DCL_PTR_CONST", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_const
376 #define DCL_PTR_VOLATILE(l) validateLink(l, "DCL_PTR_VOLATILE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_volatile
377 #define DCL_PTR_RESTRICT(l) validateLink(l, "DCL_PTR_RESTRICT", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_restrict
378 #define DCL_TSPEC(l) validateLink(l, "DCL_TSPEC", #l, DECLARATOR, __FILE__, __LINE__)->select.d.tspec
380 #define FUNC_DEBUG //assert(IS_FUNC(x));
381 #define FUNC_HASVARARGS(x) (x->funcAttrs.hasVargs)
382 #define IFFUNC_HASVARARGS(x) (IS_FUNC(x) && FUNC_HASVARARGS(x))
383 #define FUNC_ARGS(x) (x->funcAttrs.args)
384 #define IFFUNC_ARGS(x) (IS_FUNC(x) && FUNC_ARGS(x))
385 #define FUNC_HASFCALL(x) (x->funcAttrs.hasFcall)
386 #define IFFUNC_HASFCALL(x) (IS_FUNC(x) && FUNC_HASFCALL(x))
387 #define FUNC_HASBODY(x) (x->funcAttrs.hasbody)
388 #define IFFUNC_HASBODY(x) (IS_FUNC(x) && FUNC_HASBODY(x))
389 #define FUNC_CALLEESAVES(x) (x->funcAttrs.calleeSaves)
390 #define IFFUNC_CALLEESAVES(x) (IS_FUNC(x) && FUNC_CALLEESAVES(x))
391 #define FUNC_ISISR(x) (x->funcAttrs.intrtn)
392 #define IFFUNC_ISISR(x) (IS_FUNC(x) && FUNC_ISISR(x))
393 #define IFFUNC_RBANK(x) (IS_FUNC(x) && FUNC_RBANK(x))
394 #define FUNC_INTNO(x) (x->funcAttrs.intno)
395 #define FUNC_REGBANK(x) (x->funcAttrs.regbank)
396 #define FUNC_HASSTACKPARM(x) (x->funcAttrs.hasStackParms)
397 #define FUNC_ISINLINE(x) (x->funcAttrs.inlinereq)
398 #define IFFUNC_ISINLINE(x) (IS_FUNC(x) && FUNC_ISINLINE(x))
400 #define FUNC_ISREENT(x) (x->funcAttrs.reent)
401 #define IFFUNC_ISREENT(x) (IS_FUNC(x) && FUNC_ISREENT(x))
402 #define FUNC_ISSHADOWREGS(x) (x->funcAttrs.shadowregs)
403 #define IFFUNC_ISSHADOWREGS(x) (IS_FUNC(x) && FUNC_ISSHADOWREGS(x))
404 #define FUNC_ISWPARAM(x) (x->funcAttrs.wparam)
405 #define IFFUNC_ISWPARAM(x) (IS_FUNC(x) && FUNC_ISWPARAM(x))
406 #define FUNC_ISNAKED(x) (x->funcAttrs.naked)
407 #define IFFUNC_ISNAKED(x) (IS_FUNC(x) && FUNC_ISNAKED(x))
408 #define FUNC_NONBANKED(x) (x->funcAttrs.nonbanked)
409 #define IFFUNC_NONBANKED(x) (IS_FUNC(x) && FUNC_NONBANKED(x))
410 #define FUNC_BANKED(x) (x->funcAttrs.banked)
411 #define IFFUNC_BANKED(x) (IS_FUNC(x) && FUNC_BANKED(x))
412 #define FUNC_ISCRITICAL(x) (x->funcAttrs.critical)
413 #define IFFUNC_ISCRITICAL(x) (IS_FUNC(x) && FUNC_ISCRITICAL(x))
414 #define FUNC_ISBUILTIN(x) (x->funcAttrs.builtin)
415 #define IFFUNC_ISBUILTIN(x) (IS_FUNC(x) && FUNC_ISBUILTIN(x))
416 #define FUNC_ISJAVANATIVE(x) (x->funcAttrs.javaNative)
417 #define IFFUNC_ISJAVANATIVE(x) (IS_FUNC(x) && FUNC_ISJAVANATIVE(x))
418 #define FUNC_ISOVERLAY(x) (x->funcAttrs.overlay)
419 #define IFFUNC_ISOVERLAY(x) (IS_FUNC(x) && FUNC_ISOVERLAY(x))
421 #define IFFUNC_ISBANKEDCALL(x) (!IFFUNC_NONBANKED(x) && \
422 (options.model == MODEL_HUGE || \
423 ((options.model == MODEL_LARGE || options.model == MODEL_MEDIUM) && \
424 (TARGET_IS_Z80 || TARGET_IS_GBZ80)) || \
427 #define SPEC_NOUN(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.noun
428 #define SPEC_LONG(x) validateLink(x, "SPEC_LONG", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_long
429 #define SPEC_SHORT(x) validateLink(x, "SPEC_LONG", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_short
430 #define SPEC_USIGN(x) validateLink(x, "SPEC_USIGN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_unsigned
431 #define SPEC_SCLS(x) validateLink(x, "SPEC_SCLS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.sclass
432 #define SPEC_ENUM(x) validateLink(x, "SPEC_ENUM", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_isenum
433 #define SPEC_OCLS(x) validateLink(x, "SPEC_OCLS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.oclass
434 #define SPEC_STAT(x) validateLink(x, "SPEC_STAT", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_static
435 #define SPEC_EXTR(x) validateLink(x, "SPEC_EXTR", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_extern
436 #define SPEC_CODE(x) validateLink(x, "SPEC_CODE", #x, SPECIFIER, __FILE__, __LINE__)->select.s._codesg
437 #define SPEC_ABSA(x) validateLink(x, "SPEC_ABSA", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_absadr
438 #define SPEC_BANK(x) validateLink(x, "SPEC_BANK", #x, SPECIFIER, __FILE__, __LINE__)->select.s._regbank
439 #define SPEC_ADDR(x) validateLink(x, "SPEC_ADDR", #x, SPECIFIER, __FILE__, __LINE__)->select.s._addr
440 #define SPEC_STAK(x) validateLink(x, "SPEC_STAK", #x, SPECIFIER, __FILE__, __LINE__)->select.s._stack
441 #define SPEC_CVAL(x) validateLink(x, "SPEC_CVAL", #x, SPECIFIER, __FILE__, __LINE__)->select.s.const_val
442 #define SPEC_BSTR(x) validateLink(x, "SPEC_BSTR", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
443 #define SPEC_BLEN(x) validateLink(x, "SPEC_BLEN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitLength
445 /* Sleaze: SPEC_ISR_SAVED_BANKS is only used on
446 * function type symbols, which obviously cannot
447 * be of BIT type. Therefore, we recycle the
448 * _bitStart field instead of defining a new field.
450 #define SPEC_ISR_SAVED_BANKS(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
451 #define SPEC_VOLATILE(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_volatile
452 #define SPEC_CONST(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_const
453 #define SPEC_RESTRICT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_restrict
454 #define SPEC_STRUCT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.v_struct
455 #define SPEC_TYPEDEF(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_typedef
456 #define SPEC_REGPARM(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_isregparm
457 #define SPEC_ARGREG(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.argreg
458 #define SPEC_INLINE(x) validateLink(x, "SPEC_INLINE", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_inline
460 /* type check macros */
461 #define IS_DECL(x) ( x && x->class == DECLARATOR )
462 #define IS_SPEC(x) ( x && x->class == SPECIFIER )
463 #define IS_ARRAY(x) (IS_DECL(x) && DCL_TYPE(x) == ARRAY)
464 #define IS_DATA_PTR(x) (IS_DECL(x) && DCL_TYPE(x) == POINTER)
465 #define IS_PTR(x) (IS_DECL(x) && (DCL_TYPE(x) == POINTER || \
466 DCL_TYPE(x) == FPOINTER || \
467 DCL_TYPE(x) == GPOINTER || \
468 DCL_TYPE(x) == IPOINTER || \
469 DCL_TYPE(x) == PPOINTER || \
470 DCL_TYPE(x) == EEPPOINTER || \
471 DCL_TYPE(x) == CPOINTER || \
472 DCL_TYPE(x) == UPOINTER ))
473 #define IS_PTR_CONST(x) (IS_PTR(x) && DCL_PTR_CONST(x))
474 #define IS_PTR_RESTRICT(x) (IS_PTR(x) && DCL_PTR_RESTRICT(x))
475 #define IS_FARPTR(x) (IS_DECL(x) && DCL_TYPE(x) == FPOINTER)
476 #define IS_CODEPTR(x) (IS_DECL(x) && DCL_TYPE(x) == CPOINTER)
477 #define IS_GENPTR(x) (IS_DECL(x) && DCL_TYPE(x) == GPOINTER)
478 #define IS_FUNCPTR(x) (IS_DECL(x) && (DCL_TYPE(x) == CPOINTER || DCL_TYPE(x) == GPOINTER) && IS_FUNC(x->next))
479 #define IS_FUNC(x) (IS_DECL(x) && DCL_TYPE(x) == FUNCTION)
480 #define IS_LONG(x) (IS_SPEC(x) && x->select.s.b_long)
481 #define IS_UNSIGNED(x) (IS_SPEC(x) && x->select.s.b_unsigned)
482 #define IS_TYPEDEF(x)(IS_SPEC(x) && x->select.s.b_typedef)
483 #define IS_CONSTANT(x) (!x ? 0 : \
485 x->select.s.b_const : \
486 x->select.d.ptr_const)
487 #define IS_STRUCT(x) (IS_SPEC(x) && x->select.s.noun == V_STRUCT)
488 #define IS_ABSOLUTE(x) (IS_SPEC(x) && x->select.s.b_absadr )
489 #define IS_REGISTER(x) (IS_SPEC(x) && SPEC_SCLS(x) == S_REGISTER)
490 #define IS_RENT(x) (IS_SPEC(x) && x->select.s._reent )
491 #define IS_STATIC(x) (IS_SPEC(x) && SPEC_STAT(x))
492 #define IS_INLINE(x) (IS_SPEC(x) && SPEC_INLINE(x))
493 #define IS_INT(x) (IS_SPEC(x) && x->select.s.noun == V_INT)
494 #define IS_VOID(x) (IS_SPEC(x) && x->select.s.noun == V_VOID)
495 #define IS_CHAR(x) (IS_SPEC(x) && x->select.s.noun == V_CHAR)
496 #define IS_EXTERN(x) (IS_SPEC(x) && x->select.s.b_extern)
497 #define IS_VOLATILE(x) (!x ? 0 : \
499 x->select.s.b_volatile : \
500 x->select.d.ptr_volatile)
501 #define IS_INTEGRAL(x) (IS_SPEC(x) && (x->select.s.noun == V_INT || \
502 x->select.s.noun == V_CHAR || \
503 x->select.s.noun == V_BITFIELD || \
504 x->select.s.noun == V_BIT || \
505 x->select.s.noun == V_SBIT ))
506 #define IS_BITFIELD(x) (IS_SPEC(x) && (x->select.s.noun == V_BITFIELD))
507 #define IS_BITVAR(x) (IS_SPEC(x) && (x->select.s.noun == V_BITFIELD || \
508 x->select.s.noun == V_BIT || \
509 x->select.s.noun == V_SBIT ))
510 #define IS_BIT(x) (IS_SPEC(x) && (x->select.s.noun == V_BIT || \
511 x->select.s.noun == V_SBIT ))
512 #define IS_FLOAT(x) (IS_SPEC(x) && x->select.s.noun == V_FLOAT)
513 #define IS_FIXED16X16(x) (IS_SPEC(x) && x->select.s.noun == V_FIXED16X16)
514 #define IS_FIXED(x) (IS_FIXED16X16(x))
515 #define IS_ARITHMETIC(x) (IS_INTEGRAL(x) || IS_FLOAT(x) || IS_FIXED(x))
516 #define IS_AGGREGATE(x) (IS_ARRAY(x) || IS_STRUCT(x))
517 #define IS_LITERAL(x) (IS_SPEC(x) && x->select.s.sclass == S_LITERAL)
518 #define IS_CODE(x) (IS_SPEC(x) && SPEC_SCLS(x) == S_CODE)
519 #define IS_REGPARM(x) (IS_SPEC(x) && SPEC_REGPARM(x))
521 /* symbol check macros */
522 #define IS_AUTO(x) (x->level && !IS_STATIC(x->etype) && !IS_EXTERN(x->etype))
524 /* forward declaration for the global vars */
525 extern bucket *SymbolTab[];
526 extern bucket *StructTab[];
527 extern bucket *TypedefTab[];
528 extern bucket *LabelTab[];
529 extern bucket *enumTab[];
530 extern symbol *__fsadd;
531 extern symbol *__fssub;
532 extern symbol *__fsmul;
533 extern symbol *__fsdiv;
534 extern symbol *__fseq;
535 extern symbol *__fsneq;
536 extern symbol *__fslt;
537 extern symbol *__fslteq;
538 extern symbol *__fsgt;
539 extern symbol *__fsgteq;
541 extern symbol *__fps16x16_add;
542 extern symbol *__fps16x16_sub;
543 extern symbol *__fps16x16_mul;
544 extern symbol *__fps16x16_div;
545 extern symbol *__fps16x16_eq;
546 extern symbol *__fps16x16_neq;
547 extern symbol *__fps16x16_lt;
548 extern symbol *__fps16x16_lteq;
549 extern symbol *__fps16x16_gt;
550 extern symbol *__fps16x16_gteq;
552 /* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
553 extern symbol *__muldiv[3][3][2];
554 /* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */
555 extern sym_link *__multypes[3][2];
556 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
557 extern symbol *__conv[2][3][2];
558 /* Dims: to/from fixed16x16, BYTE/WORD/DWORD/FLOAT, SIGNED/USIGNED */
559 extern symbol *__fp16x16conv[2][4][2];
560 /* Dims: shift left/shift right, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
561 extern symbol *__rlrr[2][3][2];
563 #define CHARTYPE __multypes[0][0]
564 #define UCHARTYPE __multypes[0][1]
565 #define INTTYPE __multypes[1][0]
566 #define UINTTYPE __multypes[1][1]
567 #define LONGTYPE __multypes[2][0]
568 #define ULONGTYPE __multypes[2][1]
570 extern sym_link *floatType;
571 extern sym_link *fixed16x16Type;
577 RESULT_TYPE_NONE = 0, /* operands will be promoted to int */
581 RESULT_TYPE_OTHER, /* operands will be promoted to int */
585 /* forward definitions for the symbol table related functions */
587 symbol *newSymbol (char *, int);
588 sym_link *newLink (SYM_LINK_CLASS);
589 sym_link *newFloatLink ();
590 structdef *newStruct (char *);
591 void addDecl (symbol *, int, sym_link *);
592 sym_link *mergeSpec (sym_link *, sym_link *, char *name);
593 symbol *reverseSyms (symbol *);
594 sym_link *reverseLink (sym_link *);
595 symbol *copySymbol (symbol *);
596 symbol *copySymbolChain (symbol *);
597 void printSymChain (symbol *, int);
598 void printStruct (structdef *, int);
599 char *genSymName (int);
600 sym_link *getSpec (sym_link *);
601 int compStructSize (int, structdef *);
602 sym_link *copyLinkChain (sym_link *);
603 int checkDecl (symbol *, int);
604 void checkBasic (sym_link *, sym_link *);
605 value *checkPointerIval (sym_link *, value *);
606 value *checkStructIval (symbol *, value *);
607 value *checkArrayIval (sym_link *, value *);
608 value *checkIval (sym_link *, value *);
609 unsigned int getSize (sym_link *);
610 unsigned int bitsForType (sym_link *);
611 sym_link *newIntLink ();
612 sym_link *newCharLink ();
613 sym_link *newLongLink ();
614 sym_link *newBoolLink ();
615 int compareType (sym_link *, sym_link *);
616 int compareTypeExact (sym_link *, sym_link *, int);
617 int checkFunction (symbol *, symbol *);
618 void cleanUpLevel (bucket **, int);
619 void cleanUpBlock (bucket **, int);
620 int funcInChain (sym_link *);
621 void addSymChain (symbol **);
622 sym_link *structElemType (sym_link *, value *);
623 symbol *getStructElement (structdef *, symbol *);
624 sym_link *computeType (sym_link *, sym_link *, RESULT_TYPE, int);
625 void processFuncPtrArgs (sym_link *);
626 void processFuncArgs (symbol *);
627 int isSymbolEqual (symbol *, symbol *);
628 int powof2 (TYPE_TARGET_ULONG);
629 void dbuf_printTypeChain (sym_link *, struct dbuf_s *);
630 void printTypeChain (sym_link *, FILE *);
631 void printTypeChainRaw (sym_link *, FILE *);
632 void initCSupport ();
633 void initBuiltIns ();
634 void pointerTypes (sym_link *, sym_link *);
635 void cdbStructBlock (int);
637 bucket *newBucket ();
638 void addSym (bucket **, void *, char *, int, int, int checkType);
639 void deleteSym (bucket **, void *, char *);
640 void *findSym (bucket **, void *, const char *);
641 void *findSymWithLevel (bucket **, struct symbol *);
642 void *findSymWithBlock (bucket **, struct symbol *, int);
643 void changePointer (sym_link * p);
644 void checkTypeSanity(sym_link *etype, char *name);
645 sym_link *typeFromStr (char *) ;
646 STORAGE_CLASS sclsFromPtr(sym_link *ptr);
647 sym_link *newEnumType (symbol *);
648 void promoteAnonStructs (int, structdef *);
651 extern char *nounName(sym_link *); /* noun strings */
652 extern void printFromToType (sym_link *, sym_link *);