]> git.sur5r.net Git - cc65/blobdiff - src/ca65/symtab.c
The longbranch macros did not work with numeric addresses
[cc65] / src / ca65 / symtab.c
index 76055f92715df2b02148bc568311290eca3735a1..c54445faec0de0fecbb96804284abb55891ca74a 100644 (file)
@@ -66,6 +66,7 @@
 #define SF_GLOBAL      0x0010          /* Global symbol */
 #define SF_ZP                  0x0020          /* Declared as zeropage symbol */
 #define SF_ABS         0x0040          /* Declared as absolute symbol */
+#define SF_LABEL        0x0080          /* Used as a label */
 #define SF_INDEXED     0x0800          /* Index is valid */
 #define SF_CONST       0x1000          /* The symbol has a constant value */
 #define SF_MULTDEF             0x2000          /* Multiply defined symbol */
@@ -399,7 +400,7 @@ void SymLeaveLevel (void)
 
 
 
-void SymDef (const char* Name, ExprNode* Expr, int ZP)
+void SymDef (const char* Name, ExprNode* Expr, int ZP, int Label)
 /* Define a new symbol */
 {
     /* Do we have such a symbol? */
@@ -430,6 +431,9 @@ void SymDef (const char* Name, ExprNode* Expr, int ZP)
     if (ZP) {
        S->Flags |= SF_ZP;
     }
+    if (Label) {
+       S->Flags |= SF_LABEL;
+    }
 
     /* If the symbol is a ZP symbol, check if the value is in correct range */
     if (S->Flags & SF_ZP) {
@@ -588,7 +592,11 @@ void SymConDes (const char* Name, unsigned Type, unsigned Prio)
     SymEntry* S;
 
     /* Check the parameters */
+#if (CD_TYPE_MIN != 0)
     CHECK (Type >= CD_TYPE_MIN && Type <= CD_TYPE_MAX);
+#else
+    CHECK (Type <= CD_TYPE_MAX);
+#endif
     CHECK (Prio >= CD_PRIO_MIN && Prio <= CD_PRIO_MAX);
 
     /* Don't accept local symbols */
@@ -635,7 +643,7 @@ int SymIsDef (const char* Name)
 /* Return true if the given symbol is already defined */
 {
     SymEntry* S = SymFindAny (SymTab, Name);
-    return S != 0 && (S->Flags & (SF_DEFINED | SF_IMPORT)) != 0;
+    return S != 0 && (S->Flags & SF_DEFINED) != 0;
 }
 
 
@@ -1015,13 +1023,14 @@ void SymDump (FILE* F)
     while (S) {
        /* Ignore trampoline symbols */
        if ((S->Flags & SF_TRAMPOLINE) != 0) {
-           printf ("%-24s %s %s %s %s %s\n",
-                   S->Name,
-                   (S->Flags & SF_DEFINED)? "DEF" : "---",
-                   (S->Flags & SF_REFERENCED)? "REF" : "---",
-                   (S->Flags & SF_IMPORT)? "IMP" : "---",
-                   (S->Flags & SF_EXPORT)? "EXP" : "---",
-                   (S->Flags & SF_ZP)? "ZP" : "--");
+           fprintf (F,
+                    "%-24s %s %s %s %s %s\n",
+                    S->Name,
+                    (S->Flags & SF_DEFINED)? "DEF" : "---",
+                    (S->Flags & SF_REFERENCED)? "REF" : "---",
+                    (S->Flags & SF_IMPORT)? "IMP" : "---",
+                    (S->Flags & SF_EXPORT)? "EXP" : "---",
+                    (S->Flags & SF_ZP)? "ZP" : "--");
        }
        /* Next symbol */
        S = S->List;
@@ -1062,6 +1071,26 @@ void WriteImports (void)
 
 
 
+static unsigned char GetExprMask (SymEntry* S)
+/* Return the expression bits for the given symbol table entry */
+{
+    unsigned char ExprMask;
+
+    /* Check if the symbol is const */
+    ExprMask = (SymIsConst (S))? EXP_CONST : EXP_EXPR;
+
+    /* Add zeropage/abs bits */
+    ExprMask |= (S->Flags & SF_ZP)? EXP_ZP : EXP_ABS;
+
+    /* Add the label/equate bits */
+    ExprMask |= (S->Flags & SF_LABEL)? EXP_LABEL : EXP_EQUATE;
+
+    /* Return the mask */
+    return ExprMask;
+}
+
+
+
 void WriteExports (void)
 /* Write the exports list to the object file */
 {
@@ -1083,11 +1112,8 @@ void WriteExports (void)
            /* Finalize an associated expression if we have one */
            SymFinalize (S);
 
-           /* Check if the symbol is const */
-           ExprMask = (SymIsConst (S))? EXP_CONST : EXP_EXPR;
-
-           /* Add zeropage/abs bits */
-           ExprMask |= (S->Flags & SF_ZP)? EXP_ZP : EXP_ABS;
+           /* Get the expression bits */
+           ExprMask = GetExprMask (S);
 
            /* Count the number of ConDes types */
            for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
@@ -1104,7 +1130,7 @@ void WriteExports (void)
                for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
                    unsigned char Prio = S->ConDesPrio[Type];
                    if (Prio != CD_PRIO_NONE) {
-                       ObjWrite8 (CD_BUILD (Type, Prio));
+                       ObjWrite8 (CD_BUILD (Type, Prio));
                    }
                }
            }
@@ -1167,11 +1193,8 @@ void WriteDbgSyms (void)
                /* Finalize an associated expression if we have one */
                SymFinalize (S);
 
-               /* Check if the symbol is const */
-               ExprMask = (SymIsConst (S))? EXP_CONST : EXP_EXPR;
-
-               /* Add zeropage/abs bits */
-               ExprMask |= (S->Flags & SF_ZP)? EXP_ZP : EXP_ABS;
+               /* Get the expression bits */
+                       ExprMask = GetExprMask (S);
 
                /* Write the type */
                ObjWrite8 (ExprMask);