Update svn merge history.
[sdcc.git] / sdcc / src / SDCCsymt.h
blobbfcaf31636b94228e6776b25ca3b5cd4da030a0a
1 /*-------------------------------------------------------------------------
2 SDCCsymt.h - Header file for Symbols table related structures and MACRO's.
4 Copyright (C) 1998 Sandeep Dutta . sandeep.dutta@usa.net
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 -------------------------------------------------------------------------*/
21 #ifndef SDCCSYMT_H
22 #define SDCCSYMT_H
24 #define MAX_NEST_LEVEL 256
25 #define SDCC_SYMNAME_MAX 256
26 #define SDCC_NAME_MAX 3*SDCC_SYMNAME_MAX // big enough for _<func>_<var>_etc
27 #include "SDCChasht.h"
28 #include "SDCCglobl.h"
29 #include "SDCCattr.h"
30 #include "dbuf.h"
32 #define INTNO_MAX 255 /* maximum allowed interrupt number */
33 #define INTNO_TRAP INTNO_MAX
34 #define INTNO_UNSPEC (INTNO_MAX+1) /* interrupt number unspecified */
37 #define BITVAR_PAD -1
39 // values for first byte (or 3 most significant bits) of generic pointer.
40 #if 0
41 #define GPTYPE_FAR 0x00
42 #define GPTYPE_NEAR 0x40
43 #define GPTYPE_XSTACK 0x60
44 #define GPTYPE_CODE 0x80
45 #else
46 #define GPTYPE_FAR (port->gp_tags.tag_far)
47 #define GPTYPE_NEAR (port->gp_tags.tag_near)
48 #define GPTYPE_XSTACK (port->gp_tags.tag_xstack)
49 #define GPTYPE_CODE (port->gp_tags.tag_code)
50 #endif
52 #define HASHTAB_SIZE 256
54 /* hash table bucket */
55 typedef struct bucket
57 void *sym; /* pointer to the object */
58 char name[SDCC_NAME_MAX + 1]; /* name of this symbol */
59 long level; /* nest level for this symbol */
60 int block; /* belongs to which block */
61 struct bucket *prev; /* ptr 2 previous bucket */
62 struct bucket *next; /* ptr 2 next bucket */
64 bucket;
66 typedef struct structdef
68 char tag[SDCC_NAME_MAX + 1]; /* tag part of structure */
69 long level; /* Nesting level */
70 int block; /* belongs to which block */
71 struct symbol *fields; /* pointer to fields */
72 unsigned size; /* sizeof the table in bytes */
73 int type; /* STRUCT or UNION */
74 bool b_flexArrayMember; /* has got a flexible array member,
75 only needed for syntax checks */
76 bool redefinition; /* is a redefinition only needed for syntax checks */
77 struct symbol *tagsym; /* tag symbol (NULL if no tag) */
79 structdef;
81 /* noun definitions */
82 typedef enum
84 V_INT = 1,
85 V_BITINT,
86 V_FLOAT,
87 V_FIXED16X16,
88 V_BOOL,
89 V_CHAR,
90 V_NULLPTR,
91 V_VOID,
92 V_STRUCT,
93 V_LABEL,
94 V_BITFIELD,
95 V_BBITFIELD,
96 V_BITINTBITFIELD,
97 V_BIT,
98 V_SBIT,
99 V_DOUBLE
101 NOUN;
103 /* storage class */
104 typedef enum
106 S_FIXED = 0,
107 S_AUTO,
108 S_REGISTER,
109 S_SFR,
110 S_SBIT,
111 S_CODE,
112 S_XDATA,
113 S_DATA,
114 S_IDATA,
115 S_PDATA,
116 S_LITERAL,
117 S_STACK,
118 S_XSTACK,
119 S_BIT,
120 S_EEPROM
122 STORAGE_CLASS;
124 #define TYPE_TARGET_CHAR TYPE_BYTE
125 #define TYPE_TARGET_INT TYPE_WORD
126 #define TYPE_TARGET_LONG TYPE_DWORD
127 #define TYPE_TARGET_UCHAR TYPE_UBYTE
128 #define TYPE_TARGET_UINT TYPE_UWORD
129 #define TYPE_TARGET_ULONG TYPE_UDWORD
130 #define TYPE_TARGET_LONGLONG TYPE_QWORD
131 #define TYPE_TARGET_ULONGLONG TYPE_UQWORD
133 /* specifier is the last in the type-chain */
134 typedef struct specifier
136 NOUN noun; /* CHAR INT STRUCTURE LABEL */
137 STORAGE_CLASS sclass; /* REGISTER,AUTO,FIX,CONSTANT */
138 bool sclass_implicitintrinsic:1; /* intrinsic named address space implied by sclass has been assigned implicitly. */
139 struct memmap *oclass; /* output storage class */
140 unsigned b_long:1; /* 1=long */
141 unsigned b_longlong:1; /* 1=long long */
142 unsigned b_short:1; /* 1=short int */
143 unsigned b_unsigned:1; /* 1=unsigned, 0=signed */
144 unsigned b_signed:1; /* just for sanity checks only*/
145 bool b_implicit_sign:1; /* signedness not explicitly specified - needed to keep char a separate type from signed char and unsigned char. */
146 unsigned b_static:1; /* 1=static keyword found */
147 unsigned b_extern:1; /* 1=extern found */
148 unsigned b_inline:1; /* inline function requested */
149 unsigned b_noreturn:1; /* promised not to return */
150 unsigned b_alignas:1; /* alignment */
151 unsigned b_absadr:1; /* absolute address specfied */
152 unsigned b_const:1; /* is a constant */
153 unsigned b_restrict:1; /* is restricted */
154 unsigned b_volatile:1; /* is marked as volatile */
155 unsigned b_atomic:1; /* is marked as _Atomic */
156 struct symbol *addrspace; /* is in named address space */
157 unsigned b_typedef:1; /* is typedefed */
158 unsigned b_isregparm:1; /* is the first parameter */
159 unsigned b_isenum:1; /* is an enumerated type */
160 unsigned b_bitUnnamed:1; /* is an unnamed bit-field */
161 unsigned b_needspar:1; /* has to be a parameter */
162 unsigned bitintwidth; /* width of bit-precise type */
163 unsigned _bitStart; /* bit start position */
164 unsigned _bitLength; /* bit length */
165 unsigned _addr; /* address of symbol */
166 unsigned _stack; /* stack offset for stacked v */
167 int argreg; /* reg no for regparm */
168 union
169 { /* Values if constant or enum */
170 TYPE_TARGET_INT v_int; /* 2 bytes: int and char values */
171 const char *v_char; /* char character string */
172 const TYPE_TARGET_UINT *v_char16; /* char16_t character string */
173 const TYPE_TARGET_ULONG *v_char32;/* char32_t character string */
174 TYPE_TARGET_UINT v_uint; /* 2 bytes: unsigned int const value */
175 TYPE_TARGET_LONG v_long; /* 4 bytes: long constant value */
176 TYPE_TARGET_ULONG v_ulong; /* 4 bytes: unsigned long constant value */
177 TYPE_TARGET_LONGLONG v_longlong; /* 8 bytes: long long constant value */
178 TYPE_TARGET_ULONGLONG v_ulonglong;/* 8 bytes: unsigned long long const value */
179 double v_float; /* floating point constant value */
180 TYPE_TARGET_ULONG v_fixed16x16; /* 4 bytes: fixed point constant value */
181 struct symbol *v_enum; /* ptr to enum_list if enum==1 */
183 const_val;
184 struct structdef *v_struct; /* structure pointer */
186 specifier;
188 /* types of declarators */
189 typedef enum
191 UPOINTER = 0, /* unknown pointer used only when parsing */
192 POINTER, /* pointer to near data */
193 IPOINTER, /* pointer to upper 128 bytes */
194 PPOINTER, /* paged area pointer */
195 FPOINTER, /* pointer to far data */
196 CPOINTER, /* pointer to code space */
197 GPOINTER, /* generic pointer */
198 EEPPOINTER, /* pointer to eeprom */
199 ARRAY,
200 FUNCTION
202 DECLARATOR_TYPE;
204 typedef struct ast ast;
206 typedef struct declarator
208 DECLARATOR_TYPE dcl_type; /* POINTER,ARRAY or FUNCTION */
209 bool dcl_type_implicitintrinsic:1;/* intrinsic named address space indicated by dcltype has been assigned implicitly. */
210 size_t num_elem; /* # of elems if type==array, */
211 ast *num_elem_ast; /* ast for # of elems, used to calculate num_elem. */
212 /* always 0 for flexible arrays */
213 unsigned ptr_const:1; /* pointer is constant */
214 unsigned ptr_volatile:1; /* pointer is volatile */
215 unsigned ptr_restrict:1; /* pointer is resticted */
216 bool array_vla:1; // Array is known to be a VLA.
217 bool vla_check_visited:1; // Already visited in check for VLA - implementation detail to prevent infinite recursion */
218 struct symbol *ptr_addrspace; /* pointer is in named address space */
220 struct sym_link *tspec; /* pointer type specifier */
222 declarator;
224 typedef enum
226 DECLARATOR = 1,
227 SPECIFIER
228 } SYM_LINK_CLASS;
229 #define DECLSPEC2TXT(select) (select==DECLARATOR?"DECLARATOR":select==SPECIFIER?"SPECIFIER":"UNKNOWN")
231 typedef struct sym_link
233 SYM_LINK_CLASS xclass; /* DECLARATOR or SPECIFIER */
234 unsigned tdef:1; /* current link created by */
235 /* typedef if this flag is set */
236 union
238 specifier s; /* if CLASS == SPECIFIER */
239 declarator d; /* if CLASS == DECLARATOR */
240 } select;
242 /* function attributes */
243 struct
245 struct value *args; /* the defined arguments */
246 unsigned hasVargs:1; /* functions has varargs */
247 unsigned calleeSaves:1; /* functions uses callee save */
248 unsigned hasbody:1; /* function body defined */
249 unsigned hasFcall:1; /* does it call other functions */
250 unsigned reent:1; /* function is reentrant */
251 unsigned naked:1; /* naked function */
252 unsigned oldStyle:1; /* K&R function (TODO: remove, once noprototype can be used for K&R functions) */
254 unsigned shadowregs:1; /* function uses shadow registers (pic16 port) */
255 unsigned wparam:1; /* first byte of arguments is passed via WREG (pic16 port) */
256 unsigned nonbanked:1; /* function has the nonbanked attribute */
257 unsigned banked:1; /* function has the banked attribute */
258 unsigned critical:1; /* critical function */
259 unsigned intrtn:1; /* this is an interrupt routine */
260 unsigned rbank:1; /* separate register bank */
261 unsigned inlinereq:1; /* inlining requested */
262 unsigned noreturn:1; /* promised not to return */
263 bool noprototype:1; /* Up to C17 function declaratos without prototypes were allowed */
264 signed sdcccall; /* ABI version used */
265 unsigned smallc:1; /* Small-C calling convention: Parameters on stack are passed left-to-right */
266 unsigned raisonance:1; /* Raisonance calling convention for STM8 */
267 unsigned iar:1; /* IAR calling convention */
268 unsigned cosmic:1; /* Cosmic calling convention */
269 unsigned z88dk_fastcall:1; /* For the z80-related ports: Function has a single parameter of at most 32 bits that is passed in dehl */
270 unsigned z88dk_callee:1; /* Stack pointer adjustment for parameters passed on the stack is done by the callee */
271 unsigned z88dk_shortcall:1; /* Short call available via rst (see values later) (Z80 only) */
272 unsigned z88dk_has_params_offset:1; /* Has a parameter offset (Z80 only) */
273 unsigned intno; /* Number of interrupt for interrupt service routine */
274 short regbank; /* register bank 2b used */
275 unsigned builtin; /* is a builtin function */
276 unsigned javaNative; /* is a JavaNative Function (TININative ONLY) */
277 unsigned overlay; /* force parameters & locals into overlay segment */
278 unsigned hasStackParms; /* function has parameters on stack */
279 bool preserved_regs[9]; /* Registers preserved by the function - may be an underestimate */
280 unsigned char z88dk_shortcall_rst; /* Rst for a short call */
281 unsigned short z88dk_shortcall_val; /* Value for a short call */
282 unsigned short z88dk_params_offset; /* Additional offset from for arguments */
283 } funcAttrs;
285 struct sym_link *next; /* next element on the chain */
287 sym_link;
289 typedef struct symbol
291 char name[SDCC_SYMNAME_MAX + 1]; /* Input Variable Name */
292 char rname[SDCC_NAME_MAX + 1]; /* internal name */
294 long level; /* declaration lev,fld offset */
295 int block; /* sequential block # of definition */
296 int seqPoint; /* sequence point defined or, if unbound, used */
297 int key;
298 unsigned flexArrayLength; /* if the symbol specifies a struct
299 with a "flexible array member", then the additional length in bytes for
300 the "fam" is stored here. Because the length can be different from symbol
301 to symbol AND v_struct isn't copied in copyLinkChain(), it's located here
302 in the symbol and not in v_struct or the declarator */
303 unsigned implicit:1; /* implicit flag */
304 unsigned undefined:1; /* undefined variable */
305 unsigned infertype:1; /* type should be inferred from first assign */
306 unsigned _isparm:1; /* is a parameter */
307 unsigned ismyparm:1; /* is parameter of the function being generated */
308 unsigned isitmp:1; /* is an intermediate temp */
309 unsigned islbl:1; /* is a temporary label */
310 unsigned isref:1; /* has been referenced */
311 unsigned isind:1; /* is an induction variable */
312 unsigned isinvariant:1; /* is a loop invariant */
313 unsigned cdef:1; /* compiler defined symbol */
314 unsigned addrtaken:1; /* address of the symbol was taken */
315 unsigned isreqv:1; /* is the register equivalent of a symbol */
316 unsigned udChked:1; /* use def checking has been already done */
317 unsigned generated:1; /* code generated (function symbols only) */
318 unsigned isinscope:1; /* is in scope */
320 /* following flags are used by the backend
321 for code generation and can be changed
322 if a better scheme for backend is thought of */
323 unsigned isLiveFcall:1; /* is live at or across a function call */
324 unsigned isspilt:1; /* has to be spilt */
325 unsigned spillA:1; /* spilt be register allocator */
326 unsigned remat:1; /* can be remateriazed */
327 unsigned isptr:1; /* is a pointer */
328 unsigned uptr:1; /* used as a pointer */
329 unsigned isFree:1; /* used by register allocator */
330 unsigned islocal:1; /* is a local variable */
331 unsigned blockSpil:1; /* spilt at block level */
332 unsigned remainSpil:1; /* spilt because not used in remainder */
333 unsigned stackSpil:1; /* has been spilt on temp stack location */
334 unsigned onStack:1; /* this symbol allocated on the stack */
335 unsigned iaccess:1; /* indirect access */
336 unsigned ruonly:1; /* used in return statement only */
337 unsigned spildir:1; /* spilt in direct space */
338 unsigned ptrreg:1; /* this symbol assigned to a ptr reg */
339 unsigned noSpilLoc:1; /* cannot be assigned a spil location */
340 bool funcDivFlagSafe:1; /* we know this function is safe to call with undocumented stm8 flag bit 6 set*/
341 bool funcUsesVolatile:1; /* The function accesses a volatile variable */
342 bool funcRestartAtomicSupport:1; /* The function uses (directly or indirectly) restartable atomic support routines. */
343 unsigned isstrlit; /* is a string literal and it's usage count */
344 unsigned accuse; /* can be left in the accumulator
345 On the Z80 accuse is divided into
346 ACCUSE_A and ACCUSE_HL as the idea
347 is quite similar.
349 unsigned dptr; /* 8051 variants with multiple DPTRS
350 currently implemented in DS390 only
352 int allocreq; /* allocation is required for this variable */
353 int stack; /* offset on stack */
354 int xstack; /* offset on xternal stack */
355 short nRegs; /* number of registers required */
356 short regType; /* type of register required */
358 struct reg_info *regs[8]; /* can have at the most 8 registers */
359 struct asmop *aop; /* asmoperand for this symbol */
360 struct iCode *fuse; /* furthest use */
361 struct iCode *rematiCode; /* rematerialise with which instruction */
362 struct operand *reqv; /* register equivalent of a local variable */
363 struct symbol *prereqv; /* symbol before register equiv. substitution */
364 struct symbol *psbase; /* if pseudo symbol, the symbol it is based on */
365 union
367 struct symbol *spillLoc; /* register spil location */
368 struct set *itmpStack; /* symbols spilt @ this stack location */
370 usl;
371 int bitVar; /* if bitVar != 0: this is a bit variable, bitVar is the size in bits */
372 unsigned bitUnnamed:1; /* unnamed bit variable */
373 unsigned offset; /* offset from top if struct */
375 int lineDef; /* defined line number */
376 char *fileDef; /* defined filename */
377 int lastLine; /* for functions the last line */
378 struct sym_link *type; /* 1st link to declarator chain */
379 struct sym_link *etype; /* last link to declarator chain */
380 struct symbol *next; /* crosslink to next symbol */
381 struct symbol *localof; /* local variable of which function */
382 struct initList *ival; /* ptr to initializer if any */
383 struct bitVect *defs; /* bit vector for definitions */
384 struct bitVect *uses; /* bit vector for uses */
385 struct bitVect *regsUsed; /* for functions registers used */
386 int liveFrom; /* live from iCode sequence number */
387 int liveTo; /* live to sequence number */
388 int used; /* no. of times this was used */
389 int recvSize; /* size of first argument */
390 struct bitVect *clashes; /* overlaps with what other symbols */
391 struct ast *funcTree; /* function body ast if inlined */
392 struct symbol *addressmod[2]; /* access functions for named address spaces */
394 bool for_newralloc;
396 symbol;
398 extern sym_link *validateLink (sym_link * l,
399 const char *macro, const char *args, const char select, const char *file, unsigned line);
400 /* Easy Access Macros */
401 #define IS_OP_RUONLY(x) (IS_SYMOP(x) && OP_SYMBOL(x) && OP_SYMBOL(x)->ruonly)
402 #define IS_OP_ACCUSE(x) (IS_SYMOP(x) && OP_SYMBOL(x) && OP_SYMBOL(x)->accuse)
404 #define DCL_TYPE(l) validateLink(l, "DCL_TYPE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.dcl_type
405 #define DCL_TYPE_IMPLICITINTRINSIC(l) validateLink(l, "DCL_TYPE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.dcl_type_implicitintrinsic
406 #define DCL_ELEM(l) validateLink(l, "DCL_ELEM", #l, DECLARATOR, __FILE__, __LINE__)->select.d.num_elem
407 #define DCL_ELEM_AST(l) validateLink(l, "DCL_ELEM", #l, DECLARATOR, __FILE__, __LINE__)->select.d.num_elem_ast
408 #define DCL_PTR_CONST(l) validateLink(l, "DCL_PTR_CONST", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_const
409 #define DCL_PTR_VOLATILE(l) validateLink(l, "DCL_PTR_VOLATILE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_volatile
410 #define DCL_PTR_RESTRICT(l) validateLink(l, "DCL_PTR_RESTRICT", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_restrict
411 #define DCL_ARRAY_VLA(l) validateLink(l, "DCL_ARRAY_VLA", #l, DECLARATOR, __FILE__, __LINE__)->select.d.array_vla
412 #define DCL_PTR_ADDRSPACE(l) validateLink(l, "DCL_PTR_ADDRSPACE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_addrspace
413 #define DCL_TSPEC(l) validateLink(l, "DCL_TSPEC", #l, DECLARATOR, __FILE__, __LINE__)->select.d.tspec
415 #define FUNC_DEBUG //assert(IS_FUNC(x));
416 #define FUNC_HASVARARGS(x) (x->funcAttrs.hasVargs)
417 #define IFFUNC_HASVARARGS(x) (IS_FUNC(x) && FUNC_HASVARARGS(x))
418 #define FUNC_ARGS(x) (x->funcAttrs.args)
419 #define IFFUNC_ARGS(x) (IS_FUNC(x) && FUNC_ARGS(x))
420 #define FUNC_HASFCALL(x) (x->funcAttrs.hasFcall)
421 #define IFFUNC_HASFCALL(x) (IS_FUNC(x) && FUNC_HASFCALL(x))
422 #define FUNC_HASBODY(x) (x->funcAttrs.hasbody)
423 #define IFFUNC_HASBODY(x) (IS_FUNC(x) && FUNC_HASBODY(x))
424 #define FUNC_CALLEESAVES(x) (x->funcAttrs.calleeSaves)
425 #define IFFUNC_CALLEESAVES(x) (IS_FUNC(x) && FUNC_CALLEESAVES(x))
426 #define FUNC_ISISR(x) (x->funcAttrs.intrtn)
427 #define IFFUNC_ISISR(x) (IS_FUNC(x) && FUNC_ISISR(x))
428 #define FUNC_INTNO(x) (x->funcAttrs.intno)
429 #define FUNC_SDCCCALL(x) (x->funcAttrs.sdcccall)
430 #define FUNC_REGBANK(x) (x->funcAttrs.regbank)
431 #define FUNC_HASSTACKPARM(x) (x->funcAttrs.hasStackParms)
432 #define FUNC_ISINLINE(x) (x->funcAttrs.inlinereq)
433 #define IFFUNC_ISINLINE(x) (IS_FUNC(x) && FUNC_ISINLINE(x))
434 #define FUNC_ISNORETURN(x) (x->funcAttrs.noreturn)
435 #define IFFUNC_ISNORETURN(x) (IS_FUNC(x) && FUNC_ISNORETURN(x))
436 #define FUNC_NOPROTOTYPE(x) (x->funcAttrs.noprototype)
437 #define IFFUNC_NOPROTOTYPE(x) (IS_FUNC(x) && FUNC_NOPROTOTYPE(x))
439 #define FUNC_ISREENT(x) (x->funcAttrs.reent)
440 #define IFFUNC_ISREENT(x) (IS_FUNC(x) && FUNC_ISREENT(x))
441 #define FUNC_ISSHADOWREGS(x) (x->funcAttrs.shadowregs)
442 #define IFFUNC_ISSHADOWREGS(x) (IS_FUNC(x) && FUNC_ISSHADOWREGS(x))
443 #define FUNC_ISWPARAM(x) (x->funcAttrs.wparam)
444 #define IFFUNC_ISWPARAM(x) (IS_FUNC(x) && FUNC_ISWPARAM(x))
445 #define FUNC_ISNAKED(x) (x->funcAttrs.naked)
446 #define IFFUNC_ISNAKED(x) (IS_FUNC(x) && FUNC_ISNAKED(x))
447 #define FUNC_NONBANKED(x) (x->funcAttrs.nonbanked)
448 #define IFFUNC_NONBANKED(x) (IS_FUNC(x) && FUNC_NONBANKED(x))
449 #define FUNC_BANKED(x) (x->funcAttrs.banked)
450 #define IFFUNC_BANKED(x) (IS_FUNC(x) && FUNC_BANKED(x))
451 #define FUNC_ISCRITICAL(x) (x->funcAttrs.critical)
452 #define IFFUNC_ISCRITICAL(x) (IS_FUNC(x) && FUNC_ISCRITICAL(x))
453 #define FUNC_ISBUILTIN(x) (x->funcAttrs.builtin)
454 #define IFFUNC_ISBUILTIN(x) (IS_FUNC(x) && FUNC_ISBUILTIN(x))
455 #define FUNC_ISJAVANATIVE(x) (x->funcAttrs.javaNative)
456 #define IFFUNC_ISJAVANATIVE(x) (IS_FUNC(x) && FUNC_ISJAVANATIVE(x))
457 #define FUNC_ISOVERLAY(x) (x->funcAttrs.overlay)
458 #define IFFUNC_ISOVERLAY(x) (IS_FUNC(x) && FUNC_ISOVERLAY(x))
459 #define FUNC_ISSMALLC(x) (x->funcAttrs.smallc)
460 #define IFFUNC_ISSMALLC(x) (IS_FUNC(x) && FUNC_ISSMALLC(x))
461 #define FUNC_ISRAISONANCE(x) (x->funcAttrs.raisonance)
462 #define IFFUNC_ISRAISONANCE(x) (IS_FUNC(x) && FUNC_ISRAISONANCE(x))
463 #define FUNC_ISIAR(x) (x->funcAttrs.iar)
464 #define IFFUNC_ISIAR(x) (IS_FUNC(x) && FUNC_ISIAR(x))
465 #define FUNC_ISCOSMIC(x) (x->funcAttrs.cosmic)
466 #define IFFUNC_ISCOSMIC(x) (IS_FUNC(x) && FUNC_ISCOSMIC(x))
467 #define FUNC_ISZ88DK_FASTCALL(x) (x->funcAttrs.z88dk_fastcall)
468 #define IFFUNC_ISZ88DK_FASTCALL(x) (IS_FUNC(x) && FUNC_ISZ88DK_FASTCALL(x))
469 #define FUNC_ISZ88DK_CALLEE(x) (x->funcAttrs.z88dk_callee)
470 #define IFFUNC_ISZ88DK_CALLEE(x) (IS_FUNC(x) && FUNC_ISZ88DK_CALLEE(x))
471 #define FUNC_ISZ88DK_SHORTCALL(x) (x->funcAttrs.z88dk_shortcall)
472 #define IFFUNC_ISZ88DK_SHORTCALL(x) (IS_FUNC(x) && FUNC_ISZ88DK_SHORTCALL(x))
474 #define BANKED_FUNCTIONS ( options.model == MODEL_HUGE || \
475 ( (options.model == MODEL_LARGE || options.model == MODEL_MEDIUM) && \
476 TARGET_Z80_LIKE ) )
477 #define IFFUNC_ISBANKEDCALL(x) ( IS_FUNC(x) && \
478 ( FUNC_BANKED(x) || ( BANKED_FUNCTIONS && !FUNC_NONBANKED(x) ) ) )
480 #define SPEC_NOUN(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.noun
481 #define SPEC_LONG(x) validateLink(x, "SPEC_LONG", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_long
482 #define SPEC_LONGLONG(x) validateLink(x, "SPEC_LONGLONG", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_longlong
483 #define SPEC_SHORT(x) validateLink(x, "SPEC_LONG", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_short
484 #define SPEC_USIGN(x) validateLink(x, "SPEC_USIGN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_unsigned
485 #define SPEC_SIGN(x) validateLink(x, "SPEC_SIGN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_signed
486 #define SPEC_SCLS(x) validateLink(x, "SPEC_SCLS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.sclass
487 #define SPEC_SCLS_IMPLICITINTRINSIC(x) validateLink(x, "SPEC_SCLS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.sclass_implicitintrinsic
488 #define SPEC_ENUM(x) validateLink(x, "SPEC_ENUM", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_isenum
489 #define SPEC_OCLS(x) validateLink(x, "SPEC_OCLS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.oclass
490 #define SPEC_STAT(x) validateLink(x, "SPEC_STAT", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_static
491 #define SPEC_EXTR(x) validateLink(x, "SPEC_EXTR", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_extern
492 #define SPEC_CODE(x) validateLink(x, "SPEC_CODE", #x, SPECIFIER, __FILE__, __LINE__)->select.s._codesg
493 #define SPEC_ABSA(x) validateLink(x, "SPEC_ABSA", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_absadr
494 #define SPEC_BANK(x) validateLink(x, "SPEC_BANK", #x, SPECIFIER, __FILE__, __LINE__)->select.s._regbank
495 #define SPEC_ADDR(x) validateLink(x, "SPEC_ADDR", #x, SPECIFIER, __FILE__, __LINE__)->select.s._addr
496 #define SPEC_STAK(x) validateLink(x, "SPEC_STAK", #x, SPECIFIER, __FILE__, __LINE__)->select.s._stack
497 #define SPEC_CVAL(x) validateLink(x, "SPEC_CVAL", #x, SPECIFIER, __FILE__, __LINE__)->select.s.const_val
498 #define SPEC_BITINTWIDTH(x) validateLink(x, "SPEC_BITINTWIDTH", #x, SPECIFIER, __FILE__, __LINE__)->select.s.bitintwidth
499 #define SPEC_BSTR(x) validateLink(x, "SPEC_BSTR", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
500 #define SPEC_BLEN(x) validateLink(x, "SPEC_BLEN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitLength
501 #define SPEC_BUNNAMED(x) validateLink(x, "SPEC_BUNNAMED", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_bitUnnamed
502 #define SPEC_NEEDSPAR(x) validateLink(x, "SPEC_NEEDSPAR", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_needspar
504 /* Sleaze: SPEC_ISR_SAVED_BANKS is only used on
505 * function type symbols, which obviously cannot
506 * be of BIT type. Therefore, we recycle the
507 * _bitStart field instead of defining a new field.
509 #define SPEC_ISR_SAVED_BANKS(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
510 #define SPEC_CONST(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_const
511 #define SPEC_RESTRICT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_restrict
512 #define SPEC_VOLATILE(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_volatile
513 #define SPEC_ATOMIC(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_atomic
514 #define SPEC_ADDRSPACE(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.addrspace
515 #define SPEC_STRUCT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.v_struct
516 #define SPEC_TYPEDEF(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_typedef
517 #define SPEC_REGPARM(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_isregparm
518 #define SPEC_ARGREG(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.argreg
519 #define SPEC_INLINE(x) validateLink(x, "SPEC_INLINE", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_inline
520 #define SPEC_NORETURN(x) validateLink(x, "SPEC_NORETURN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_noreturn
521 #define SPEC_ALIGNAS(x) validateLink(x, "SPEC_ALIGNAS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_alignas
523 /* type check macros */
524 #define IS_DECL(x) ( x && x->xclass == DECLARATOR )
525 #define IS_SPEC(x) ( x && x->xclass == SPECIFIER )
527 #define IS_ARRAY(x) (IS_DECL(x) && DCL_TYPE(x) == ARRAY)
528 #define IS_DATA_PTR(x) (IS_DECL(x) && DCL_TYPE(x) == POINTER)
529 #define IS_SMALL_PTR(x) (IS_DECL(x) && (DCL_TYPE(x) == POINTER || \
530 DCL_TYPE(x) == IPOINTER || \
531 DCL_TYPE(x) == PPOINTER ))
532 #define IS_PTR(x) (IS_DECL(x) && (DCL_TYPE(x) == POINTER || \
533 DCL_TYPE(x) == FPOINTER || \
534 DCL_TYPE(x) == GPOINTER || \
535 DCL_TYPE(x) == IPOINTER || \
536 DCL_TYPE(x) == PPOINTER || \
537 DCL_TYPE(x) == EEPPOINTER || \
538 DCL_TYPE(x) == CPOINTER || \
539 DCL_TYPE(x) == UPOINTER ))
540 #define IS_PTR_CONST(x) (IS_PTR(x) && DCL_PTR_CONST(x))
541 #define IS_PTR_RESTRICT(x) (IS_PTR(x) && DCL_PTR_RESTRICT(x))
542 #define IS_FARPTR(x) (IS_DECL(x) && DCL_TYPE(x) == FPOINTER)
543 #define IS_CODEPTR(x) (IS_DECL(x) && DCL_TYPE(x) == CPOINTER)
544 #define IS_GENPTR(x) (IS_DECL(x) && DCL_TYPE(x) == GPOINTER)
545 #define IS_FUNCPTR(x) (IS_DECL(x) && (DCL_TYPE(x) == CPOINTER || DCL_TYPE(x) == GPOINTER || DCL_TYPE(x) == UPOINTER) && IS_FUNC(x->next))
546 #define IS_FUNC(x) (IS_DECL(x) && DCL_TYPE(x) == FUNCTION)
547 #define IS_LONG(x) (IS_SPEC(x) && x->select.s.b_long)
548 #define IS_LONGLONG(x) (IS_SPEC(x) && x->select.s.b_longlong)
549 #define IS_UNSIGNED(x) (IS_SPEC(x) && x->select.s.b_unsigned)
550 #define IS_TYPEDEF(x) (IS_SPEC(x) && x->select.s.b_typedef)
551 #define IS_CONSTANT(x) (isConstant (x))
552 #define IS_RESTRICT(x) (isRestrict (x))
553 #define IS_STRUCT(x) (IS_SPEC(x) && x->select.s.noun == V_STRUCT)
554 #define IS_ABSOLUTE(x) (IS_SPEC(x) && x->select.s.b_absadr )
555 #define IS_REGISTER(x) (IS_SPEC(x) && SPEC_SCLS(x) == S_REGISTER)
556 #define IS_STATIC(x) (IS_SPEC(x) && SPEC_STAT(x))
557 #define IS_INLINE(x) (IS_SPEC(x) && SPEC_INLINE(x))
558 #define IS_NORETURN(x) (IS_SPEC(x) && SPEC_NORETURN(x))
559 #define IS_INT(x) (IS_SPEC(x) && x->select.s.noun == V_INT)
560 #define IS_NULLPTR(x) (IS_SPEC(x) && x->select.s.noun == V_NULLPTR)
561 #define IS_VOID(x) (IS_SPEC(x) && x->select.s.noun == V_VOID)
562 #define IS_BOOL(x) (IS_SPEC(x) && x->select.s.noun == V_BOOL)
563 #define IS_BITINT(x) (IS_SPEC(x) && x->select.s.noun == V_BITINT)
564 #define IS_CHAR(x) (IS_SPEC(x) && x->select.s.noun == V_CHAR)
565 #define IS_EXTERN(x) (IS_SPEC(x) && x->select.s.b_extern)
566 #define IS_VOLATILE(x) (isVolatile (x))
567 #define IS_INTEGRAL(x) (IS_SPEC(x) && (x->select.s.noun == V_INT || \
568 x->select.s.noun == V_BITINT || \
569 x->select.s.noun == V_BOOL || \
570 x->select.s.noun == V_CHAR || \
571 x->select.s.noun == V_BITFIELD || \
572 x->select.s.noun == V_BBITFIELD || \
573 x->select.s.noun == V_BITINTBITFIELD || \
574 x->select.s.noun == V_BIT || \
575 x->select.s.noun == V_SBIT ))
576 #define IS_BITFIELD(x) (IS_SPEC(x) && (x->select.s.noun == V_BITFIELD || \
577 x->select.s.noun == V_BBITFIELD || \
578 x->select.s.noun == V_BITINTBITFIELD ))
579 #define IS_BITVAR(x) (IS_SPEC(x) && (x->select.s.noun == V_BITFIELD || \
580 x->select.s.noun == V_BBITFIELD || \
581 x->select.s.noun == V_BITINTBITFIELD || \
582 x->select.s.noun == V_BIT || \
583 x->select.s.noun == V_SBIT ))
584 #define IS_BIT(x) (IS_SPEC(x) && (x->select.s.noun == V_BIT || \
585 x->select.s.noun == V_SBIT ))
586 #define IS_BOOLEAN(x) (IS_SPEC(x) && (x->select.s.noun == V_BIT || \
587 x->select.s.noun == V_SBIT || \
588 x->select.s.noun == V_BBITFIELD || \
589 x->select.s.noun == V_BOOL ))
590 #define IS_FLOAT(x) (IS_SPEC(x) && x->select.s.noun == V_FLOAT)
591 #define IS_FIXED16X16(x) (IS_SPEC(x) && x->select.s.noun == V_FIXED16X16)
592 #define IS_FIXED(x) (IS_FIXED16X16(x))
593 #define IS_ARITHMETIC(x) (IS_INTEGRAL(x) || IS_FLOAT(x) || IS_FIXED(x))
594 #define IS_AGGREGATE(x) (IS_ARRAY(x) || IS_STRUCT(x))
595 #define IS_LITERAL(x) (IS_SPEC(x) && x->select.s.sclass == S_LITERAL)
596 #define IS_CODE(x) (IS_SPEC(x) && SPEC_SCLS(x) == S_CODE)
597 #define IS_REGPARM(x) (IS_SPEC(x) && SPEC_REGPARM(x))
599 #define IS_VALID_PARAMETER_STORAGE_CLASS_SPEC(x) (!SPEC_TYPEDEF(x) && !SPEC_EXTR(x) && !SPEC_STAT(x) && SPEC_SCLS(x) != S_AUTO)
601 /* symbol check macros */
602 #define IS_AUTO(x) (x->level && !IS_STATIC(x->etype) && !IS_EXTERN(x->etype))
604 /* forward declaration for the global vars */
605 extern bucket *SymbolTab[];
606 extern bucket *StructTab[];
607 extern bucket *TypedefTab[];
608 extern bucket *LabelTab[];
609 extern bucket *enumTab[];
610 extern bucket *AddrspaceTab[];
611 extern symbol *fsadd;
612 extern symbol *fssub;
613 extern symbol *fsmul;
614 extern symbol *fsdiv;
615 extern symbol *fseq;
616 extern symbol *fsneq;
617 extern symbol *fslt;
619 extern symbol *fps16x16_add;
620 extern symbol *fps16x16_sub;
621 extern symbol *fps16x16_mul;
622 extern symbol *fps16x16_div;
623 extern symbol *fps16x16_eq;
624 extern symbol *fps16x16_neq;
625 extern symbol *fps16x16_lt;
626 extern symbol *fps16x16_lteq;
627 extern symbol *fps16x16_gt;
628 extern symbol *fps16x16_gteq;
630 /* Dims: mul/div/mod, BYTE/WORD/DWORD/QWORD, SIGNED/UNSIGNED/BOTH */
631 extern symbol *muldiv[3][4][4];
632 /* 16 x 16 -> 32 multiplication SIGNED/UNSIGNED */
633 extern symbol *muls16tos32[2];
634 /* 32 x 8 -> 64 multiplication UNSIGNED */
635 extern symbol *mulu32u8tou64;
636 /* Dims: BYTE/WORD/DWORD/QWORD SIGNED/UNSIGNED */
637 extern sym_link *multypes[4][2];
638 /* Dims: to/from float, BYTE/WORD/DWORD/QWORD, SIGNED/UNSIGNED */
639 extern symbol *conv[2][4][2];
640 /* Dims: to/from fixed16x16, BYTE/WORD/DWORD/QWORD/FLOAT, SIGNED/UNSIGNED */
641 extern symbol *fp16x16conv[2][5][2];
642 /* Dims: shift left/shift right, BYTE/WORD/DWORD/QWORD, SIGNED/UNSIGNED */
643 extern symbol *rlrr[2][4][2];
645 extern symbol *builtin_memcpy;
646 extern symbol *nonbuiltin_memcpy;
648 #define SCHARTYPE multypes[0][0]
649 #define UCHARTYPE multypes[0][1]
650 #define INTTYPE multypes[1][0]
651 #define UINTTYPE multypes[1][1]
652 #define LONGTYPE multypes[2][0]
653 #define ULONGTYPE multypes[2][1]
654 #define LONGLONGTYPE multypes[3][0]
655 #define ULONGLONGTYPE multypes[3][1]
657 extern sym_link *floatType;
658 extern sym_link *fixed16x16Type;
660 #include "SDCCval.h"
662 typedef enum
664 RESULT_TYPE_NONE = 0, /* operands will be promoted to int */
665 RESULT_TYPE_BOOL,
666 RESULT_TYPE_CHAR,
667 RESULT_TYPE_INT,
668 RESULT_TYPE_OTHER, /* operands will be promoted to int */
669 RESULT_TYPE_IFX,
670 RESULT_TYPE_GPTR /* operands will be promoted to generic ptr */
671 } RESULT_TYPE;
673 /* forward definitions for the symbol table related functions */
674 void initSymt ();
675 symbol *newSymbol (const char *, long);
676 sym_link *newLink (SYM_LINK_CLASS);
677 sym_link *newFloatLink ();
678 structdef *newStruct (const char *);
679 void addDecl (symbol *, int, sym_link *);
680 sym_link *finalizeSpec (sym_link *);
681 sym_link *mergeSpec (sym_link *, sym_link *, const char *name);
682 sym_link *mergeDeclSpec (sym_link *, sym_link *, const char *name);
683 symbol *reverseSyms (symbol *);
684 sym_link *reverseLink (sym_link *);
685 symbol *copySymbol (const symbol *);
686 symbol *copySymbolChain (const symbol *);
687 char *genSymName (long);
688 sym_link *getSpec (sym_link *);
689 int compStructSize (int, structdef *);
690 sym_link *copyLinkChain (const sym_link *);
691 int checkDecl (symbol *, int);
692 void checkBasic (sym_link *, sym_link *);
693 value *checkPointerIval (sym_link *, value *);
694 value *checkStructIval (symbol *, value *);
695 value *checkArrayIval (sym_link *, value *);
696 value *checkIval (sym_link *, value *);
697 unsigned int getSize (sym_link *);
698 unsigned int bitsForType (sym_link *);
699 sym_link *newBitIntLink (unsigned int width);
700 sym_link *newIntLink ();
701 sym_link *newCharLink ();
702 sym_link *newLongLink ();
703 sym_link *newLongLongLink ();
704 sym_link *newBoolLink ();
705 sym_link *newPtrDiffLink ();
706 sym_link *newVoidLink ();
707 int compareType (sym_link *, sym_link *, bool ignoreimplicitintrinsic);
708 int compareTypeExact (sym_link *, sym_link *, long);
709 int compareTypeInexact (sym_link *, sym_link *);
710 int checkFunction (symbol *, symbol *);
711 void cleanUpLevel (bucket **, long);
712 void cleanUpBlock (bucket **, int);
713 symbol *getAddrspace (sym_link *type);
714 int funcInChain (sym_link *);
715 void addSymChain (symbol **);
716 sym_link *structElemType (sym_link *, value *);
717 symbol *getStructElement (structdef *, symbol *);
718 sym_link *computeType (sym_link *, sym_link *, RESULT_TYPE, int);
719 void processFuncPtrArgs (sym_link *);
720 void processFuncArgs (symbol *, sym_link *);
721 int isSymbolEqual (const symbol *, const symbol *);
722 int powof2 (TYPE_TARGET_ULONGLONG);
723 void dbuf_printTypeChain (sym_link *, struct dbuf_s *);
724 void printTypeChain (sym_link *, FILE *);
725 void printTypeChainRaw (sym_link *, FILE *);
726 void initCSupport ();
727 void initBuiltIns ();
728 void pointerTypes (sym_link *, sym_link *);
729 void cdbStructBlock (int);
730 void initHashT ();
731 bucket *newBucket ();
732 void addSym (bucket **, void *, char *, long, int, int checkType);
733 void deleteSym (bucket **, void *, const char *);
734 void *findSym (bucket **, void *, const char *);
735 void *findSymWithLevel (bucket **, struct symbol *);
736 void *findSymWithBlock (bucket **, struct symbol *, int, long);
737 void changePointer (sym_link * p);
738 void checkTypeSanity (sym_link * etype, const char *name);
739 sym_link *typeFromStr (const char *);
740 STORAGE_CLASS sclsFromPtr (sym_link * ptr);
741 sym_link *newEnumType (symbol *enumlist, sym_link *userRequestedType);
742 void promoteAnonStructs (int, structdef *);
743 int isConstant (sym_link * type);
744 int isVolatile (sym_link * type);
745 int isRestrict (sym_link * type);
746 value *aggregateToPointer (value *);
747 void leaveBlockScope (int block);
748 void mergeKRDeclListIntoFuncDecl (symbol *funcDecl, symbol *kr_decls);
751 extern char *nounName (sym_link *); /* noun strings */
752 extern void printFromToType (sym_link *, sym_link *);
754 #endif