mirror of
https://github.com/cc65/cc65.git
synced 2024-10-01 00:57:11 +00:00
Use the Span structure also for scopes.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5115 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
e9d9ba92b0
commit
04a0dafe25
@ -186,3 +186,27 @@ const char* GetObjFileName (const ObjData* O)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct Section* GetObjSection (ObjData* O, unsigned Id)
|
||||||
|
/* Get a section from an object file checking for a valid index */
|
||||||
|
{
|
||||||
|
if (Id >= CollCount (&O->Sections)) {
|
||||||
|
Error ("Invalid section index (%u) in module `%s'",
|
||||||
|
Id, GetObjFileName (O));
|
||||||
|
}
|
||||||
|
return CollAtUnchecked (&O->Sections, Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct Scope* GetObjScope (ObjData* O, unsigned Id)
|
||||||
|
/* Get a scope from an object file checking for a valid index */
|
||||||
|
{
|
||||||
|
if (Id >= CollCount (&O->Scopes)) {
|
||||||
|
Error ("Invalid scope index (%u) in module `%s'",
|
||||||
|
Id, GetObjFileName (O));
|
||||||
|
}
|
||||||
|
return CollAtUnchecked (&O->Scopes, Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,6 +51,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Forwards */
|
||||||
|
struct Scope;
|
||||||
|
struct Section;
|
||||||
|
|
||||||
/* Values for the Flags field */
|
/* Values for the Flags field */
|
||||||
#define OBJ_REF 0x0001 /* We have a reference to this file */
|
#define OBJ_REF 0x0001 /* We have a reference to this file */
|
||||||
|
|
||||||
@ -129,6 +133,12 @@ INLINE int ObjHasFiles (const ObjData* O)
|
|||||||
# define ObjHasFiles(O) ((O) != 0 && CollCount (&(O)->Files) != 0)
|
# define ObjHasFiles(O) ((O) != 0 && CollCount (&(O)->Files) != 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct Section* GetObjSection (ObjData* Obj, unsigned Id);
|
||||||
|
/* Get a section from an object file checking for a valid index */
|
||||||
|
|
||||||
|
struct Scope* GetObjScope (ObjData* Obj, unsigned Id);
|
||||||
|
/* Get a scope from an object file checking for a valid index */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End of objdata.h */
|
/* End of objdata.h */
|
||||||
|
@ -317,15 +317,17 @@ void ObjAdd (FILE* Obj, const char* Name)
|
|||||||
/* Read the assertions from the object file */
|
/* Read the assertions from the object file */
|
||||||
ObjReadAssertions (Obj, O->Header.AssertOffs, O);
|
ObjReadAssertions (Obj, O->Header.AssertOffs, O);
|
||||||
|
|
||||||
/* Read the scope table from the object file */
|
/* Read the segment list from the object file. This must be late, since
|
||||||
ObjReadScopes (Obj, O->Header.ScopeOffs, O);
|
|
||||||
|
|
||||||
/* Read the segment list from the object file. This must be last, since
|
|
||||||
* the expressions stored in the code may reference segments or imported
|
* the expressions stored in the code may reference segments or imported
|
||||||
* symbols.
|
* symbols.
|
||||||
*/
|
*/
|
||||||
ObjReadSections (Obj, O->Header.SegOffs, O);
|
ObjReadSections (Obj, O->Header.SegOffs, O);
|
||||||
|
|
||||||
|
/* Read the scope table from the object file. Scopes reference segments, so
|
||||||
|
* we must read them after the sections.
|
||||||
|
*/
|
||||||
|
ObjReadScopes (Obj, O->Header.ScopeOffs, O);
|
||||||
|
|
||||||
/* Mark this object file as needed */
|
/* Mark this object file as needed */
|
||||||
O->Flags |= OBJ_REF;
|
O->Flags |= OBJ_REF;
|
||||||
|
|
||||||
|
@ -40,21 +40,7 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
#include "scopes.h"
|
#include "scopes.h"
|
||||||
|
#include "span.h"
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* Data */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct SegRange SegRange;
|
|
||||||
struct SegRange {
|
|
||||||
unsigned SegId; /* Id of segment */
|
|
||||||
unsigned long Start; /* Start of range */
|
|
||||||
unsigned long End; /* End of range */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -74,7 +60,7 @@ static Scope* NewScope (ObjData* Obj, unsigned Id)
|
|||||||
S->Id = Id;
|
S->Id = Id;
|
||||||
S->Obj = Obj;
|
S->Obj = Obj;
|
||||||
S->Size = 0;
|
S->Size = 0;
|
||||||
S->SegRanges = EmptyCollection;
|
S->Spans = EmptyCollection;
|
||||||
|
|
||||||
/* Return the new entry */
|
/* Return the new entry */
|
||||||
return S;
|
return S;
|
||||||
@ -82,37 +68,9 @@ static Scope* NewScope (ObjData* Obj, unsigned Id)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static SegRange* NewSegRange (void)
|
|
||||||
/* Create a new SegRange and return it */
|
|
||||||
{
|
|
||||||
/* Allocate memory and return it */
|
|
||||||
return xmalloc (sizeof (SegRange));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static SegRange* ReadSegRange (FILE* F)
|
|
||||||
/* Read a SegRange from a file and return it */
|
|
||||||
{
|
|
||||||
/* Create a new SegRange */
|
|
||||||
SegRange* S = NewSegRange ();
|
|
||||||
|
|
||||||
/* Read data */
|
|
||||||
S->SegId = ReadVar (F);
|
|
||||||
S->Start = ReadVar (F);
|
|
||||||
S->End = ReadVar (F);
|
|
||||||
|
|
||||||
/* Return the SegRange read */
|
|
||||||
return S;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id)
|
Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id)
|
||||||
/* Read a scope from a file and return it */
|
/* Read a scope from a file and return it */
|
||||||
{
|
{
|
||||||
unsigned Count;
|
|
||||||
|
|
||||||
/* Create a new scope */
|
/* Create a new scope */
|
||||||
Scope* S = NewScope (Obj, Id);
|
Scope* S = NewScope (Obj, Id);
|
||||||
|
|
||||||
@ -127,10 +85,7 @@ Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read the segment ranges for this scope */
|
/* Read the segment ranges for this scope */
|
||||||
Count = ReadVar (F);
|
ReadSpans (&S->Spans, F, Obj);
|
||||||
while (Count--) {
|
|
||||||
CollAppend (&S->SegRanges, ReadSegRange (F));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return the new Scope */
|
/* Return the new Scope */
|
||||||
return S;
|
return S;
|
||||||
@ -154,13 +109,7 @@ void ResolveScopes (ObjData* Obj)
|
|||||||
/* Root scope */
|
/* Root scope */
|
||||||
S->Parent.Scope = 0;
|
S->Parent.Scope = 0;
|
||||||
} else {
|
} else {
|
||||||
/* Check the data */
|
S->Parent.Scope = GetObjScope (Obj, S->Parent.Id);
|
||||||
unsigned ParentId = S->Parent.Id;
|
|
||||||
if (ParentId >= CollCount (&Obj->Scopes)) {
|
|
||||||
Error ("Invalid scope index (%u) in module `%s'",
|
|
||||||
ParentId, GetObjFileName (Obj));
|
|
||||||
}
|
|
||||||
S->Parent.Scope = CollAtUnchecked (&Obj->Scopes, S->Parent.Id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ struct Scope {
|
|||||||
unsigned Type; /* Type of scope */
|
unsigned Type; /* Type of scope */
|
||||||
unsigned Name; /* Name of scope */
|
unsigned Name; /* Name of scope */
|
||||||
unsigned long Size; /* Size of scope */
|
unsigned long Size; /* Size of scope */
|
||||||
Collection SegRanges; /* Segment ranges for this scope */
|
Collection Spans; /* Spans for this scope */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +37,9 @@
|
|||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
/* ld65 */
|
/* ld65 */
|
||||||
|
#include "fileio.h"
|
||||||
|
#include "objdata.h"
|
||||||
|
#include "segments.h"
|
||||||
#include "span.h"
|
#include "span.h"
|
||||||
|
|
||||||
|
|
||||||
@ -64,6 +67,38 @@ Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Span* ReadSpan (FILE* F, ObjData* O)
|
||||||
|
/* Read a Span from a file and return it */
|
||||||
|
{
|
||||||
|
/* Read the section id and translate it to a section pointer */
|
||||||
|
Section* Sec = GetObjSection (O, ReadVar (F));
|
||||||
|
|
||||||
|
/* Read the offset and relocate it */
|
||||||
|
unsigned long Offs = ReadVar (F) + Sec->Offs;
|
||||||
|
|
||||||
|
/* Create and return a new Span */
|
||||||
|
return NewSpan (Sec->Seg, Offs, ReadVar (F));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ReadSpans (Collection* Spans, FILE* F, ObjData* O)
|
||||||
|
/* Read a list of Spans from a file and return it */
|
||||||
|
{
|
||||||
|
/* First is number of Spans */
|
||||||
|
unsigned Count = ReadVar (F);
|
||||||
|
|
||||||
|
/* Preallocate enough entries in the collection */
|
||||||
|
CollGrow (Spans, Count);
|
||||||
|
|
||||||
|
/* Read the spans and add them */
|
||||||
|
while (Count--) {
|
||||||
|
CollAppend (Spans, ReadSpan (F, O));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FreeSpan (Span* S)
|
void FreeSpan (Span* S)
|
||||||
/* Free a span structure */
|
/* Free a span structure */
|
||||||
{
|
{
|
||||||
|
@ -38,6 +38,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "coll.h"
|
#include "coll.h"
|
||||||
|
|
||||||
@ -49,6 +51,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct ObjData;
|
||||||
struct Segment;
|
struct Segment;
|
||||||
|
|
||||||
|
|
||||||
@ -77,6 +80,12 @@ struct Span {
|
|||||||
Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size);
|
Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size);
|
||||||
/* Create and return a new span */
|
/* Create and return a new span */
|
||||||
|
|
||||||
|
Span* ReadSpan (FILE* F, struct ObjData* O);
|
||||||
|
/* 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 FreeSpan (Span* S);
|
void FreeSpan (Span* S);
|
||||||
/* Free a span structure */
|
/* Free a span structure */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user