From 51e918cdfec5d59e52ea987c004b4843012f690e Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 15 Aug 2011 17:36:38 +0000 Subject: [PATCH] Track the main scope of modules. git-svn-id: svn://svn.cc65.org/cc65/trunk@5174 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/dbginfo/dbginfo.c | 31 ++++++++++++++++++++++++++----- src/dbginfo/dbginfo.h | 7 ++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/dbginfo/dbginfo.c b/src/dbginfo/dbginfo.c index 88212d73e..14f0e29e4 100644 --- a/src/dbginfo/dbginfo.c +++ b/src/dbginfo/dbginfo.c @@ -270,6 +270,7 @@ struct ModInfo { unsigned Id; /* Id of library if any */ LibInfo* Info; /* Pointer to library info */ } Lib; + ScopeInfo* MainScope; /* Pointer to main scope */ Collection FileInfoByName; /* Files for this module */ Collection ScopeInfoByName;/* Scopes for this module */ char Name[1]; /* Name of module with path */ @@ -1422,6 +1423,7 @@ static ModInfo* NewModInfo (const StrBuf* Name) ModInfo* M = xmalloc (sizeof (ModInfo) + SB_GetLen (Name)); /* Initialize it */ + M->MainScope = 0; CollInit (&M->FileInfoByName); CollInit (&M->ScopeInfoByName); memcpy (M->Name, SB_GetConstBuf (Name), SB_GetLen (Name) + 1); @@ -1469,6 +1471,7 @@ static void CopyModInfo (cc65_moduledata* D, const ModInfo* M) } else { D->library_id = CC65_INV_ID; } + D->scope_id = M->MainScope->Id; } @@ -2464,7 +2467,7 @@ static void ParseInfo (InputData* D) CollGrow (&D->Info->SpanInfoById, D->IVal); break; - case TOK_SYM: + case TOK_SYM: CollGrow (&D->Info->SymInfoById, D->IVal); CollGrow (&D->Info->SymInfoByName, D->IVal); CollGrow (&D->Info->SymInfoByVal, D->IVal); @@ -4137,6 +4140,14 @@ static void ProcessScopeInfo (InputData* D) /* Add the scope to the list of scopes for this module */ CollAppend (&S->Mod.Info->ScopeInfoByName, S); + + /* If this is a main scope, add a pointer to the corresponding + * module. + */ + if (S->Parent.Id == CC65_INV_ID) { + /* No parent means main scope */ + S->Mod.Info->MainScope = S; + } } /* Resolve the parent scope */ @@ -4185,20 +4196,30 @@ static void ProcessScopeInfo (InputData* D) CollReplace (&S->SpanInfoList, SP, J); /* Insert a backpointer into the span */ - if (SP->ScopeInfoList == 0) { - SP->ScopeInfoList = CollNew (); - } + if (SP->ScopeInfoList == 0) { + SP->ScopeInfoList = CollNew (); + } CollAppend (SP->ScopeInfoList, S); } } } - /* Walk over all modules and sort the scopes by name */ + /* Walk over all modules, check that eacxh one has a main scope assigned, + * then sort the scopes by name + */ for (I = 0; I < CollCount (&D->Info->ModInfoById); ++I) { /* Get this module */ ModInfo* M = CollAt (&D->Info->ModInfoById, I); + /* Must have a main scope */ + if (M->MainScope == 0) { + ParseError (D, + CC65_ERROR, + "Module with id %u has no main scope", + M->Id); + } + /* Sort the scopes for this module by name */ CollSort (&M->ScopeInfoByName, CompareScopeInfoByName); } diff --git a/src/dbginfo/dbginfo.h b/src/dbginfo/dbginfo.h index 04f4d7f68..5867c0a6a 100644 --- a/src/dbginfo/dbginfo.h +++ b/src/dbginfo/dbginfo.h @@ -217,6 +217,7 @@ struct cc65_moduledata { const char* module_name; /* Name of the module */ unsigned source_id; /* Id of the module main file */ unsigned library_id; /* Id of the library if any */ + unsigned scope_id; /* Id of the main scope */ }; typedef struct cc65_moduleinfo cc65_moduleinfo; @@ -256,14 +257,14 @@ struct cc65_spandata { cc65_size span_size; /* Size of the span */ unsigned segment_id; /* Id of the segment */ }; - + typedef struct cc65_spaninfo cc65_spaninfo; struct cc65_spaninfo { unsigned count; /* Number of data sets that follow */ cc65_spandata data[1]; /* Data sets, number is dynamic */ }; - + cc65_spaninfo* cc65_get_spanlist (cc65_dbginfo handle); /* Return a list of all spans */ @@ -274,7 +275,7 @@ cc65_spaninfo* cc65_spaninfo_byid (cc65_dbginfo handle, unsigned id); * cc65_spaninfo structure with one entry that contains the requested * span information. */ - + void cc65_free_spaninfo (cc65_dbginfo handle, cc65_spaninfo* info); /* Free a span info record */ -- 2.39.5