From 3593eb2869acd980f4a6ed7a68a16a3f2205a641 Mon Sep 17 00:00:00 2001 From: uz Date: Thu, 4 Aug 2011 18:47:01 +0000 Subject: [PATCH] More work on scope suport. git-svn-id: svn://svn.cc65.org/cc65/trunk@5119 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ld65/dbgsyms.c | 20 +++++++++++++++++--- src/ld65/dbgsyms.h | 6 +----- src/ld65/scopes.c | 29 +++-------------------------- src/ld65/scopes.h | 11 ++++------- 4 files changed, 25 insertions(+), 41 deletions(-) diff --git a/src/ld65/dbgsyms.c b/src/ld65/dbgsyms.c index cf68714c8..de17a61d3 100644 --- a/src/ld65/dbgsyms.c +++ b/src/ld65/dbgsyms.c @@ -85,7 +85,7 @@ static DbgSym* NewDbgSym (unsigned char Type, unsigned char AddrSize, ObjData* O D->LineInfos = EmptyCollection; D->Expr = 0; D->Size = 0; - D->Parent.Id = ~0UL; + D->OwnerId = ~0U; D->Name = 0; D->Type = Type; D->AddrSize = AddrSize; @@ -153,7 +153,7 @@ DbgSym* ReadDbgSym (FILE* F, ObjData* O) DbgSym* D = NewDbgSym (Type, AddrSize, O); /* Read the id of the owner scope/symbol */ - D->Parent.Id = ReadVar (F); + D->OwnerId = ReadVar (F); /* Read and assign the name */ D->Name = MakeGlobalStringId (O, ReadVar (F)); @@ -210,6 +210,7 @@ void PrintDbgSyms (FILE* F) { unsigned I, J; + unsigned BaseId = 0; for (I = 0; I < CollCount (&ObjDataList); ++I) { /* Get the object file */ @@ -229,7 +230,8 @@ void PrintDbgSyms (FILE* F) /* Emit the base data for the entry */ fprintf (F, - "sym\tname=\"%s\",value=0x%lX,addrsize=%s,type=%s", + "sym\tid=%u,name=\"%s\",value=0x%lX,addrsize=%s,type=%s", + BaseId + J, GetString (S->Name), Val, AddrSizeToStr (S->AddrSize), @@ -248,9 +250,21 @@ void PrintDbgSyms (FILE* F) fprintf (F, ",segment=%u", D.Seg->Id); } + /* For cheap local symbols, add the owner symbol, for others, + * add the owner scope. + */ + if (SYM_IS_STD (S->Type)) { + fprintf (F, ",scope=%u", S->OwnerId); + } else { + fprintf (F, ",parent=%u", S->OwnerId); + } + /* Terminate the output line */ fputc ('\n', F); } + + /* Increment base id */ + BaseId += CollCount (&O->DbgSyms); } } diff --git a/src/ld65/dbgsyms.h b/src/ld65/dbgsyms.h index 18027e6ff..ad84fd9be 100644 --- a/src/ld65/dbgsyms.h +++ b/src/ld65/dbgsyms.h @@ -67,11 +67,7 @@ struct DbgSym { Collection LineInfos; /* Line infos of definition */ ExprNode* Expr; /* Expression (0 if not def'd) */ unsigned long Size; /* Symbol size if any */ - union { - unsigned long Id; /* Id of parent while not resolved */ - struct Scope* Scope; /* Parent scope */ - struct DbgSym* Sym; /* Parent symbol for cheap locals */ - } Parent; + unsigned OwnerId; /* Id of parent/owner */ unsigned Name; /* Name */ unsigned char Type; /* Type of symbol */ unsigned char AddrSize; /* Address size of symbol */ diff --git a/src/ld65/scopes.c b/src/ld65/scopes.c index 0bf3f881b..93e3d6b0d 100644 --- a/src/ld65/scopes.c +++ b/src/ld65/scopes.c @@ -76,7 +76,7 @@ Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id) Scope* S = NewScope (Obj, Id); /* Read the data from file */ - S->Parent.Id = ReadVar (F); + S->ParentId = ReadVar (F); S->LexicalLevel = ReadVar (F); S->Flags = ReadVar (F); S->Type = ReadVar (F); @@ -94,29 +94,6 @@ Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id) -void ResolveScopes (ObjData* Obj) -/* Resolve a scope list. */ -{ - unsigned I; - - /* Walk over the list and resolve the parent ids. */ - for (I = 0; I < CollCount (&Obj->Scopes); ++I) { - - /* Get the scope */ - Scope* S = CollAtUnchecked (&Obj->Scopes, I); - - /* Resolve the parent id. The root scope doesn't have a parent */ - if (S->Id == 0) { - /* Root scope */ - S->Parent.Scope = 0; - } else { - S->Parent.Scope = GetObjScope (Obj, S->Parent.Id); - } - } -} - - - void PrintDbgScopes (FILE* F) /* Output the scopes to a debug info file */ { @@ -144,8 +121,8 @@ void PrintDbgScopes (FILE* F) fprintf (F, ",size=%lu", S->Size); } /* Print parent if available */ - if (S->Parent.Scope) { - fprintf (F, ",parent=%u", BaseId + S->Parent.Scope->Id); + if (S->Id != S->ParentId) { + fprintf (F, ",parent=%u", BaseId + S->ParentId); } /* Terminate the output line */ diff --git a/src/ld65/scopes.h b/src/ld65/scopes.h index 82f1da00e..1af33fa4c 100644 --- a/src/ld65/scopes.h +++ b/src/ld65/scopes.h @@ -60,10 +60,7 @@ typedef struct Scope Scope; struct Scope { unsigned Id; /* Id of scope */ ObjData* Obj; /* Object file that exports the name */ - union { - unsigned Id; /* Id of parent scope */ - Scope* Scope; /* Pointer to parent scope */ - } Parent; + unsigned ParentId; /* Id of parent scope */ unsigned LexicalLevel; /* Lexical level */ unsigned Flags; unsigned Type; /* Type of scope */ @@ -83,8 +80,8 @@ struct Scope { Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id); /* Read a scope from a file, insert and return it */ -void ResolveScopes (ObjData* Obj); -/* Resolve a scope list. */ +void PrintDbgScopes (FILE* F); +/* Output the scopes to a debug info file */ @@ -93,4 +90,4 @@ void ResolveScopes (ObjData* Obj); #endif - + -- 2.39.5