/* */
/* */
/* */
-/* (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 */
#include "xmalloc.h"
/* ca65 */
+#include "objfile.h"
#include "segment.h"
#include "segrange.h"
void CloseSegRanges (Collection* Ranges)
/* Close all open segment ranges by setting PC to the current PC for the
* segment.
- */
+ */
{
unsigned I;
+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);
+ }
+ }
+}
+
+
+
+
/* */
/* */
/* */
-/* (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 */
* segment.
*/
+void WriteSegRanges (const Collection* Ranges);
+/* Write a list of segment ranges to the output file */
+
/* End of segrange.h */
-
+
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 */
}
/* 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) {
S->Id = LastScope->Id + 1;
}
LastScope = S;
+ ++ScopeCount;
/* Insert the symbol table into the child tree of the parent */
if (Parent) {
} else {
T->Right = S;
break;
- }
+ }
} else {
/* Duplicate scope name */
Internal ("Duplicate scope name: `%m%p'", Name);
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);
}
}
/* 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 ();