Write spans out in a separate object file section. This allows to merge

duplicate spans in an object file and more extensions to come.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5250 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2011-08-21 19:08:23 +00:00
parent 37ac033370
commit 358ccf236e
18 changed files with 396 additions and 111 deletions

View File

@@ -200,6 +200,8 @@ static void LibReadObjHeader (Library* L, ObjData* O)
O->Header.AssertSize = Read32 (L->F);
O->Header.ScopeOffs = Read32 (L->F);
O->Header.ScopeSize = Read32 (L->F);
O->Header.SpanOffs = Read32 (L->F);
O->Header.SpanSize = Read32 (L->F);
}
@@ -220,7 +222,7 @@ static ObjData* ReadIndexEntry (Library* L)
O->Flags = Read16 (L->F);
O->MTime = Read32 (L->F);
O->Start = Read32 (L->F);
Read32 (L->F); /* Skip Size */
Read32 (L->F); /* Skip Size */
/* Done */
return O;
@@ -243,6 +245,9 @@ 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);

View File

@@ -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);
ReadSpans (&LI->Spans, F, O);
ReadSpanList (&LI->Spans, F, O);
/* Return the struct read */
return LI;

View File

@@ -107,6 +107,8 @@ static void ObjReadHeader (FILE* Obj, ObjHeader* H, const char* Name)
H->AssertSize = Read32 (Obj);
H->ScopeOffs = Read32 (Obj);
H->ScopeSize = Read32 (Obj);
H->SpanOffs = Read32 (Obj);
H->SpanSize = Read32 (Obj);
}
@@ -281,6 +283,25 @@ void ObjReadScopes (FILE* F, unsigned long Pos, ObjData* O)
void ObjReadSpans (FILE* F, unsigned long Pos, ObjData* O)
/* Read the span table from a file at the given offset */
{
unsigned I;
unsigned SpanCount;
/* Seek to the correct position */
FileSetPos (F, Pos);
/* Read the data */
SpanCount = ReadVar (F);
CollGrow (&O->Spans, SpanCount);
for (I = 0; I < SpanCount; ++I) {
CollAppend (&O->Spans, ReadSpan (F, O, I));
}
}
void ObjAdd (FILE* Obj, const char* Name)
/* Add an object file to the module list */
{
@@ -302,6 +323,9 @@ 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);

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<EFBFBD>merstra<EFBFBD>e 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -81,6 +81,9 @@ void ObjReadAssertions (FILE* F, unsigned long Pos, ObjData* O);
void ObjReadScopes (FILE* F, unsigned long Pos, ObjData* O);
/* Read the scope table from a file at the given offset */
void ObjReadSpans (FILE* F, unsigned long Pos, ObjData* O);
/* Read the span table from a file at the given offset */
void ObjAdd (FILE* F, const char* Name);
/* Add an object file to the module list */

View File

@@ -90,7 +90,7 @@ Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id)
}
/* Read the spans for this scope */
ReadSpans (&S->Spans, F, Obj);
ReadSpanList (&S->Spans, F, Obj);
/* Return the new Scope */
return S;

View File

@@ -34,6 +34,7 @@
/* common */
#include "attrib.h"
#include "xmalloc.h"
/* ld65 */
@@ -66,41 +67,38 @@ struct Span {
Span* NewSpan (ObjData* Obj, unsigned SecId, unsigned long Offs, unsigned long Size)
static Span* NewSpan (unsigned Id, unsigned Sec, unsigned long Offs, unsigned long Size)
/* Create and return a new span */
{
/* Allocate memory */
Span* S = xmalloc (sizeof (*S));
/* Initialize the fields */
S->Id = CollCount (&Obj->Spans);
S->Sec = SecId;
S->Id = Id;
S->Sec = Sec;
S->Offs = Offs;
S->Size = Size;
/* Insert it into the collection of all spans of this object file */
CollAppend (&Obj->Spans, S);
/* Return the result */
return S;
}
Span* ReadSpan (FILE* F, ObjData* O)
Span* ReadSpan (FILE* F, ObjData* O attribute ((unused)), unsigned Id)
/* Read a Span from a file and return it */
{
/* Create a new Span and return it */
unsigned SecId = ReadVar (F);
unsigned long Offs = ReadVar (F);
unsigned Size = ReadVar (F);
return NewSpan (O, SecId, Offs, Size);
return NewSpan (Id, SecId, Offs, Size);
}
void ReadSpans (Collection* Spans, FILE* F, ObjData* O)
/* Read a list of Spans from a file and return it */
void ReadSpanList (Collection* Spans, FILE* F, ObjData* O)
/* Read a list of span ids from a file and return the spans for the ids */
{
/* First is number of Spans */
unsigned Count = ReadVar (F);
@@ -110,7 +108,7 @@ void ReadSpans (Collection* Spans, FILE* F, ObjData* O)
/* Read the spans and add them */
while (Count--) {
CollAppend (Spans, ReadSpan (F, O));
CollAppend (Spans, CollAt (&O->Spans, ReadVar (F)));
}
}

View File

@@ -73,15 +73,11 @@ typedef struct Span Span;
Span* NewSpan (struct ObjData* Obj, unsigned SecId, unsigned long Offs,
unsigned long Size);
/* Create and return a new span */
Span* ReadSpan (FILE* F, struct ObjData* O);
Span* ReadSpan (FILE* F, struct ObjData* O, unsigned Id);
/* Read a Span from a file and return it */
void ReadSpans (Collection* Spans, FILE* F, struct ObjData* O);
/* Read a list of Spans 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 */
void FreeSpan (Span* S);
/* Free a span structure */