fixed bug #697590
[fw/sdcc] / src / SDCCsymt.h
index 6ff6e0a72addecde9906c0d4dd7fe5f953c11a28..f1cc4de749906ba38440b2af1caa9a0186eebb2a 100644 (file)
 #define SDCC_SYMNAME_MAX 64
 #define SDCC_NAME_MAX  3*SDCC_SYMNAME_MAX // big enough for _<func>_<var>_etc
 #include "SDCChasht.h"
-
+#include "SDCCglobl.h"
+
+enum {
+    TYPEOF_INT=1,
+    TYPEOF_SHORT,
+    TYPEOF_CHAR,
+    TYPEOF_LONG,
+    TYPEOF_FLOAT,
+    TYPEOF_BIT,
+    TYPEOF_SBIT,
+    TYPEOF_SFR,
+    TYPEOF_VOID,
+    TYPEOF_STRUCT,
+    TYPEOF_ARRAY,
+    TYPEOF_FUNCTION,
+    TYPEOF_POINTER,
+    TYPEOF_FPOINTER,
+    TYPEOF_CPOINTER,
+    TYPEOF_GPOINTER,
+    TYPEOF_PPOINTER,
+    TYPEOF_IPOINTER,
+    TYPEOF_EEPPOINTER
+};
+
+// values for first byte of generic pointer.
+#define GPTYPE_NEAR    0
+#define GPTYPE_FAR     1
+#define GPTYPE_CODE    2
+#define GPTYPE_XSTACK  3
+#define GPTYPE_GPTR    4       // Never used?
+#define GPTYPE_IDATA   5
 
 #define HASHTAB_SIZE 256
 
@@ -111,15 +141,15 @@ typedef struct specifier
     unsigned _stack;           /* stack offset for stacked v */
     unsigned _bitStart;                /* bit start position         */
     int _bitLength;            /* bit length                 */
-
+    int argreg;                /* reg no for regparm         */
     union
       {                                /* Values if constant or enum */
-       short int v_int;                /* int and char values        */
-       char *v_char;           /* character string           */
-       unsigned short v_uint;  /* unsigned int const value   */
-       long v_long;            /* long constant value        */
-       unsigned long v_ulong;  /* unsigned long constant val */
-       double v_float;         /* floating point constant value */
+       TYPE_WORD   v_int;      /* 2 bytes: int and char values        */
+       char       *v_char;     /*          character string           */
+       TYPE_UWORD  v_uint;     /* 2 bytes: unsigned int const value   */
+       TYPE_DWORD  v_long;     /* 4 bytes: long constant value        */
+       TYPE_UDWORD v_ulong;    /* 4 bytes: unsigned long constant val */
+       double      v_float;    /*          floating point constant value */
        struct symbol *v_enum;  /* ptr 2 enum_list if enum==1 */
       }
     const_val;
@@ -185,6 +215,10 @@ typedef struct sym_link
       unsigned rbank:1;                /* seperate register bank     */
       unsigned intno;          /* 1=Interrupt svc routine    */
       unsigned regbank;                /* register bank 2b used      */
+      unsigned builtin;                /* is a builtin function      */
+      unsigned javaNative;     /* is a JavaNative Function (TININative ONLY) */
+      unsigned overlay;        /* force parameters & locals into overlay segment */
+      unsigned hasStackParms;   /* function has parameters on stack */
     } funcAttrs;
 
     struct sym_link *next;     /* next element on the chain  */
@@ -208,9 +242,7 @@ typedef struct symbol
     unsigned isref:1;          /* has been referenced  */
     unsigned isind:1;          /* is a induction variable */
     unsigned isinvariant:1;    /* is a loop invariant  */
-    unsigned isstrlit:1;       /* is a string literal  */
     unsigned cdef:1;           /* compiler defined symbol */
-    unsigned allocreq:1;       /* allocation is required for this variable */
     unsigned addrtaken:1;      /* address of the symbol was taken */
     unsigned isreqv:1;         /* is the register quivalent of a symbol */
     unsigned udChked:1;                /* use def checking has been already done */
@@ -220,6 +252,7 @@ typedef struct symbol
        if a better scheme for backend is thought of */
     unsigned isLiveFcall:1;    /* is live at or across a function call */
     unsigned isspilt:1;                /* has to be spilt */
+    unsigned spillA:1;         /* spilt be register allocator */
     unsigned remat:1;          /* can be remateriazed */
     unsigned isptr:1;          /* is a pointer */
     unsigned uptr:1;           /* used as a pointer */
@@ -234,12 +267,16 @@ typedef struct symbol
     unsigned spildir:1;                /* spilt in direct space */
     unsigned ptrreg:1;         /* this symbol assigned to a ptr reg */
     unsigned noSpilLoc:1;      /* cannot be assigned a spil location */
+    unsigned isstrlit;         /* is a string literal and it's usage count  */
     unsigned accuse;           /* can be left in the accumulator
                                   On the Z80 accuse is devided into
                                   ACCUSE_A and ACCUSE_HL as the idea
                                   is quite similar.
                                 */
-
+    unsigned dptr;             /* 8051 variants with multiple DPTRS
+                                  currently implemented in DS390 only
+                               */
+    int allocreq ;             /* allocation is required for this variable */
     int stack;                 /* offset on stack      */
     int xstack;                        /* offset on xternal stack */
     short nRegs;               /* number of registers required */
@@ -273,6 +310,7 @@ typedef struct symbol
     int liveTo;                        /* live to sequence number */
     int used;                  /* no. of times this was used */
     int recvSize;              /* size of first argument  */
