Track the main scope of modules.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5174 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2011-08-15 17:36:38 +00:00
parent 34d393a76f
commit 51e918cdfe
2 changed files with 30 additions and 8 deletions

View File

@@ -270,6 +270,7 @@ struct ModInfo {
unsigned Id; /* Id of library if any */ unsigned Id; /* Id of library if any */
LibInfo* Info; /* Pointer to library info */ LibInfo* Info; /* Pointer to library info */
} Lib; } Lib;
ScopeInfo* MainScope; /* Pointer to main scope */
Collection FileInfoByName; /* Files for this module */ Collection FileInfoByName; /* Files for this module */
Collection ScopeInfoByName;/* Scopes for this module */ Collection ScopeInfoByName;/* Scopes for this module */
char Name[1]; /* Name of module with path */ 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)); ModInfo* M = xmalloc (sizeof (ModInfo) + SB_GetLen (Name));
/* Initialize it */ /* Initialize it */
M->MainScope = 0;
CollInit (&M->FileInfoByName); CollInit (&M->FileInfoByName);
CollInit (&M->ScopeInfoByName); CollInit (&M->ScopeInfoByName);
memcpy (M->Name, SB_GetConstBuf (Name), SB_GetLen (Name) + 1); memcpy (M->Name, SB_GetConstBuf (Name), SB_GetLen (Name) + 1);
@@ -1469,6 +1471,7 @@ static void CopyModInfo (cc65_moduledata* D, const ModInfo* M)
} else { } else {
D->library_id = CC65_INV_ID; 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); CollGrow (&D->Info->SpanInfoById, D->IVal);
break; break;
case TOK_SYM: case TOK_SYM:
CollGrow (&D->Info->SymInfoById, D->IVal); CollGrow (&D->Info->SymInfoById, D->IVal);
CollGrow (&D->Info->SymInfoByName, D->IVal); CollGrow (&D->Info->SymInfoByName, D->IVal);
CollGrow (&D->Info->SymInfoByVal, 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 */ /* Add the scope to the list of scopes for this module */
CollAppend (&S->Mod.Info->ScopeInfoByName, S); 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 */ /* Resolve the parent scope */
@@ -4185,20 +4196,30 @@ static void ProcessScopeInfo (InputData* D)
CollReplace (&S->SpanInfoList, SP, J); CollReplace (&S->SpanInfoList, SP, J);
/* Insert a backpointer into the span */ /* Insert a backpointer into the span */
if (SP->ScopeInfoList == 0) { if (SP->ScopeInfoList == 0) {
SP->ScopeInfoList = CollNew (); SP->ScopeInfoList = CollNew ();
} }
CollAppend (SP->ScopeInfoList, S); 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) { for (I = 0; I < CollCount (&D->Info->ModInfoById); ++I) {
/* Get this module */ /* Get this module */
ModInfo* M = CollAt (&D->Info->ModInfoById, I); 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 */ /* Sort the scopes for this module by name */
CollSort (&M->ScopeInfoByName, CompareScopeInfoByName); CollSort (&M->ScopeInfoByName, CompareScopeInfoByName);
} }

View File

@@ -217,6 +217,7 @@ struct cc65_moduledata {
const char* module_name; /* Name of the module */ const char* module_name; /* Name of the module */
unsigned source_id; /* Id of the module main file */ unsigned source_id; /* Id of the module main file */
unsigned library_id; /* Id of the library if any */ unsigned library_id; /* Id of the library if any */
unsigned scope_id; /* Id of the main scope */
}; };
typedef struct cc65_moduleinfo cc65_moduleinfo; typedef struct cc65_moduleinfo cc65_moduleinfo;
@@ -256,14 +257,14 @@ struct cc65_spandata {
cc65_size span_size; /* Size of the span */ cc65_size span_size; /* Size of the span */
unsigned segment_id; /* Id of the segment */ unsigned segment_id; /* Id of the segment */
}; };
typedef struct cc65_spaninfo cc65_spaninfo; typedef struct cc65_spaninfo cc65_spaninfo;
struct cc65_spaninfo { struct cc65_spaninfo {
unsigned count; /* Number of data sets that follow */ unsigned count; /* Number of data sets that follow */
cc65_spandata data[1]; /* Data sets, number is dynamic */ cc65_spandata data[1]; /* Data sets, number is dynamic */
}; };
cc65_spaninfo* cc65_get_spanlist (cc65_dbginfo handle); cc65_spaninfo* cc65_get_spanlist (cc65_dbginfo handle);
/* Return a list of all spans */ /* 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 * cc65_spaninfo structure with one entry that contains the requested
* span information. * span information.
*/ */
void cc65_free_spaninfo (cc65_dbginfo handle, cc65_spaninfo* info); void cc65_free_spaninfo (cc65_dbginfo handle, cc65_spaninfo* info);
/* Free a span info record */ /* Free a span info record */