* src/*.c, src/pic16/{gen.c,glue.c,main.c}: applied Vangelis
[fw/sdcc] / src / SDCCsymt.h
index f79b049322de30f01738d081eb6b4dd91341e24a..df7e048432760691865f8796ef597990059fcc0f 100644 (file)
@@ -41,6 +41,7 @@ enum {
     TYPEOF_CHAR,
     TYPEOF_LONG,
     TYPEOF_FLOAT,
+    TYPEOF_FIXED16X16,
     TYPEOF_BIT,
     TYPEOF_BITFIELD,
     TYPEOF_SBIT,
@@ -58,13 +59,11 @@ enum {
     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
+// values for first byte (or 3 most significant bits) of generic pointer.
+#define GPTYPE_FAR       0x00
+#define GPTYPE_NEAR      0x40
+#define GPTYPE_XSTACK    0x60
+#define GPTYPE_CODE      0x80
 
 #define HASHTAB_SIZE 256
 
@@ -95,6 +94,7 @@ typedef enum
   {
     V_INT = 1,
     V_FLOAT,
+    V_FIXED16X16,
     V_CHAR,
     V_VOID,
     V_STRUCT,
@@ -152,12 +152,13 @@ typedef struct specifier
     int argreg;                /* reg no for regparm         */
     union
       {                                /* Values if constant or enum */
-       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 */
+       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 value  */
        double      v_float;    /*          floating point constant value */
+       TYPE_UDWORD v_fixed16x16; /* 4 bytes: fixed floating point constant value */
        struct symbol *v_enum;  /* ptr 2 enum_list if enum==1 */
       }
     const_val;
@@ -218,13 +219,15 @@ typedef struct sym_link
       unsigned reent:1;                /* function is reentrant      */
       unsigned naked:1;                /* naked function             */
 
+      unsigned shadowregs:1;    /* function uses shadow registers (pic16 port) */
+      unsigned wparam:1;       /* first byte of arguments is passed via WREG (pic16 port) */
       unsigned nonbanked:1;    /* function has the nonbanked attribute */
       unsigned banked:1;       /* function has the banked attribute */
       unsigned critical:1;     /* critical function          */
-      unsigned intrtn:1;       /* this is an interrupt routin */
+      unsigned intrtn:1;        /* this is an interrupt routine */
       unsigned rbank:1;                /* seperate register bank     */
       unsigned intno;          /* 1=Interrupt svc routine    */
-      unsigned regbank;                /* register bank 2b used      */
+      short    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 */
@@ -279,7 +282,7 @@ typedef struct symbol
     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
+                                   On the Z80 accuse is divided into
                                   ACCUSE_A and ACCUSE_HL as the idea
                                   is quite similar.
                                 */
@@ -295,8 +298,10 @@ typedef struct symbol
     struct regs *regs[4];      /* can have at the most 4 registers */
     struct asmop *aop;         /* asmoperand for this symbol */
     struct iCode *fuse;                /* furthest use */
-    struct iCode *rematiCode;  /* rematerialse with which instruction */
+    struct iCode *rematiCode;   /* rematerialise with which instruction */
     struct operand *reqv;      /* register equivalent of a local variable */