+    struct bitVect *clashes;    /* overlaps with what other symbols */
   }
 symbol;
 
@@ -296,10 +334,10 @@ symbol;
 #define IFFUNC_CALLEESAVES(x) (IS_FUNC(x) && FUNC_CALLEESAVES(x))
 #define FUNC_ISISR(x) (x->funcAttrs.intrtn)
 #define IFFUNC_ISISR(x) (IS_FUNC(x) && FUNC_ISISR(x))
-//#define FUNC_RBANK(x) (x->funcAttrs.rbank)
 #define IFFUNC_RBANK(x) (IS_FUNC(x) && FUNC_RBANK(x))
 #define FUNC_INTNO(x) (x->funcAttrs.intno)
 #define FUNC_REGBANK(x) (x->funcAttrs.regbank)
+#define FUNC_HASSTACKPARM(x) (x->funcAttrs.hasStackParms)
 
 #define FUNC_ISREENT(x) (x->funcAttrs.reent)
 #define IFFUNC_ISREENT(x) (IS_FUNC(x) && FUNC_ISREENT(x))
@@ -311,6 +349,13 @@ symbol;
 #define IFFUNC_BANKED(x) (IS_FUNC(x) && FUNC_BANKED(x))
 #define FUNC_ISCRITICAL(x) (x->funcAttrs.critical)
 #define IFFUNC_ISCRITICAL(x) (IS_FUNC(x) && FUNC_ISCRITICAL(x))
+#define FUNC_ISBUILTIN(x) (x->funcAttrs.builtin)
+#define IFFUNC_ISBUILTIN(x) (IS_FUNC(x) && FUNC_ISBUILTIN(x))
+#define FUNC_ISJAVANATIVE(x) (x->funcAttrs.javaNative)
+#define IFFUNC_ISJAVANATIVE(x) (IS_FUNC(x) && FUNC_ISJAVANATIVE(x))
+#define FUNC_ISOVERLAY(x) (x->funcAttrs.overlay)
+#define IFFUNC_ISOVERLAY(x) (IS_FUNC(x) && FUNC_ISOVERLAY(x))
+
 
 // jwk: I am not sure about this
 #define IFFUNC_ISBANKEDCALL(x) (!IFFUNC_NONBANKED(x) && \
@@ -346,6 +391,7 @@ symbol;
 #define SPEC_STRUCT(x) x->select.s.v_struct
 #define SPEC_TYPEDEF(x) x->select.s._typedef
 #define SPEC_REGPARM(x) x->select.s._isregparm
+#define SPEC_ARGREG(x) x->select.s.argreg
 
 /* type check macros */
 #define IS_DECL(x)   ( x && x->class == DECLARATOR     )
@@ -366,6 +412,7 @@ symbol;
 #define IS_GENPTR(x) (IS_DECL(x) && DCL_TYPE(x) == GPOINTER)
 #define IS_FUNC(x)   (IS_DECL(x) && DCL_TYPE(x) == FUNCTION)
 #define IS_LONG(x)   (IS_SPEC(x) && x->select.s._long)
+#define IS_UNSIGNED(x) (IS_SPEC(x) && x->select.s._unsigned)
 #define IS_TYPEDEF(x)(IS_SPEC(x) && x->select.s._typedef)
 #define IS_CONSTANT(x)  (IS_SPEC(x) && ( x->select.s._const == 1))
 #define IS_STRUCT(x) (IS_SPEC(x) && x->select.s.noun == V_STRUCT)
@@ -389,6 +436,7 @@ symbol;
 #define IS_ARITHMETIC(x) (IS_INTEGRAL(x) || IS_FLOAT(x))
 #define IS_AGGREGATE(x) (IS_ARRAY(x) || IS_STRUCT(x))
 #define IS_LITERAL(x)   (IS_SPEC(x)  && x->select.s.sclass == S_LITERAL)
+#define IS_CODE(x)      (IS_SPEC(x)  && SPEC_SCLS(x) == S_CODE)
 #define IS_REGPARM(x)   (IS_SPEC(x) && SPEC_REGPARM(x))
 
 /* forward declaration for the global vars */
@@ -437,7 +485,6 @@ sym_link *newFloatLink ();
 structdef *newStruct (char *);
 void addDecl (symbol *, int, sym_link *);
 sym_link *mergeSpec (sym_link *, sym_link *, char *name);
-sym_link *cloneSpec (sym_link *);
 symbol *reverseSyms (symbol *);
 sym_link *reverseLink (sym_link *);
 symbol *copySymbol (symbol *);
@@ -469,11 +516,12 @@ void addSymChain (symbol *);
 sym_link *structElemType (sym_link *, value *);
 symbol *getStructElement (structdef *, symbol *);
 sym_link *computeType (sym_link *, sym_link *);
-void processFuncArgs (symbol *, int);
+void processFuncArgs (symbol *);
 int isSymbolEqual (symbol *, symbol *);
 int powof2 (unsigned long);
 void printTypeChain (sym_link *, FILE *);
 void initCSupport ();
+void initBuiltIns ();
 void pointerTypes (sym_link *, sym_link *);
 void cdbTypeInfo (sym_link *, FILE *);
 void cdbSymbol (symbol *, FILE *, int, int);
@@ -487,6 +535,8 @@ void *findSymWithLevel (bucket **, struct symbol *);
 void *findSymWithBlock (bucket **, struct symbol *, int);
 void changePointer (symbol * sym);
 void checkTypeSanity(sym_link *etype, char *name);
+sym_link *typeFromStr (char *) ;
+
 
 extern char *nounName(sym_link *); /* noun strings */
 extern void printFromToType (sym_link *, sym_link *);