mirror of
https://github.com/cc65/cc65.git
synced 2025-01-13 09:31:53 +00:00
Write scope information to the object file.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5091 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
9c55586569
commit
359e119a6b
@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2003 Ullrich von Bassewitz */
|
/* (C) 2003-2011, Ullrich von Bassewitz */
|
||||||
/* Römerstraße 52 */
|
/* Roemerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
@ -37,6 +37,7 @@
|
|||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
/* ca65 */
|
/* ca65 */
|
||||||
|
#include "objfile.h"
|
||||||
#include "segment.h"
|
#include "segment.h"
|
||||||
#include "segrange.h"
|
#include "segrange.h"
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ void AddSegRanges (Collection* Ranges)
|
|||||||
void CloseSegRanges (Collection* Ranges)
|
void CloseSegRanges (Collection* Ranges)
|
||||||
/* Close all open segment ranges by setting PC to the current PC for the
|
/* Close all open segment ranges by setting PC to the current PC for the
|
||||||
* segment.
|
* segment.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
unsigned I;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2003 Ullrich von Bassewitz */
|
/* (C) 2003-2011, Ullrich von Bassewitz */
|
||||||
/* Römerstraße 52 */
|
/* Roemerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
@ -92,6 +92,9 @@ void CloseSegRanges (Collection* Ranges);
|
|||||||
* segment.
|
* segment.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void WriteSegRanges (const Collection* Ranges);
|
||||||
|
/* Write a list of segment ranges to the output file */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End of segrange.h */
|
/* End of segrange.h */
|
||||||
@ -100,4 +103,4 @@ void CloseSegRanges (Collection* Ranges);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
SymTable* CurrentScope = 0; /* Pointer to current symbol table */
|
SymTable* CurrentScope = 0; /* Pointer to current symbol table */
|
||||||
SymTable* RootScope = 0; /* Root symbol table */
|
SymTable* RootScope = 0; /* Root symbol table */
|
||||||
static SymTable* LastScope = 0; /* Pointer to last scope in list */
|
static SymTable* LastScope = 0; /* Pointer to last scope in list */
|
||||||
|
static unsigned ScopeCount = 0; /* Number of scopes */
|
||||||
|
|
||||||
/* Symbol table variables */
|
/* Symbol table variables */
|
||||||
static unsigned ImportCount = 0; /* Counter for import symbols */
|
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
|
/* 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;
|
S->Next = LastScope;
|
||||||
if (RootScope == 0) {
|
if (RootScope == 0) {
|
||||||
@ -137,6 +138,7 @@ static SymTable* NewSymTable (SymTable* Parent, const StrBuf* Name)
|
|||||||
S->Id = LastScope->Id + 1;
|
S->Id = LastScope->Id + 1;
|
||||||
}
|
}
|
||||||
LastScope = S;
|
LastScope = S;
|
||||||
|
++ScopeCount;
|
||||||
|
|
||||||
/* Insert the symbol table into the child tree of the parent */
|
/* Insert the symbol table into the child tree of the parent */
|
||||||
if (Parent) {
|
if (Parent) {
|
||||||
@ -161,7 +163,7 @@ static SymTable* NewSymTable (SymTable* Parent, const StrBuf* Name)
|
|||||||
} else {
|
} else {
|
||||||
T->Right = S;
|
T->Right = S;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Duplicate scope name */
|
/* Duplicate scope name */
|
||||||
Internal ("Duplicate scope name: `%m%p'", Name);
|
Internal ("Duplicate scope name: `%m%p'", Name);
|
||||||
@ -245,7 +247,7 @@ void SymLeaveLevel (void)
|
|||||||
const SegRange* R = CollAtUnchecked (&CurrentScope->SegRanges, 0);
|
const SegRange* R = CollAtUnchecked (&CurrentScope->SegRanges, 0);
|
||||||
unsigned long Size = GetSegRangeSize (R);
|
unsigned long Size = GetSegRangeSize (R);
|
||||||
DefSizeOfScope (CurrentScope, Size);
|
DefSizeOfScope (CurrentScope, Size);
|
||||||
if (CurrentScope->OwnerSym) {
|
if (CurrentScope->OwnerSym) {
|
||||||
DefSizeOfSymbol (CurrentScope->OwnerSym, Size);
|
DefSizeOfSymbol (CurrentScope->OwnerSym, Size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -889,8 +891,56 @@ void WriteScopes (void)
|
|||||||
/* Tell the object file module that we're about to start the scopes */
|
/* Tell the object file module that we're about to start the scopes */
|
||||||
ObjStartScopes ();
|
ObjStartScopes ();
|
||||||
|
|
||||||
/* No debug info requested */
|
/* We will write scopes only if debug symbols are requested */
|
||||||
ObjWriteVar (0);
|
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 */
|
/* Done writing the scopes */
|
||||||
ObjEndScopes ();
|
ObjEndScopes ();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user