various ds390 code generator improvements, including fixing an 'ack!' in genCmpLt
[fw/sdcc] / src / SDCCsymt.h
index d25cd4180a741ff9aceb159ecd3305a3ec78035e..55d95ec8ffaf84c816619bc9fbddd62924a72fff 100644 (file)
@@ -50,17 +50,20 @@ typedef struct structdef {
 } structdef ;
 
 /* noun definitions */
-enum  { V_INT   =  0,
+typedef enum { 
+       V_INT   =  0,
        V_FLOAT     ,
         V_CHAR      ,
         V_VOID      ,
         V_STRUCT    ,
         V_LABEL     ,
         V_BIT       ,
-        V_SBIT      };
+        V_SBIT      
+} NOUN;
 
 /* storage class    */
-enum  { S_FIXED  =  0,
+typedef enum { 
+       S_FIXED  =  0,
         S_AUTO       ,
         S_REGISTER   ,        
         S_CONSTANT   ,
@@ -75,12 +78,13 @@ enum  { S_FIXED  =  0,
         S_STACK      ,
         S_XSTACK     ,
         S_BIT        ,
-        S_EEPROM      };
+        S_EEPROM      
+} STORAGE_CLASS;
 
 /* specifier is the last in the type-chain */
 typedef struct specifier {
-    unsigned    noun        ;  /* CHAR INT STRUCTURE LABEL   */
-    unsigned    sclass      ;  /* REGISTER,AUTO,FIX,CONSTANT */
+    NOUN       noun        ;  /* CHAR INT STRUCTURE LABEL   */
+    STORAGE_CLASS sclass    ;  /* REGISTER,AUTO,FIX,CONSTANT */
     struct memmap *oclass   ;  /* output storage class       */
     unsigned    _long : 1   ;  /* 1=long            */
     unsigned    _short: 1      ;       /* 1=short int    */
@@ -97,6 +101,8 @@ typedef struct specifier {
     unsigned   _typedef :1  ;  /* is typedefed               */
     unsigned   _isregparm:1 ;  /* is the first parameter     */
     unsigned   _isenum   :1 ;  /* is an enumerated type      */
+    unsigned   nonbanked   :1  ;  /* function has the nonbanked attribute */
+    unsigned   banked   :1  ;  /* function has the banked attribute */
     unsigned   _IntNo       ;  /* 1=Interrupt svc routine    */
     short      _regbank     ;  /* register bank 2b used      */
     unsigned   _addr        ;  /* address of symbol          */
@@ -117,7 +123,8 @@ typedef struct specifier {
 } specifier ;
 
 /* types of declarators */
-enum {  POINTER   = 0,       /* pointer to near data */
+typedef enum {
+       POINTER   = 0,       /* pointer to near data */
         FPOINTER     ,       /* pointer to far data  */
         CPOINTER     ,       /* pointer to code space */
         GPOINTER     ,       /* _generic pointer     */
@@ -126,20 +133,21 @@ enum {  POINTER   = 0,       /* pointer to near data */
        UPOINTER     ,       /* unknown pointer used only when parsing */
        EEPPOINTER   ,       /* pointer to eeprom     */
         ARRAY        ,
-        FUNCTION     };
+        FUNCTION     
+} DECLARATOR_TYPE;
 
 typedef struct declarator {
-    short    dcl_type;     /* POINTER,ARRAY or FUNCTION  */
-    short    num_elem;     /* # of elems if type==array  */
-    short    ptr_const :1;   /* pointer is constant        */
-    short    ptr_volatile:1; /* pointer is volatile        */
-    struct link *tspec;     /* pointer type specifier      */
+    DECLARATOR_TYPE dcl_type;       /* POINTER,ARRAY or FUNCTION  */
+    unsigned int    num_elem;       /* # of elems if type==array  */
+    short           ptr_const :1;   /* pointer is constant        */
+    short           ptr_volatile:1; /* pointer is volatile        */
+    struct sym_link *tspec;         /* pointer type specifier      */
 } declarator ;
 
 #define DECLARATOR   0
 #define SPECIFIER    1
 
-typedef struct link {
+typedef struct sym_link {
        unsigned class : 1      ;  /* DECLARATOR or SPECIFIER    */
        unsigned tdef  : 1      ;  /* current link created by    */
                                    /* typedef if this flag is set*/
@@ -148,8 +156,8 @@ typedef struct link {
                declarator     d     ;  /* if CLASS == DECLARATOR     */
        } select ;
 
-       struct link    *next    ;  /* next element on the chain  */
-} link ;
+       struct sym_link *next    ;  /* next element on the chain  */
+} sym_link ;
 
 typedef struct symbol {
     char name [SDCC_NAME_MAX+1]        ;  /* Input Variable Name     */
@@ -177,11 +185,12 @@ typedef struct symbol {
     unsigned isreqv     :1      ;  /* is the register quivalent of a symbol */
     unsigned hasFcall   :1      ;  /* for functions does it call other functions */
     unsigned calleeSave :1      ;  /* for functions uses callee save paradigm */
+    unsigned udChked    :1      ;  /* use def checking has been already done */
 
     /* following flags are used by the backend
        for code generation and can be changed
        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 remat      :1      ;  /* can be remateriazed */
     unsigned isptr      :1      ;  /* is a pointer */
@@ -194,9 +203,13 @@ typedef struct symbol {
     unsigned onStack    :1      ;  /* this symbol allocated on the stack */
     unsigned iaccess    :1      ;  /* indirect access      */
     unsigned ruonly     :1      ;  /* used in return statement only */
-    unsigned accuse     :1      ;  /* can be left in the accumulator */
     unsigned spildir    :1      ;  /* spilt in direct space */
     unsigned ptrreg     :1      ;  /* this symbol assigned to a ptr reg */
+    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.
+                                  */
 
     int      stack              ;  /* offset on stack      */
     int      xstack             ;  /* offset on xternal stack */
@@ -217,12 +230,12 @@ typedef struct symbol {
     
     int      lineDef           ;  /* defined line number        */
     int      lastLine           ;  /* for functions the last line*/
-    struct   link  *type        ;  /* 1st link to declator chain */
-    struct   link  *etype       ;  /* last link to declarator chn*/
+    struct   sym_link  *type    ;  /* 1st link to declator chain */
+    struct   sym_link  *etype   ;  /* last link to declarator chn*/
     struct   value *args        ;  /* arguments if function      */
     struct   symbol *next       ;  /* crosslink to next symbol   */
     struct   symbol *localof    ;  /* local variable of which function */
-    struct   initList *ival       ;  /* ptr to initializer if any  */
+    struct   initList *ival     ;  /* ptr to initializer if any  */
     struct   bitVect *defs      ;  /* bit vector for definitions */
     struct   bitVect *uses      ;  /* bit vector for uses        */        
     struct   bitVect *regsUsed  ;  /* for functions registers used */
@@ -267,6 +280,8 @@ typedef struct 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_NONBANKED(x) x->select.s.nonbanked
+#define SPEC_BANKED(x) x->select.s.banked
 
 /* type check macros */
 #define IS_DECL(x)   ( x && x->class == DECLARATOR     )
@@ -311,8 +326,11 @@ typedef struct 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_ISR(x)              (IS_SPEC(x)  && SPEC_INTRTN(x))
+#define IS_ISR(x)      (IS_SPEC(x)  && SPEC_INTRTN(x))
 #define IS_REGPARM(x)   (IS_SPEC(x) && SPEC_REGPARM(x))
+#define IS_NONBANKED(x) (IS_SPEC(x) && SPEC_NONBANKED(x))
+#define IS_BANKED(x)   (IS_SPEC(x) && SPEC_BANKED(x))
+#define IS_BANKEDCALL(x) (IS_SPEC(x) && !SPEC_NONBANKED(x) && !SPEC_STAT(x) && (options.model == MODEL_LARGE || options.model == MODEL_MEDIUM || SPEC_BANKED(x)))
 
 /* forward declaration for the global vars */
 extern bucket *SymbolTab[] ;
@@ -334,71 +352,76 @@ extern symbol *__fsgteq;
 /* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
 extern symbol *__muldiv[3][3][2];
 /* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */
-extern link *__multypes[3][2];
+extern sym_link *__multypes[3][2];
 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
 extern symbol *__conv[2][3][2];
 
 #define CHARTYPE       __multypes[0][0]
-#define INTTYPE                __multypes[1][0]
 #define UCHARTYPE      __multypes[0][1]
+#define INTTYPE                __multypes[1][0]
+#define UINTTYPE       __multypes[1][1]
+#define LONGTYPE       __multypes[2][0]
+#define ULONGTYPE      __multypes[2][1]
+
 
-extern link *floatType;
+extern sym_link *floatType;
 
 #include "SDCCval.h"
 
 /* forward definitions for the symbol table related functions */
 void       initSymt           (                                );
 symbol      *newSymbol        ( char      *, int               );
-link        *newLink          (                                );
+sym_link    *newLink          (                                );
+sym_link    *newFloatLink     (                                       );
 structdef   *newStruct        ( char      *                    );
-void         addDecl          ( symbol   *, int   , link *     );
-link        *mergeSpec        ( link      *, link *            );
-link        *cloneSpec        ( link  *                        );
-symbol      *reverseSyms     ( symbol     *                   );
-link        *reverseLink      ( link *                         );
+void         addDecl          ( symbol   *, int   , sym_link * );
+sym_link    *mergeSpec        ( sym_link      *, sym_link *    );
+sym_link    *cloneSpec        ( sym_link  *                    );
+symbol      *reverseSyms      ( symbol     *                   );
+sym_link    *reverseLink      ( sym_link *                     );
 symbol     *copySymbol       ( symbol     *                   );
 symbol     *copySymbolChain  ( symbol     *                   );
 void         printSymChain    ( symbol     *, int              );
 void         printStruct      ( structdef *, int               );
 char        *genSymName       ( int                            );
-link        *getSpec          ( link     *                     );
+sym_link    *getSpec          ( sym_link     *                 );
 char        *genSymName       ( int                            );
 int          compStructSize   ( int    ,structdef *            );
-link        *copyLinkChain    ( link    *                      );
+sym_link    *copyLinkChain    ( sym_link    *                  );
 int          checkDecl        ( symbol *                       );
-void         checkBasic       ( link   *, link  *              );
-value       *checkPointerIval ( link   *, value *              );
+void         checkBasic       ( sym_link   *, sym_link  *      );
+value       *checkPointerIval ( sym_link   *, value *          );
 value       *checkStructIval  ( symbol *, value *              );
-value       *checkArrayIval   ( link   *, value *              );
-value       *checkIval        ( link   *, value *              );
-unsigned int getSize         ( link   *                       );
-unsigned int bitsForType      ( link   *                       );
-link        *newIntLink       (                                );
-link        *newCharLink      (                                );
-link        *newLongLink      (                                );
-int          checkType        ( link   *, link  *              );
+value       *checkArrayIval   ( sym_link   *, value *          );
+value       *checkIval        ( sym_link   *, value *          );
+unsigned int getSize         ( sym_link   *                   );
+unsigned int bitsForType      ( sym_link   *                   );
+sym_link    *newIntLink       (                                );
+sym_link    *newCharLink      (                                );
+sym_link    *newLongLink      (                                );
+int          checkType        ( sym_link   *, sym_link  *      );
 int          checkFunction    ( symbol *                       );
 void         cleanUpLevel     ( bucket **,int                  );
 void         cleanUpBlock     ( bucket **,int                  );
-int          funcInChain      ( link   *                       );
+int          funcInChain      ( sym_link   *                   );
 void         addSymChain      ( symbol *                       );
-link        *structElemType   ( link   *, value * , value **   );
+sym_link    *structElemType   ( sym_link *, value * , value ** );
 symbol      *getStructElement ( structdef *, symbol *) ;
-link        *computeType      ( link *, link *);
+sym_link    *computeType      ( sym_link *, sym_link *);
 void         processFuncArgs  (symbol *,int);
 int          isSymbolEqual    (symbol *, symbol *);
 int          powof2           (unsigned long );
-void         printTypeChain   (link *,FILE *);
+void         printTypeChain   (sym_link *,FILE *);
 void         initCSupport     ();
-void         pointerTypes     (link *, link * );
-void         cdbTypeInfo      (link *,FILE *);
+void         pointerTypes     (sym_link *, sym_link * );
+void         cdbTypeInfo      (sym_link *,FILE *);
 void         cdbSymbol        (symbol *,FILE *,int,int);
 void         cdbStructBlock   (int ,FILE *);
 void          initHashT            (                              );
 bucket       *newBucket            (                              );
 void          addSym               ( bucket ** , void   *, char  *, int, int);
 void          deleteSym            ( bucket ** , void   *, char  *);
-void         *findSym              ( bucket ** , void   *, char  *);
+void         *findSym              ( bucket ** , void   *, const char  *);
 void          *findSymWithLevel     ( bucket ** , struct symbol *  );
 void          *findSymWithBlock     ( bucket ** , struct symbol *,int   );
 #include "SDCCmem.h"