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":"UNKNOW")
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. substituion */
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 DCL_TYPE(l) validateLink(l, "DCL_TYPE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.dcl_type
371 #define DCL_ELEM(l) validateLink(l, "DCL_ELEM", #l, DECLARATOR, __FILE__, __LINE__)->select.d.num_elem
372 #define DCL_PTR_CONST(l) validateLink(l, "DCL_PTR_CONST", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_const
373 #define DCL_PTR_VOLATILE(l) validateLink(l, "DCL_PTR_VOLATILE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_volatile
374 #define DCL_PTR_RESTRICT(l) validateLink(l, "DCL_PTR_RESTRICT", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_restrict
375 #define DCL_TSPEC(l) validateLink(l, "DCL_TSPEC", #l, DECLARATOR, __FILE__, __LINE__)->select.d.tspec
377 #define FUNC_DEBUG //assert(IS_FUNC(x));
378 #define FUNC_HASVARARGS(x) (x->funcAttrs.hasVargs)
379 #define IFFUNC_HASVARARGS(x) (IS_FUNC(x) && FUNC_HASVARARGS(x))
380 #define FUNC_ARGS(x) (x->funcAttrs.args)
381 #define IFFUNC_ARGS(x) (IS_FUNC(x) && FUNC_ARGS(x))
382 #define FUNC_HASFCALL(x) (x->funcAttrs.hasFcall)
383 #define IFFUNC_HASFCALL(x) (IS_FUNC(x) && FUNC_HASFCALL(x))
384 #define FUNC_HASBODY(x) (x->funcAttrs.hasbody)
385 #define IFFUNC_HASBODY(x) (IS_FUNC(x) && FUNC_HASBODY(x))
386 #define FUNC_CALLEESAVES(x) (x->funcAttrs.calleeSaves)
387 #define IFFUNC_CALLEESAVES(x) (IS_FUNC(x) && FUNC_CALLEESAVES(x))
388 #define FUNC_ISISR(x) (x->funcAttrs.intrtn)
389 #define IFFUNC_ISISR(x) (IS_FUNC(x) && FUNC_ISISR(x))
390 #define IFFUNC_RBANK(x) (IS_FUNC(x) && FUNC_RBANK(x))
391 #define FUNC_INTNO(x) (x->funcAttrs.intno)
392 #define FUNC_REGBANK(x) (x->funcAttrs.regbank)
393 #define FUNC_HASSTACKPARM(x) (x->funcAttrs.hasStackParms)
394 #define FUNC_ISINLINE(x) (x->funcAttrs.inlinereq)
395 #define IFFUNC_ISINLINE(x) (IS_FUNC(x) && FUNC_ISINLINE(x))
397 #define FUNC_ISREENT(x) (x->funcAttrs.reent)
398 #define IFFUNC_ISREENT(x) (IS_FUNC(x) && FUNC_ISREENT(x))
399 #define FUNC_ISSHADOWREGS(x) (x->funcAttrs.shadowregs)
400 #define IFFUNC_ISSHADOWREGS(x) (IS_FUNC(x) && FUNC_ISSHADOWREGS(x))
401 #define FUNC_ISWPARAM(x) (x->funcAttrs.wparam)
402 #define IFFUNC_ISWPARAM(x) (IS_FUNC(x) && FUNC_ISWPARAM(x))
403 #define FUNC_ISNAKED(x) (x->funcAttrs.naked)
404 #define IFFUNC_ISNAKED(x) (IS_FUNC(x) && FUNC_ISNAKED(x))
405 #define FUNC_NONBANKED(x) (x->funcAttrs.nonbanked)
406 #define IFFUNC_NONBANKED(x) (IS_FUNC(x) && FUNC_NONBANKED(x))
407 #define FUNC_BANKED(x) (x->funcAttrs.banked)
408 #define IFFUNC_BANKED(x) (IS_FUNC(x) && FUNC_BANKED(x))
409 #define FUNC_ISCRITICAL(x) (x->funcAttrs.critical)
410 #define IFFUNC_ISCRITICAL(x) (IS_FUNC(x) && FUNC_ISCRITICAL(x))
411 #define FUNC_ISBUILTIN(x) (x->funcAttrs.builtin)
412 #define IFFUNC_ISBUILTIN(x) (IS_FUNC(x) && FUNC_ISBUILTIN(x))
413 #define FUNC_ISJAVANATIVE(x) (x->funcAttrs.javaNative)
414 #define IFFUNC_ISJAVANATIVE(x) (IS_FUNC(x) && FUNC_ISJAVANATIVE(x))
415 #define FUNC_ISOVERLAY(x) (x->funcAttrs.overlay)
416 #define IFFUNC_ISOVERLAY(x) (IS_FUNC(x) && FUNC_ISOVERLAY(x))
418 #define IFFUNC_ISBANKEDCALL(x) (!IFFUNC_NONBANKED(x) && \
419 (options.model == MODEL_HUGE || \
420 ((options.model == MODEL_LARGE || options.model == MODEL_MEDIUM) && \
421 (TARGET_IS_Z80 || TARGET_IS_GBZ80)) || \
424 #define SPEC_NOUN(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.noun
425 #define SPEC_LONG(x) validateLink(x, "SPEC_LONG", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_long
426 #define SPEC_SHORT(x) validateLink(x, "SPEC_LONG", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_short
427 #define SPEC_USIGN(x) validateLink(x, "SPEC_USIGN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_unsigned
428 #define SPEC_SCLS(x) validateLink(x, "SPEC_SCLS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.sclass
429 #define SPEC_ENUM(x) validateLink(x, "SPEC_ENUM", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_isenum
430 #define SPEC_OCLS(x) validateLink(x, "SPEC_OCLS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.oclass
431 #define SPEC_STAT(x) validateLink(x, "SPEC_STAT", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_static
432 #define SPEC_EXTR(x) validateLink(x, "SPEC_EXTR", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_extern
433 #define SPEC_CODE(x) validateLink(x, "SPEC_CODE", #x, SPECIFIER, __FILE__, __LINE__)->select.s._codesg
434 #define SPEC_ABSA(x) validateLink(x, "SPEC_ABSA", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_absadr
435 #define SPEC_BANK(x) validateLink(x, "SPEC_BANK", #x, SPECIFIER, __FILE__, __LINE__)->select.s._regbank
436 #define SPEC_ADDR(x) validateLink(x, "SPEC_ADDR", #x, SPECIFIER, __FILE__, __LINE__)->select.s._addr
437 #define SPEC_STAK(x) validateLink(x, "SPEC_STAK", #x, SPECIFIER, __FILE__, __LINE__)->select.s._stack
438 #define SPEC_CVAL(x) validateLink(x, "SPEC_CVAL", #x, SPECIFIER, __FILE__, __LINE__)->select.s.const_val
439 #define SPEC_BSTR(x) validateLink(x, "SPEC_BSTR", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
440 #define SPEC_BLEN(x) validateLink(x, "SPEC_BLEN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitLength
442 /* Sleaze: SPEC_ISR_SAVED_BANKS is only used on
443 * function type symbols, which obviously cannot
444 * be of BIT type. Therefore, we recycle the
445 * _bitStart field instead of defining a new field.
447 #define SPEC_ISR_SAVED_BANKS(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
448 #define SPEC_VOLATILE(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_volatile
449 #define SPEC_CONST(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_const
450 #define SPEC_RESTRICT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_restrict
451 #define SPEC_STRUCT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.v_struct
452 #define SPEC_TYPEDEF(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_typedef
453 #define SPEC_REGPARM(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_isregparm
454 #define SPEC_ARGREG(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.argreg
455 #define SPEC_INLINE(x) validateLink(x, "SPEC_INLINE", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_inline
457 /* type check macros */
458 #define IS_DECL(x) ( x && x->class == DECLARATOR )
459 #define IS_SPEC(x) ( x && x->class == SPECIFIER )
460 #define IS_ARRAY(x) (IS_DECL(x) && DCL_TYPE(x) == ARRAY)
461 #define IS_DATA_PTR(x) (IS_DECL(x) && DCL_TYPE(x) == POINTER)
462 #define IS_PTR(x) (IS_DECL(x) && (DCL_TYPE(x) == POINTER || \
463 DCL_TYPE(x) == FPOINTER || \
464 DCL_TYPE(x) == GPOINTER || \
465 DCL_TYPE(x) == IPOINTER || \
466 DCL_TYPE(x) == PPOINTER || \
467 DCL_TYPE(x) == EEPPOINTER || \
468 DCL_TYPE(x) == CPOINTER || \
469 DCL_TYPE(x) == UPOINTER ))
470 #define IS_PTR_CONST(x) (IS_PTR(x) && DCL_PTR_CONST(x))
471 #define IS_PTR_RESTRICT(x) (IS_PTR(x) && DCL_PTR_RESTRICT(x))
472 #define IS_FARPTR(x) (IS_DECL(x) && DCL_TYPE(x) == FPOINTER)
473 #define IS_CODEPTR(x) (IS_DECL(x) && DCL_TYPE(x) == CPOINTER)
474 #define IS_GENPTR(x) (IS_DECL(x) && DCL_TYPE(x) == GPOINTER)
475 #define IS_FUNCPTR(x) (IS_DECL(x) && (DCL_TYPE(x) == CPOINTER || DCL_TYPE(x) == GPOINTER) && IS_FUNC(x->next))
476 #define IS_FUNC(x) (IS_DECL(x) && DCL_TYPE(x) == FUNCTION)
477 #define IS_LONG(x) (IS_SPEC(x) && x->select.s.b_long)
478 #define IS_UNSIGNED(x) (IS_SPEC(x) && x->select.s.b_unsigned)
479 #define IS_TYPEDEF(x)(IS_SPEC(x) && x->select.s.b_typedef)
480 #define IS_CONSTANT(x) (!x ? 0 : \
482 x->select.s.b_const : \
483 x->select.d.ptr_const)
484 #define IS_STRUCT(x) (IS_SPEC(x) && x->select.s.noun == V_STRUCT)
485 #define IS_ABSOLUTE(x) (IS_SPEC(x) && x->select.s.b_absadr )
486 #define IS_REGISTER(x) (IS_SPEC(x) && SPEC_SCLS(x) == S_REGISTER)
487 #define IS_RENT(x) (IS_SPEC(x) && x->select.s._reent )
488 #define IS_STATIC(x) (IS_SPEC(x) && SPEC_STAT(x))
489 #define IS_INLINE(x) (IS_SPEC(x) && SPEC_INLINE(x))
490 #define IS_INT(x) (IS_SPEC(x) && x->select.s.noun == V_INT)
491 #define IS_VOID(x) (IS_SPEC(x) && x->select.s.noun == V_VOID)
492 #define IS_CHAR(x) (IS_SPEC(x) && x->select.s.noun == V_CHAR)
493 #define IS_EXTERN(x) (IS_SPEC(x) && x->select.s.b_extern)
494 #define IS_VOLATILE(x) (!x ? 0 : \
496 x->select.s.b_volatile : \
497 x->select.d.ptr_volatile)
498 #define IS_INTEGRAL(x) (IS_SPEC(x) && (x->select.s.noun == V_INT || \
499 x->select.s.noun == V_CHAR || \
500 x->select.s.noun == V_BITFIELD || \
501 x->select.s.noun == V_BIT || \
502 x->select.s.noun == V_SBIT ))
503 #define IS_BITFIELD(x) (IS_SPEC(x) && (x->select.s.noun == V_BITFIELD))
504 #define IS_BITVAR(x) (IS_SPEC(x) && (x->select.s.noun == V_BITFIELD || \
505 x->select.s.noun == V_BIT || \
506 x->select.s.noun == V_SBIT ))
507 #define IS_BIT(x) (IS_SPEC(x) && (x->select.s.noun == V_BIT || \
508 x->select.s.noun == V_SBIT ))
509 #define IS_FLOAT(x) (IS_SPEC(x) && x->select.s.noun == V_FLOAT)
510 #define IS_FIXED16X16(x) (IS_SPEC(x) && x->select.s.noun == V_FIXED16X16)
511 #define IS_FIXED(x) (IS_FIXED16X16(x))
512 #define IS_ARITHMETIC(x) (IS_INTEGRAL(x) || IS_FLOAT(x) || IS_FIXED(x))
513 #define IS_AGGREGATE(x) (IS_ARRAY(x) || IS_STRUCT(x))
514 #define IS_LITERAL(x) (IS_SPEC(x) && x->select.s.sclass == S_LITERAL)
515 #define IS_CODE(x) (IS_SPEC(x) && SPEC_SCLS(x) == S_CODE)
516 #define IS_REGPARM(x) (IS_SPEC(x) && SPEC_REGPARM(x))
518 /* symbol check macros */
519 #define IS_AUTO(x) (x->level && !IS_STATIC(x->etype) && !IS_EXTERN(x->etype))
521 /* forward declaration for the global vars */
522 extern bucket *SymbolTab[];
523 extern bucket *StructTab[];
524 extern bucket *TypedefTab[];
525 extern bucket *LabelTab[];
526 extern bucket *enumTab[];
527 extern symbol *__fsadd;
528 extern symbol *__fssub;
529 extern symbol *__fsmul;
530 extern symbol *__fsdiv;
531 extern symbol *__fseq;
532 extern symbol *__fsneq;
533 extern symbol *__fslt;
534 extern symbol *__fslteq;
535 extern symbol *__fsgt;
536 extern symbol *__fsgteq;
538 extern symbol *__fps16x16_add;
539 extern symbol *__fps16x16_sub;
540 extern symbol *__fps16x16_mul;
541 extern symbol *__fps16x16_div;
542 extern symbol *__fps16x16_eq;
543 extern symbol *__fps16x16_neq;
544 extern symbol *__fps16x16_lt;
545 extern symbol *__fps16x16_lteq;
546 extern symbol *__fps16x16_gt;
547 extern symbol *__fps16x16_gteq;
549 /* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
550 extern symbol *__muldiv[3][3][2];
551 /* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */
552 extern sym_link *__multypes[3][2];
553 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
554 extern symbol *__conv[2][3][2];
555 /* Dims: to/from fixed16x16, BYTE/WORD/DWORD/FLOAT, SIGNED/USIGNED */
556 extern symbol *__fp16x16conv[2][4][2];
557 /* Dims: shift left/shift right, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
558 extern symbol *__rlrr[2][3][2];
560 #define CHARTYPE __multypes[0][0]
561 #define UCHARTYPE __multypes[0][1]
562 #define INTTYPE __multypes[1][0]
563 #define UINTTYPE __multypes[1][1]
564 #define LONGTYPE __multypes[2][0]
565 #define ULONGTYPE __multypes[2][1]
567 extern sym_link *floatType;
568 extern sym_link *fixed16x16Type;
574 RESULT_TYPE_NONE = 0, /* operands will be promoted to int */
578 RESULT_TYPE_OTHER, /* operands will be promoted to int */
582 /* forward definitions for the symbol table related functions */
584 symbol *newSymbol (char *, int);
585 sym_link *newLink (SYM_LINK_CLASS);
586 sym_link *newFloatLink ();
587 structdef *newStruct (char *);
588 void addDecl (symbol *, int, sym_link *);
589 sym_link *mergeSpec (sym_link *, sym_link *, char *name);
590 symbol *reverseSyms (symbol *);
591 sym_link *reverseLink (sym_link *);
592 symbol *copySymbol (symbol *);
593 symbol *copySymbolChain (symbol *);
594 void printSymChain (symbol *, int);
595 void printStruct (structdef *, int);
596 char *genSymName (int);
597 sym_link *getSpec (sym_link *);
598 int compStructSize (int, structdef *);
599 sym_link *copyLinkChain (sym_link *);
600 int checkDecl (symbol *, int);
601 void checkBasic (sym_link *, sym_link *);
602 value *checkPointerIval (sym_link *, value *);
603 value *checkStructIval (symbol *, value *);
604 value *checkArrayIval (sym_link *, value *);
605 value *checkIval (sym_link *, value *);
606 unsigned int getSize (sym_link *);
607 unsigned int bitsForType (sym_link *);
608 sym_link *newIntLink ();
609 sym_link *newCharLink ();
610 sym_link *newLongLink ();
611 sym_link *newBoolLink ();
612 int compareType (sym_link *, sym_link *);
613 int compareTypeExact (sym_link *, sym_link *, int);
614 int checkFunction (symbol *, symbol *);
615 void cleanUpLevel (bucket **, int);
616 void cleanUpBlock (bucket **, int);
617 int funcInChain (sym_link *);
618 void addSymChain (symbol **);
619 sym_link *structElemType (sym_link *, value *);
620 symbol *getStructElement (structdef *, symbol *);
621 sym_link *computeType (sym_link *, sym_link *, RESULT_TYPE, int);
622 void processFuncPtrArgs (sym_link *);
623 void processFuncArgs (symbol *);
624 int isSymbolEqual (symbol *, symbol *);
625 int powof2 (TYPE_TARGET_ULONG);
626 void dbuf_printTypeChain (sym_link *, struct dbuf_s *);
627 void printTypeChain (sym_link *, FILE *);
628 void printTypeChainRaw (sym_link *, FILE *);
629 void initCSupport ();
630 void initBuiltIns ();
631 void pointerTypes (sym_link *, sym_link *);
632 void cdbStructBlock (int);
634 bucket *newBucket ();
635 void addSym (bucket **, void *, char *, int, int, int checkType);
636 void deleteSym (bucket **, void *, char *);
637 void *findSym (bucket **, void *, const char *);
638 void *findSymWithLevel (bucket **, struct symbol *);
639 void *findSymWithBlock (bucket **, struct symbol *, int);
640 void changePointer (sym_link * p);
641 void checkTypeSanity(sym_link *etype, char *name);
642 sym_link *typeFromStr (char *) ;
643 STORAGE_CLASS sclsFromPtr(sym_link *ptr);
644 sym_link *newEnumType (symbol *);
645 void promoteAnonStructs (int, structdef *);
648 extern char *nounName(sym_link *); /* noun strings */
649 extern void printFromToType (sym_link *, sym_link *);