]> git.sur5r.net Git - cc65/blobdiff - src/ca65/symentry.h
If a debug symbol is an import, write out the import id.
[cc65] / src / ca65 / symentry.h
index f72e3bf17e5200e0c52b34f2f322ec2280990d33..32c11ca5be1dccbd223722cb5c8f00746673b3a5 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2003 Ullrich von Bassewitz                                       */
-/*               Römerstraße 52                                              */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 1998-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -43,6 +43,7 @@
 #include "coll.h"
 #include "filepos.h"
 #include "inline.h"
+#include "strbuf.h"
 
 /* ca65 */
 #include "spool.h"
@@ -64,8 +65,8 @@
 #define SF_GLOBAL      0x0010          /* Global symbol */
 #define SF_LOCAL        0x0020          /* Cheap local symbol */
 #define SF_LABEL        0x0080          /* Used as a label */
-#define SF_FORCED       0x0100          /* Forced import, SF_IMPORT also set */
-#define SF_INDEXED     0x0800          /* Index is valid */
+#define SF_VAR          0x0100          /* Variable symbol */
+#define SF_FORCED       0x0400          /* Forced import, SF_IMPORT also set */
 #define SF_MULTDEF             0x2000          /* Multiply defined symbol */
 #define        SF_DEFINED      0x4000          /* Defined */
 #define SF_REFERENCED  0x8000          /* Referenced */
 /* Structure of a symbol table entry */
 typedef struct SymEntry SymEntry;
 struct SymEntry {
-    SymEntry*                      Left;       /* Lexically smaller entry */
-    SymEntry*                      Right;      /* Lexically larger entry */
-    SymEntry*                      List;       /* List of all entries */
-    SymEntry*                      Locals;     /* Root of subtree for local symbols */
-    struct SymTable*       SymTab;     /* Table this symbol is in, 0 for locals */
-    FilePos                        Pos;        /* File position for this symbol */
-    unsigned                Flags;     /* Symbol flags */
-    unsigned               Index;      /* Index of import/export entries */
+    SymEntry*                  Left;           /* Lexically smaller entry */
+    SymEntry*                  Right;          /* Lexically larger entry */
+    SymEntry*                  List;           /* List of all entries */
+    SymEntry*                  Locals;         /* Root of subtree for local symbols */
     union {
-        struct ExprNode*    Expr;              /* Symbol expression */
-       SymEntry*           Sym;        /* Symbol (if trampoline entry) */
-    } V;
-    Collection              ExprRefs;   /* Expressions using this symbol */
-    unsigned char           ExportSize; /* Export address size */
-    unsigned char           AddrSize;   /* Address size of label */
-    unsigned char                  ConDesPrio[CD_TYPE_COUNT];  /* ConDes priorities... */
-                                       /* ...actually value+1 (used as flag) */
-    unsigned                Name;              /* Name index in global string pool */
+        struct SymTable*    Tab;               /* Table this symbol is in */
+        struct SymEntry*    Entry;
+    } Sym;
+    Collection          LineInfos;      /* Line infos for this symbol */
+    FilePos*            GuessedUse[1];  /* File position where symbol
+                                         * address size was guessed, and the
+                                         * smallest possible addressing was NOT
+                                         * used. Currently only for zero page
+                                         * addressing
+                                         */
+    unsigned            Flags;         /* Symbol flags */
+    unsigned            DebugSymId;     /* Debug symbol id */
+    unsigned                   ImportId;       /* Id of import if this is one */
+    struct ExprNode*    Expr;          /* Symbol expression */
+    Collection          ExprRefs;       /* Expressions using this symbol */
+    unsigned char       ExportSize;     /* Export address size */
+    unsigned char       AddrSize;       /* Address size of label */
+    unsigned char              ConDesPrio[CD_TYPE_COUNT];      /* ConDes priorities... */
+                                       /* ...actually value+1 (used as flag) */
+    unsigned            Name;          /* Name index in global string pool */
 };
 
 /* List of all symbol table entries */
@@ -111,10 +119,10 @@ extern SymEntry* SymLast;
 
 
 
-SymEntry* NewSymEntry (const char* Name, unsigned Flags);
+SymEntry* NewSymEntry (const StrBuf* Name, unsigned Flags);
 /* Allocate a symbol table entry, initialize and return it */
 
-int SymSearchTree (SymEntry* T, const char* Name, SymEntry** E);
+int SymSearchTree (SymEntry* T, const StrBuf* Name, SymEntry** E);
 /* Search in the given tree for a name. If we find the symbol, the function
  * will return 0 and put the entry pointer into E. If we did not find the
  * symbol, and the tree is empty, E is set to NULL. If the tree is not empty,
@@ -168,6 +176,23 @@ void SymConDes (SymEntry* Sym, unsigned char AddrSize, unsigned Type, unsigned P
  * mark the symbol as an export. Initializers may never be zero page symbols.
  */
 
