From 359e119a6ba3cff60ba1fdc2e2d662a51dac9134 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 31 Jul 2011 12:25:02 +0000 Subject: [PATCH] Write scope information to the object file. git-svn-id: svn://svn.cc65.org/cc65/trunk@5091 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/segrange.c | 51 ++++++++++++++++++++++++++++++++++---- src/ca65/segrange.h | 13 ++++++---- src/ca65/symtab.c | 60 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 109 insertions(+), 15 deletions(-) diff --git a/src/ca65/segrange.c b/src/ca65/segrange.c index 2e71bd10c..e51c621f4 100644 --- a/src/ca65/segrange.c +++ b/src/ca65/segrange.c @@ -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); + } + } +} + + + + diff --git a/src/ca65/segrange.h b/src/ca65/segrange.h index 0ee13dee9..369207c0a 100644 --- a/src/ca65/segrange.h +++ b/src/ca65/segrange.h @@ -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); - + diff --git a/src/ca65/symtab.c b/src/ca65/symtab.c index 356f7386d..8ba04c1f7 100644 --- a/src/ca65/symtab.c +++ b/src/ca65/symtab.c @@ -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 (); -- 2.39.5