]> git.sur5r.net Git - cc65/commitdiff
Write scope information to the object file.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 31 Jul 2011 12:25:02 +0000 (12:25 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 31 Jul 2011 12:25:02 +0000 (12:25 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5091 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/ca65/segrange.c
src/ca65/segrange.h
src/ca65/symtab.c

index 2e71bd10c60bc43af53d2c808fda0f063ac0b8dc..e51c621f4b429fdcc069ed61203d7a47edfd2adf 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2003      Ullrich von Bassewitz                                       */
-/*               Römerstraße 52                                              */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2003-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -37,6 +37,7 @@
 #include "xmalloc.h"
 
 /* ca65 */
+#include "objfile.h"
 #include "segment.h"
 #include "segrange.h"
 
@@ -94,7 +95,7 @@ void AddSegRanges (Collection* Ranges)
 void CloseSegRanges (Collection* Ranges)
 /* Close all open segment ranges by setting PC to the current PC for the
  * segment.
- */                                     
+ */
 {
     unsigned I;
 
@@ -111,3 +112,43 @@ void CloseSegRanges (Collection* Ranges)
 
 
 
+void WriteSegRanges (const Collection* Ranges)
+/* Write a list of segment ranges to the output file */
+{
+    unsigned I;
+    unsigned Count;
+
+    /* Determine how many of the segments contain actual data */
+    Count = 0;
+    for (I = 0; I < CollCount (Ranges); ++I) {
+
+        /* Get next range */
+        const SegRange* R = CollConstAt (Ranges, I);
+
+        /* Is this segment range empty? */
+        if (R->Start != R->End) {
+            ++Count;
+        }
+    }
+
+    /* Write the number of ranges with data */
+    ObjWriteVar (Count);
+
+    /* Write the ranges */
+    for (I = 0; I < CollCount (Ranges); ++I) {
+
+        /* Get next range */
+        const SegRange* R = CollConstAt (Ranges, I);
+
+        /* Write data for non empty ranges */
+        if (R->Start != R->End) {
+            ObjWriteVar (R->Seg->Num);
+            ObjWriteVar (R->Start);
+            ObjWriteVar (R->End);
+        }
+    }
+}
+
+
+
+
index 0ee13dee99bddabf91171cd9210e65634403c1a5..369207c0ade10b7fd577e4281208aa7a424c9b1b 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2003      Ullrich von Bassewitz                                       */
-/*               Römerstraße 52                                              */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2003-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -92,6 +92,9 @@ void CloseSegRanges (Collection* Ranges);
  * segment.
  */
 
+void WriteSegRanges (const Collection* Ranges);
+/* Write a list of segment ranges to the output file */
+
 
 
 /* End of segrange.h */
@@ -100,4 +103,4 @@ void CloseSegRanges (Collection* Ranges);
 
 
 
-                         
+
index 356f7386d45ad3fff7ecb252230905d548dad223..8ba04c1f75a0a9478b8b800ff762314365f55d9c 100644 (file)
@@ -73,6 +73,7 @@
 SymTable*                  CurrentScope = 0;   /* Pointer to current symbol table */
 SymTable*          RootScope    = 0;   /* Root symbol table */
 static SymTable*    LastScope    = 0;   /* Pointer to last scope in list */
+static unsigned     ScopeCount   = 0;   /* Number of scopes */
 
 /* Symbol table variables */
 static unsigned     ImportCount = 0;    /* Counter for import symbols */
@@ -127,7 +128,7 @@ static SymTable* NewSymTable (SymTable* Parent, const StrBuf* Name)
     }
 
     /* Insert the symbol table into the list of all symbol tables and maintain
-     * a unqiue id for each scope.
+     * a unqiue id for each scope. Count the number of scopes.
      */
     S->Next = LastScope;
     if (RootScope == 0) {
@@ -137,6 +138,7 @@ static SymTable* NewSymTable (SymTable* Parent, const StrBuf* Name)
         S->Id = LastScope->Id + 1;
     }
     LastScope = S;
+    ++ScopeCount;
 
     /* Insert the symbol table into the child tree of the parent */
     if (Parent) {
@@ -161,7 +163,7 @@ static SymTable* NewSymTable (SymTable* Parent, const StrBuf* Name)
                     } else {
                         T->Right = S;
                         break;
-                    }  
+                    }
                 } else {
                     /* Duplicate scope name */
                     Internal ("Duplicate scope name: `%m%p'", Name);
@@ -245,7 +247,7 @@ void SymLeaveLevel (void)
         const SegRange* R = CollAtUnchecked (&CurrentScope->SegRanges, 0);
         unsigned long Size = GetSegRangeSize (R);
         DefSizeOfScope (CurrentScope, Size);
-        if (CurrentScope->OwnerSym) {              
+        if (CurrentScope->OwnerSym) {
             DefSizeOfSymbol (CurrentScope->OwnerSym, Size);
         }
     }
@@ -889,8 +891,56 @@ void WriteScopes (void)
     /* Tell the object file module that we're about to start the scopes */
     ObjStartScopes ();
 
-    /* No debug info requested */
-    ObjWriteVar (0);
+    /* We will write scopes only if debug symbols are requested */
+    if (DbgSyms) {
+
+        /* Get head of list */
+        const SymTable* S = LastScope;
+
+        /* Write the scope count to the file */
+        ObjWriteVar (ScopeCount);
+
+        /* Walk through all scopes and write them to the file */
+        while (S) {
+
+            /* Type must be defined */
+            CHECK (S->Type != ST_UNDEF);
+
+            /* Id of scope */
+            ObjWriteVar (S->Id);
+
+            /* Id of parent scope */
+            if (S->Parent) {
+                ObjWriteVar (S->Parent->Id);
+            } else {
+                ObjWriteVar (0);
+            }
+
+            /* Lexical level */
+            ObjWriteVar (S->Level);
+
+            /* Scope flags (currently always zero) */
+            ObjWriteVar (0);
+
+            /* Type of scope */
+            ObjWriteVar (S->Type);
+
+            /* Name of the scope */
+            ObjWriteVar (S->Name);
+
+            /* Segment ranges for this scope */
+            WriteSegRanges (&S->SegRanges);
+
+            /* Next scope */
+            S = S->Next;
+        }
+
+    } else {
+
+        /* No debug info requested */
+        ObjWriteVar (0);
+
+    }
 
     /* Done writing the scopes */
     ObjEndScopes ();