]> git.sur5r.net Git - cc65/commitdiff
Maintain some additional information for scopes. Write a dummy scope section
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 17 Aug 2010 16:58:41 +0000 (16:58 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 17 Aug 2010 16:58:41 +0000 (16:58 +0000)
into the object file.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4808 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/ca65/main.c
src/ca65/symentry.c
src/ca65/symentry.h
src/ca65/symtab.c
src/ca65/symtab.h

index eae7c384f1278601cc3cb42d09c1d7661928c7b0..934ad6f3d3ee4ac0a256b6b46f085842677ec7c3 100644 (file)
@@ -798,6 +798,9 @@ static void CreateObjFile (void)
     /* Write the export list */
     WriteExports ();
 
+    /* Write the scopes if requested */
+    WriteScopes ();
+
     /* Write debug symbols if requested */
     WriteDbgSyms ();
 
index 9146aea384ff0f7038f4eb88ab95d9257c6859ea..7bae7e019a43ead8f1697ceea7e7ffd117749afa 100644 (file)
@@ -84,7 +84,7 @@ SymEntry* NewSymEntry (const StrBuf* Name, unsigned Flags)
     S->Left              = 0;
     S->Right             = 0;
     S->Locals            = 0;
-    S->SymTab            = 0;
+    S->Sym.Tab    = 0;
     S->Pos               = CurPos;
     for (I = 0; I < sizeof (S->GuessedUse) / sizeof (S->GuessedUse[0]); ++I) {
         S->GuessedUse[I] = 0;
@@ -620,7 +620,13 @@ SymTable* GetSymParentScope (SymEntry* S)
  * NULL if the symbol is a cheap local, or defined on global level.
  */
 {
-    return (S->SymTab && S->SymTab->Parent)? S->SymTab->Parent : 0;
+    if ((S->Flags & SF_LOCAL) != 0) {
+        /* This is a cheap local symbol */
+        return 0;
+    } else {
+        /* This is a global symbol */
+        return S->Sym.Tab->Parent;
+    }
 }
 
 
index 42b281ed7331ef2932c078af953d4397755f7e96..36ea6aed361c00fc9c6a8ebfc075212f72404ede 100644 (file)
@@ -83,7 +83,10 @@ struct SymEntry {
     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 */
+    union {
+        struct SymTable*    Tab;               /* Table this symbol is in */
+        struct SymEntry*    Entry;
+    } Sym;
     FilePos                    Pos;            /* File position for this symbol */
     FilePos*            GuessedUse[1];  /* File position where symbol
                                          * address size was guessed, and the
@@ -98,7 +101,7 @@ struct SymEntry {
     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) */
+                                       /* ...actually value+1 (used as flag) */
     unsigned            Name;          /* Name index in global string pool */
 };
 
@@ -353,4 +356,4 @@ INLINE const FilePos* GetSymPos (const SymEntry* S)
 
 
 
-                                    
+
index 615e1086a36289216a432b5ee448098096ccb1ce..593b5d52010bd377b10b3232caaa09166c1cb845 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2008 Ullrich von Bassewitz                                       */
-/*               Roemerstrasse 52                                            */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 1998-2010, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 #define SF_DBGINFOVAL  (SF_DEFINED)
 
 /* Symbol tables */
-SymTable*              CurrentScope = 0;       /* Pointer to current symbol table */
-SymTable*      RootScope    = 0;       /* Root symbol table */
+SymTable*                  CurrentScope = 0;   /* Pointer to current symbol table */
+SymTable*          RootScope    = 0;   /* Root symbol table */
+static SymTable*    LastScope    = 0;   /* Pointer to last scope in list */
 
 /* Symbol table variables */
-static unsigned ImportCount = 0;        /* Counter for import symbols */
-static unsigned ExportCount = 0;        /* Counter for export symbols */
+static unsigned     ImportCount = 0;    /* Counter for import symbols */
+static unsigned     ExportCount = 0;    /* Counter for export symbols */
 
 
 
@@ -124,6 +125,18 @@ static SymTable* NewSymTable (SymTable* Parent, const StrBuf* Name)
                S->Table[Slots] = 0;
     }
 
+    /* Insert the symbol table into the list of all symbol tables and maintain
+     * a unqiue id for each scope.
+     */
+    S->Next = LastScope;
+    if (RootScope == 0) {
+        S->Id = 0;
+        RootScope = S;
+    } else {
+        S->Id = LastScope->Id + 1;
+    }
+    LastScope = S;
+
     /* Insert the symbol table into the child tree of the parent */
     if (Parent) {
         SymTable* T = Parent->Childs;
@@ -315,6 +328,7 @@ SymEntry* SymFindLocal (SymEntry* Parent, const StrBuf* Name, int AllocNew)
 
         /* Otherwise create a new entry, insert and return it */
         SymEntry* N = NewSymEntry (Name, SF_LOCAL);
+        N->Sym.Entry = Parent;
         if (S == 0) {
             Parent->Locals = N;
         } else if (Cmp < 0) {
@@ -354,6 +368,7 @@ SymEntry* SymFind (SymTable* Scope, const StrBuf* Name, int AllocNew)
 
         /* Otherwise create a new entry, insert and return it */
         SymEntry* N = NewSymEntry (Name, SF_NONE);
+        N->Sym.Tab = Scope;
         if (S == 0) {
             Scope->Table[Hash] = N;
         } else if (Cmp < 0) {
@@ -361,7 +376,6 @@ SymEntry* SymFind (SymTable* Scope, const StrBuf* Name, int AllocNew)
         } else {
             S->Right = N;
         }
-        N->SymTab = Scope;
         ++Scope->TableEntries;
         return N;
 
@@ -836,7 +850,7 @@ void WriteScopes (void)
     /* Tell the object file module that we're about to start the scopes */
     ObjStartScopes ();
 
-    /* For now ...*/
+    /* No debug info requested */
     ObjWriteVar (0);
 
     /* Done writing the scopes */
index 9b45cfd49bab7ec0873c323783476ed49e97e4d4..9761da025af069522ff4a945a2e2e37d41e01791 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2008 Ullrich von Bassewitz                                       */
-/*               Roemerstrasse 52                                            */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 1998-2010, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -73,12 +73,14 @@ enum {
 
 /* A symbol table */
 typedef struct SymTable SymTable;
-struct SymTable {
+struct SymTable {                                     
+    SymTable*           Next;           /* Pointer to next table in list */
     SymTable*           Left;           /* Pointer to smaller entry */
     SymTable*           Right;          /* Pointer to greater entry */
     SymTable*                  Parent;         /* Link to enclosing scope if any */
     SymTable*           Childs;         /* Pointer to child scopes */
     Collection          SegRanges;      /* Segment ranges for this scope */
+    unsigned            Id;             /* Scope id */
     unsigned short      Flags;          /* Symbol table flags */
     unsigned char      AddrSize;       /* Address size */
     unsigned char       Type;           /* Type of the scope */
@@ -162,6 +164,9 @@ void WriteExports (void);
 void WriteDbgSyms (void);
 /* Write a list of all symbols to the object file */
 
+void WriteScopes (void);
+/* Write the scope table to the object file */
+
 
 
 /* End of symtab.h */