+void SymGuessedAddrSize (SymEntry* Sym, unsigned char AddrSize);
+/* Mark the address size of the given symbol as guessed. The address size
+ * passed as argument is the one NOT used, because the actual address size
+ * wasn't known. Example: Zero page addressing was not used because symbol
+ * is undefined, and absolute addressing was available.
+ */
+
+void SymExportFromGlobal (SymEntry* S);
+/* Called at the end of assembly. Converts a global symbol that is defined
+ * into an export.
+ */
+
+void SymImportFromGlobal (SymEntry* S);
+/* Called at the end of assembly. Converts a global symbol that is undefined
+ * into an import.
+ */
+
 #if defined(HAVE_INLINE)
 INLINE int SymIsDef (const SymEntry* S)
 /* Return true if the given symbol is already defined */
@@ -199,7 +224,29 @@ INLINE int SymIsImport (const SymEntry* S)
 #  define SymIsImport(S)  (((S)->Flags & SF_IMPORT) != 0)
 #endif
 
-int SymIsConst (SymEntry* Sym, long* Val);
+#if defined(HAVE_INLINE)
+INLINE int SymIsExport (const SymEntry* S)
+/* Return true if the given symbol is marked as export */
+{
+    /* Check the export flag */
+    return (S->Flags & SF_EXPORT) != 0;
+}
+#else
+#  define SymIsExport(S)  (((S)->Flags & SF_EXPORT) != 0)
+#endif
+
+#if defined(HAVE_INLINE)
+INLINE int SymIsVar (const SymEntry* S)
+/* Return true if the given symbol is marked as variable */
+{
+    /* Check the variable flag */
+    return (S->Flags & SF_VAR) != 0;
+}
+#else
+#  define SymIsVar(S)   (((S)->Flags & SF_VAR) != 0)
+#endif
+
+int SymIsConst (const SymEntry* Sym, long* Val);
 /* Return true if the given symbol has a constant value. If Val is not NULL
  * and the symbol has a constant value, store it's value there.
  */
@@ -212,7 +259,7 @@ INLINE int SymHasExpr (const SymEntry* S)
     return ((S->Flags & (SF_DEFINED|SF_IMPORT)) == SF_DEFINED);
 }
 #else
-#  define SymHasExpr(S)   (((S)->Flags & (SF_DEFINED|SF_IMPORT)) != SF_DEFINED)
+#  define SymHasExpr(S)   (((S)->Flags & (SF_DEFINED|SF_IMPORT)) == SF_DEFINED)
 #endif
 
 #if defined(HAVE_INLINE)
@@ -247,7 +294,7 @@ INLINE int SymHasUserMark (SymEntry* S)
 #else
 #  define SymHasUserMark(S) (((S)->Flags & SF_USER) != 0)
 #endif
-       
+
 struct SymTable* GetSymParentScope (SymEntry* S);
 /* Get the parent scope of the symbol (not the one it is defined in). Return
  * NULL if the symbol is a cheap local, or defined on global level.
@@ -262,13 +309,13 @@ const struct ExprNode* SymResolve (const SymEntry* Sym);
  */
 
 #if defined(HAVE_INLINE)
-INLINE const char* GetSymName (const SymEntry* S)
+INLINE const StrBuf* GetSymName (const SymEntry* S)
 /* Return the name of the symbol */
 {
-    return GetString (S->Name);
+    return GetStrBuf (S->Name);
 }
 #else
-#  define GetSymName(S)   GetString ((S)->Name)
+#  define GetSymName(S)   GetStrBuf ((S)->Name)
 #endif
 
 #if defined(HAVE_INLINE)
@@ -288,18 +335,15 @@ long GetSymVal (SymEntry* Sym);
  * in case the symbol is undefined or not constant.
  */
 
-unsigned GetSymIndex (const SymEntry* Sym);
-/* Return the symbol index for the given symbol */
+unsigned GetSymImportId (const SymEntry* Sym);
+/* Return the import id for the given symbol */
 
-#if defined(HAVE_INLINE)
-INLINE const FilePos* GetSymPos (const SymEntry* S)
-/* Return the position of first occurence in the source for the given symbol */
-{
-    return &S->Pos;
-}
-#else
-#  define GetSymPos(S)   (&(S)->Pos)
-#endif
+unsigned GetSymInfoFlags (const SymEntry* Sym, long* ConstVal);
+/* Return a set of flags used when writing symbol information into a file.
+ * If the SYM_CONST bit is set, ConstVal will contain the constant value
+ * of the symbol. The result does not include the condes count.
+ * See common/symdefs.h for more information.
+ */
 
 
 
@@ -309,3 +353,4 @@ INLINE const FilePos* GetSymPos (const SymEntry* S)
 
 
 
+