1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-28 03:29:39 +00:00

Do not resolve the lists of spans for LineInfos and Scopes, but keep them as

ids. This way, we can delay loading spans until we know that we definitely
need an object file. 
Did some restructuring for writing of span lists to the debug info file.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5261 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-22 17:36:19 +00:00
parent ecfba0c9b0
commit fda7934e68
8 changed files with 67 additions and 56 deletions

View File

@ -245,9 +245,6 @@ static void ReadBasicData (Library* L, ObjData* O)
/* Read the files list */
ObjReadFiles (L->F, O->Start + O->Header.FileOffs, O);
/* Read the spans */
ObjReadSpans (L->F, O->Start + O->Header.SpanOffs, O);
/* Read the line infos */
ObjReadLineInfos (L->F, O->Start + O->Header.LineInfoOffs, O);
@ -411,6 +408,9 @@ static void LibResolve (void)
*/
ObjReadScopes (L->F, O->Start + O->Header.ScopeOffs, O);
/* Read the spans */
ObjReadSpans (L->F, O->Start + O->Header.SpanOffs, O);
/* All references to strings are now resolved, so we can delete
* the module string pool.
*/

View File

@ -67,7 +67,7 @@ static LineInfo* NewLineInfo (void)
LI->Pos.Name = INVALID_STRING_ID;
LI->Pos.Line = 0;
LI->Pos.Col = 0;
LI->Spans = EmptyCollection;
LI->Spans = 0;
/* Return the new struct */
return LI;
@ -78,8 +78,8 @@ static LineInfo* NewLineInfo (void)
void FreeLineInfo (LineInfo* LI)
/* Free a LineInfo structure. */
{
/* Free the collections */
DoneCollection (&LI->Spans);
/* Free the span list */
xfree (LI->Spans);
/* Free the structure itself */
xfree (LI);
@ -114,7 +114,7 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O)
LI->File = CollAt (&O->Files, ReadVar (F));
LI->Pos.Name = LI->File->Name;
LI->Type = ReadVar (F);
ReadSpanList (&LI->Spans, F, O);
LI->Spans = ReadSpanList (F);
/* Return the struct read */
return LI;
@ -206,7 +206,7 @@ void AssignLineInfoIds (void)
void PrintDbgLineInfo (FILE* F)
/* Output the line infos to a debug info file */
{
unsigned I, J, K;
unsigned I, J;
/* Print line infos from all modules we have linked into the output file */
for (I = 0; I < CollCount (&ObjDataList); ++I) {
@ -224,9 +224,6 @@ void PrintDbgLineInfo (FILE* F)
unsigned Type = LI_GET_TYPE (LI->Type);
unsigned Count = LI_GET_COUNT (LI->Type);
/* Get a pointer to the spans */
const Collection* Spans = &LI->Spans;
/* Print the start of the line */
fprintf (F,
"line\tid=%u,file=%u,line=%u",
@ -241,16 +238,7 @@ void PrintDbgLineInfo (FILE* F)
}
/* Add spans if the line info has it */
if (CollCount (Spans) > 0) {
/* Output the first span */
fprintf (F, ",span=%u", SpanId (O, CollConstAt (Spans, 0)));
/* Output the other spans */
for (K = 1; K < CollCount (Spans); ++K) {
fprintf (F, "+%u", SpanId (O, CollConstAt (Spans, K)));
}
}
PrintDbgSpanList (F, O, LI->Spans);
/* Terminate line */
fputc ('\n', F);

View File

@ -77,7 +77,7 @@ struct LineInfo {
struct FileInfo* File; /* File struct for this line if any */
unsigned Type; /* Type of line info */
FilePos Pos; /* Position in file */
Collection Spans; /* Spans for this line */
unsigned* Spans; /* Spans for this line */
};

View File

@ -323,9 +323,6 @@ void ObjAdd (FILE* Obj, const char* Name)
/* Read the files list from the object file */
ObjReadFiles (Obj, O->Header.FileOffs, O);
/* Read the spans from the object file */
ObjReadSpans (Obj, O->Header.SpanOffs, O);
/* Read the line infos from the object file */
ObjReadLineInfos (Obj, O->Header.LineInfoOffs, O);
@ -352,6 +349,9 @@ void ObjAdd (FILE* Obj, const char* Name)
*/
ObjReadScopes (Obj, O->Header.ScopeOffs, O);
/* Read the spans from the object file */
ObjReadSpans (Obj, O->Header.SpanOffs, O);
/* Mark this object file as needed */
O->Flags |= OBJ_REF;

View File

@ -62,7 +62,7 @@ static Scope* NewScope (ObjData* Obj, unsigned Id)
S->Obj = Obj;
S->Size = 0;
S->LabelId = ~0U;
S->Spans = EmptyCollection;
S->Spans = 0;
/* Return the new entry */
return S;
@ -88,9 +88,7 @@ Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id)
if (SCOPE_HAS_LABEL (S->Flags)) {
S->LabelId = ReadVar (F);
}
/* Read the spans for this scope */
ReadSpanList (&S->Spans, F, Obj);
S->Spans = ReadSpanList (F);
/* Return the new Scope */
return S;
@ -120,7 +118,7 @@ unsigned ScopeCount (void)
void PrintDbgScopes (FILE* F)
/* Output the scopes to a debug info file */
{
unsigned I, J, K;
unsigned I, J;
/* Print scopes from all modules we have linked into the output file */
for (I = 0; I < CollCount (&ObjDataList); ++I) {
@ -132,6 +130,7 @@ void PrintDbgScopes (FILE* F)
for (J = 0; J < CollCount (&O->Scopes); ++J) {
const Scope* S = CollConstAt (&O->Scopes, J);
/* Output the first chunk of data */
fprintf (F,
"scope\tid=%u,name=\"%s\",mod=%u",
O->ScopeBaseId + S->Id,
@ -165,12 +164,7 @@ void PrintDbgScopes (FILE* F)
fprintf (F, ",sym=%u", O->SymBaseId + S->LabelId);
}
/* Print the list of spans for this scope */
if (CollCount (&S->Spans) > 0) {
fprintf (F, ",span=%u", SpanId (O, CollConstAt (&S->Spans, 0)));
for (K = 1; K < CollCount (&S->Spans); ++K) {
fprintf (F, "+%u", SpanId (O, CollConstAt (&S->Spans, K)));
}
}
PrintDbgSpanList (F, O, S->Spans);
/* Terminate the output line */
fputc ('\n', F);

View File

@ -67,7 +67,7 @@ struct Scope {
unsigned Type; /* Type of scope */
unsigned Name; /* Name of scope */
unsigned long Size; /* Size of scope */
Collection Spans; /* Spans for this scope */
unsigned* Spans; /* Spans for this scope */
};

View File

@ -100,19 +100,32 @@ Span* ReadSpan (FILE* F, ObjData* O, unsigned Id)
void ReadSpanList (Collection* Spans, FILE* F, ObjData* O)
/* Read a list of span ids from a file and return the spans for the ids */
unsigned* ReadSpanList (FILE* F)
/* Read a list of span ids from a file. The list is returned as an array of
* unsigneds, the first being the number of spans (never zero) followed by
* the span ids. If the number of spans is zero, NULL is returned.
*/
{
unsigned* Spans;
/* First is number of Spans */
unsigned Count = ReadVar (F);
if (Count == 0) {
return 0;
}
/* Preallocate enough entries in the collection */
CollGrow (Spans, Count);
/* Allocate memory for the list and set the count */
Spans = xmalloc ((Count + 1) * sizeof (*Spans));
*Spans = Count;
/* Read the spans and add them */
while (Count--) {
CollAppend (Spans, CollAt (&O->Spans, ReadVar (F)));
while (Count) {
Spans[Count] = ReadVar (F);
--Count;
}
/* Return the list */
return Spans;
}
@ -126,14 +139,6 @@ void FreeSpan (Span* S)
unsigned SpanId (const struct ObjData* O, const Span* S)
/* Return the global id of a span */
{
return O->SpanBaseId + S->Id;
}
unsigned SpanCount (void)
/* Return the total number of spans */
{
@ -154,6 +159,24 @@ unsigned SpanCount (void)
void PrintDbgSpanList (FILE* F, const ObjData* O, const unsigned* List)
/* Output a string ",span=x[+y...]" for the given list. If the list is empty
* or NULL, output nothing. This is a helper function for other modules to
* print a list of spans read by ReadSpanList to the debug info file.
*/
{
if (List && *List) {
unsigned I;
const char* Format = ",span=%u";
for (I = 0; I < *List; ++I) {
fprintf (F, Format, O->SpanBaseId + List[I+1]);
Format = "+%u";
}
}
}
void PrintDbgSpans (FILE* F)
/* Output the spans to a debug info file */
{

View File

@ -76,18 +76,24 @@ typedef struct Span Span;
Span* ReadSpan (FILE* F, struct ObjData* O, unsigned Id);
/* Read a Span from a file and return it */
void ReadSpanList (Collection* Spans, FILE* F, struct ObjData* O);
/* Read a list of span ids from a file and return the spans for the ids */
unsigned* ReadSpanList (FILE* F);
/* Read a list of span ids from a file. The list is returned as an array of
* unsigneds, the first being the number of spans (never zero) followed by
* the span ids. If the number of spans is zero, NULL is returned.
*/
void FreeSpan (Span* S);
/* Free a span structure */
unsigned SpanId (const struct ObjData* O, const Span* S);
/* Return the global id of a span */
unsigned SpanCount (void);
/* Return the total number of spans */
void PrintDbgSpanList (FILE* F, const struct ObjData* O, const unsigned* List);
/* Output a string ",span=x[+y...]" for the given list. If the list is empty
* or NULL, output nothing. This is a helper function for other modules to
* print a list of spans read by ReadSpanList to the debug info file.
*/
void PrintDbgSpans (FILE* F);
/* Output the spans to a debug info file */