+    struct symbol *prereqv;    /* symbol before register equiv. substituion */
+    struct symbol *psbase;     /* if pseudo symbol, the symbol it is based on */
     union
       {
        struct symbol *spillLoc;        /* register spil location */
@@ -307,9 +312,10 @@ typedef struct symbol
     unsigned offset;           /* offset from top if struct */
 
     int lineDef;               /* defined line number        */
+    char *fileDef;             /* defined filename           */
     int lastLine;              /* for functions the last line */
-    struct sym_link *type;     /* 1st link to declator chain */
-    struct sym_link *etype;    /* last link to declarator chn */
+    struct sym_link *type;      /* 1st link to declarator chain */
+    struct sym_link *etype;     /* last link to declarator chain */
     struct symbol *next;       /* crosslink to next symbol   */
     struct symbol *localof;    /* local variable of which function */
     struct initList *ival;     /* ptr to initializer if any  */
@@ -357,6 +363,10 @@ extern sym_link *validateLink(sym_link     *l,
 
 #define FUNC_ISREENT(x) (x->funcAttrs.reent)
 #define IFFUNC_ISREENT(x) (IS_FUNC(x) && FUNC_ISREENT(x))
+#define FUNC_ISSHADOWREGS(x) (x->funcAttrs.shadowregs)
+#define IFFUNC_ISSHADOWREGS(x) (IS_FUNC(x) && FUNC_ISSHADOWREGS(x))
+#define FUNC_ISWPARAM(x) (x->funcAttrs.wparam)
+#define IFFUNC_ISWPARAM(x) (IS_FUNC(x) && FUNC_ISWPARAM(x))
 #define FUNC_ISNAKED(x) (x->funcAttrs.naked)
 #define IFFUNC_ISNAKED(x) (IS_FUNC(x) && FUNC_ISNAKED(x))
 #define FUNC_NONBANKED(x) (x->funcAttrs.nonbanked)
@@ -373,8 +383,9 @@ extern sym_link *validateLink(sym_link      *l,
 #define IFFUNC_ISOVERLAY(x) (IS_FUNC(x) && FUNC_ISOVERLAY(x))
 
 #define IFFUNC_ISBANKEDCALL(x) (!IFFUNC_NONBANKED(x) && \
-  (options.model == MODEL_LARGE || \
-   options.model == MODEL_MEDIUM || \
+  (options.model == MODEL_HUGE || \
+   ((options.model == MODEL_LARGE || options.model == MODEL_MEDIUM) && \
+   (TARGET_IS_Z80 || TARGET_IS_GBZ80)) || \
   IFFUNC_BANKED(x)))
 
 #define SPEC_NOUN(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.noun
@@ -425,6 +436,7 @@ extern sym_link *validateLink(sym_link      *l,
 #define IS_FARPTR(x) (IS_DECL(x) && DCL_TYPE(x) == FPOINTER)
 #define IS_CODEPTR(x) (IS_DECL(x) && DCL_TYPE(x) == CPOINTER)
 #define IS_GENPTR(x) (IS_DECL(x) && DCL_TYPE(x) == GPOINTER)
+#define IS_FUNCPTR(x) (IS_DECL(x) && (DCL_TYPE(x) == CPOINTER || DCL_TYPE(x) == GPOINTER) && IS_FUNC(x->next))
 #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)
@@ -455,13 +467,20 @@ extern sym_link *validateLink(sym_link    *l,
 #define IS_BITVAR(x) (IS_SPEC(x) && (x->select.s.noun == V_BITFIELD || \
                                      x->select.s.noun  == V_BIT ||   \
                                      x->select.s.noun == V_SBIT ))
+#define IS_BIT(x) (IS_SPEC(x) && (x->select.s.noun  == V_BIT ||   \
+                                  x->select.s.noun == V_SBIT ))
 #define IS_FLOAT(x)  (IS_SPEC(x) && x->select.s.noun == V_FLOAT)
-#define IS_ARITHMETIC(x) (IS_INTEGRAL(x) || IS_FLOAT(x))
+#define IS_FIXED16X16(x)  (IS_SPEC(x) && x->select.s.noun == V_FIXED16X16)
+#define IS_FIXED(x) (IS_FIXED16X16(x))
+#define IS_ARITHMETIC(x) (IS_INTEGRAL(x) || IS_FLOAT(x) || IS_FIXED(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))
 
+/* symbol check macros */
+#define IS_AUTO(x) (x->level && !IS_STATIC(x->etype) && !IS_EXTERN(x->etype))
+
 /* forward declaration for the global vars */
 extern bucket *SymbolTab[];
 extern bucket *StructTab[];
@@ -479,12 +498,25 @@ extern symbol *__fslteq;
 extern symbol *__fsgt;
 extern symbol *__fsgteq;
 
+extern symbol *__fps16x16_add;
+extern symbol *__fps16x16_sub;
+extern symbol *__fps16x16_mul;
+extern symbol *__fps16x16_div;
+extern symbol *__fps16x16_eq;
+extern symbol *__fps16x16_neq;
+extern symbol *__fps16x16_lt;
+extern symbol *__fps16x16_lteq;
+extern symbol *__fps16x16_gt;
+extern symbol *__fps16x16_gteq;
+
 /* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
 extern symbol *__muldiv[3][3][2];
 /* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */
 extern sym_link *__multypes[3][2];
 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
 extern symbol *__conv[2][3][2];
+/* Dims: to/from fixed16x16, BYTE/WORD/DWORD/FLOAT, SIGNED/USIGNED */
+extern symbol *__fp16x16conv[2][4][2];
 /* Dims: shift left/shift right, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
 extern symbol *__rlrr[2][3][2];
 
@@ -495,11 +527,21 @@ extern symbol *__rlrr[2][3][2];
 #define LONGTYPE       __multypes[2][0]
 #define ULONGTYPE      __multypes[2][1]
 
-
 extern sym_link *floatType;
+extern sym_link *fixed16x16Type;
 
 #include "SDCCval.h"
 
+typedef enum
+{
+  RESULT_TYPE_NONE = 0,        /* operands will be promoted to int */
+  RESULT_TYPE_BIT,
+  RESULT_TYPE_CHAR,
+  RESULT_TYPE_INT,
+  RESULT_TYPE_OTHER,   /* operands will be promoted to int */
+  RESULT_TYPE_IFX,
+} RESULT_TYPE;
+
 /* forward definitions for the symbol table related functions */
 void initSymt ();
 symbol *newSymbol (char *, int);
@@ -526,6 +568,7 @@ value *checkStructIval (symbol *, value *);
 value *checkArrayIval (sym_link *, value *);
 value *checkIval (sym_link *, value *);
 unsigned int getSize (sym_link *);
+unsigned int getAllocSize (sym_link *);
 unsigned int bitsForType (sym_link *);
 sym_link *newIntLink ();
 sym_link *newCharLink ();
@@ -536,10 +579,10 @@ int checkFunction (symbol *, symbol *);
 void cleanUpLevel (bucket **, int);
 void cleanUpBlock (bucket **, int);
 int funcInChain (sym_link *);
-void addSymChain (symbol *);
+void addSymChain (symbol **);
 sym_link *structElemType (sym_link *, value *);
 symbol *getStructElement (structdef *, symbol *);
-sym_link *computeType (sym_link *, sym_link *, bool promoteCharToInt);
+sym_link *computeType (sym_link *, sym_link *, RESULT_TYPE, int);
 void processFuncArgs (symbol *);
 int isSymbolEqual (symbol *, symbol *);
 int powof2 (TYPE_UDWORD);
@@ -556,10 +599,12 @@ void deleteSym (bucket **, void *, char *);
 void *findSym (bucket **, void *, const char *);
 void *findSymWithLevel (bucket **, struct symbol *);
 void *findSymWithBlock (bucket **, struct symbol *, int);
-void changePointer (symbol * sym);
+void changePointer (sym_link * p);
 void checkTypeSanity(sym_link *etype, char *name);
 sym_link *typeFromStr (char *) ;
 STORAGE_CLASS sclsFromPtr(sym_link *ptr);
+sym_link *newEnumType (symbol *);
+void  promoteAnonStructs (int, structdef *);
 
 
 extern char *nounName(sym_link *); /* noun strings */