1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-30 16:29:58 +00:00

More work on scope suport.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5119 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-04 18:47:01 +00:00
parent d1efe1af90
commit 3593eb2869
4 changed files with 25 additions and 41 deletions

View File

@ -85,7 +85,7 @@ static DbgSym* NewDbgSym (unsigned char Type, unsigned char AddrSize, ObjData* O
D->LineInfos = EmptyCollection; D->LineInfos = EmptyCollection;
D->Expr = 0; D->Expr = 0;
D->Size = 0; D->Size = 0;
D->Parent.Id = ~0UL; D->OwnerId = ~0U;
D->Name = 0; D->Name = 0;
D->Type = Type; D->Type = Type;
D->AddrSize = AddrSize; D->AddrSize = AddrSize;
@ -153,7 +153,7 @@ DbgSym* ReadDbgSym (FILE* F, ObjData* O)
DbgSym* D = NewDbgSym (Type, AddrSize, O); DbgSym* D = NewDbgSym (Type, AddrSize, O);
/* Read the id of the owner scope/symbol */ /* Read the id of the owner scope/symbol */
D->Parent.Id = ReadVar (F); D->OwnerId = ReadVar (F);
/* Read and assign the name */ /* Read and assign the name */
D->Name = MakeGlobalStringId (O, ReadVar (F)); D->Name = MakeGlobalStringId (O, ReadVar (F));
@ -210,6 +210,7 @@ void PrintDbgSyms (FILE* F)
{ {
unsigned I, J; unsigned I, J;
unsigned BaseId = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) { for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get the object file */ /* Get the object file */
@ -229,7 +230,8 @@ void PrintDbgSyms (FILE* F)
/* Emit the base data for the entry */ /* Emit the base data for the entry */
fprintf (F, 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), GetString (S->Name),
Val, Val,
AddrSizeToStr (S->AddrSize), AddrSizeToStr (S->AddrSize),
@ -248,9 +250,21 @@ void PrintDbgSyms (FILE* F)
fprintf (F, ",segment=%u", D.Seg->Id); 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 */ /* Terminate the output line */
fputc ('\n', F); fputc ('\n', F);
} }
/* Increment base id */
BaseId += CollCount (&O->DbgSyms);
} }
} }

View File

@ -67,11 +67,7 @@ struct DbgSym {
Collection LineInfos; /* Line infos of definition */ Collection LineInfos; /* Line infos of definition */
ExprNode* Expr; /* Expression (0 if not def'd) */ ExprNode* Expr; /* Expression (0 if not def'd) */
unsigned long Size; /* Symbol size if any */ unsigned long Size; /* Symbol size if any */
union { unsigned OwnerId; /* Id of parent/owner */
unsigned long Id; /* Id of parent while not resolved */
struct Scope* Scope; /* Parent scope */
struct DbgSym* Sym; /* Parent symbol for cheap locals */
} Parent;
unsigned Name; /* Name */ unsigned Name; /* Name */
unsigned char Type; /* Type of symbol */ unsigned char Type; /* Type of symbol */
unsigned char AddrSize; /* Address size of symbol */ unsigned char AddrSize; /* Address size of symbol */

View File

@ -76,7 +76,7 @@ Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id)
Scope* S = NewScope (Obj, Id); Scope* S = NewScope (Obj, Id);
/* Read the data from file */ /* Read the data from file */
S->Parent.Id = ReadVar (F); S->ParentId = ReadVar (F);
S->LexicalLevel = ReadVar (F); S->LexicalLevel = ReadVar (F);
S->Flags = ReadVar (F); S->Flags = ReadVar (F);
S->Type = 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) void PrintDbgScopes (FILE* F)
/* Output the scopes to a debug info file */ /* Output the scopes to a debug info file */
{ {
@ -144,8 +121,8 @@ void PrintDbgScopes (FILE* F)
fprintf (F, ",size=%lu", S->Size); fprintf (F, ",size=%lu", S->Size);
} }
/* Print parent if available */ /* Print parent if available */
if (S->Parent.Scope) { if (S->Id != S->ParentId) {
fprintf (F, ",parent=%u", BaseId + S->Parent.Scope->Id); fprintf (F, ",parent=%u", BaseId + S->ParentId);
} }
/* Terminate the output line */ /* Terminate the output line */

View File

@ -60,10 +60,7 @@ typedef struct Scope Scope;
struct Scope { struct Scope {
unsigned Id; /* Id of scope */ unsigned Id; /* Id of scope */
ObjData* Obj; /* Object file that exports the name */ ObjData* Obj; /* Object file that exports the name */
union { unsigned ParentId; /* Id of parent scope */
unsigned Id; /* Id of parent scope */
Scope* Scope; /* Pointer to parent scope */
} Parent;
unsigned LexicalLevel; /* Lexical level */ unsigned LexicalLevel; /* Lexical level */
unsigned Flags; unsigned Flags;
unsigned Type; /* Type of scope */ unsigned Type; /* Type of scope */
@ -83,8 +80,8 @@ struct Scope {
Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id); Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id);
/* Read a scope from a file, insert and return it */ /* Read a scope from a file, insert and return it */
void ResolveScopes (ObjData* Obj); void PrintDbgScopes (FILE* F);
/* Resolve a scope list. */ /* Output the scopes to a debug info file */
@ -93,4 +90,4 @@ void ResolveScopes (ObjData* Obj);
#endif #endif