mirror of
https://github.com/cc65/cc65.git
synced 2024-11-16 02:10:52 +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 */
|
||||
#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)
|
||||
#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 */
|
||||
|
@ -317,15 +317,17 @@ void ObjAdd (FILE* Obj, const char* Name)
|
||||
/* Read the assertions from the object file */
|
||||
ObjReadAssertions (Obj, O->Header.AssertOffs, O);
|
||||
|
||||
/* Read the scope table from the object file */
|
||||
ObjReadScopes (Obj, O->Header.ScopeOffs, O);
|
||||
|
||||
/* Read the segment list from the object file. This must be last, since
|
||||
/* Read the segment list from the object file. This must be late, since
|
||||
* the expressions stored in the code may reference segments or imported
|
||||
* symbols.
|
||||
*/
|
||||
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 */
|
||||
O->Flags |= OBJ_REF;
|
||||
|
||||
|
@ -40,21 +40,7 @@
|
||||
#include "error.h"
|
||||
#include "fileio.h"
|
||||
#include "scopes.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 */
|
||||
};
|
||||
#include "span.h"
|
||||
|
||||
|
||||
|
||||
@ -71,10 +57,10 @@ static Scope* NewScope (ObjData* Obj, unsigned Id)
|
||||
Scope* S = xmalloc (sizeof (Scope));
|
||||
|
||||
/* Initialize the fields where necessary */
|
||||
S->Id = Id;
|
||||
S->Obj = Obj;
|
||||
S->Size = 0;
|
||||
S->SegRanges = EmptyCollection;
|
||||
S->Id = Id;
|
||||
S->Obj = Obj;
|
||||
S->Size = 0;
|
||||
S->Spans = EmptyCollection;
|
||||
|
||||
/* Return the new entry */
|
||||
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)
|
||||
/* Read a scope from a file and return it */
|
||||
{
|
||||
unsigned Count;
|
||||
|
||||
/* Create a new scope */
|
||||
Scope* S = NewScope (Obj, Id);
|
||||
|
||||
@ -127,10 +85,7 @@ Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id)
|
||||
}
|
||||
|
||||
/* Read the segment ranges for this scope */
|
||||
Count = ReadVar (F);
|
||||
while (Count--) {
|
||||
CollAppend (&S->SegRanges, ReadSegRange (F));
|
||||
}
|
||||
ReadSpans (&S->Spans, F, Obj);
|
||||
|
||||
/* Return the new Scope */
|
||||
return S;
|
||||
@ -154,13 +109,7 @@ void ResolveScopes (ObjData* Obj)
|
||||
/* Root scope */
|
||||
S->Parent.Scope = 0;
|
||||
} else {
|
||||
/* Check the data */
|
||||
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);
|
||||
S->Parent.Scope = GetObjScope (Obj, S->Parent.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ struct Scope {
|
||||
unsigned Type; /* Type of scope */
|
||||
unsigned Name; /* Name of scope */
|
||||
unsigned long Size; /* Size of scope */
|
||||
Collection SegRanges; /* Segment ranges for this scope */
|
||||
Collection Spans; /* Spans for this scope */
|
||||
};
|
||||
|
||||
|
||||
@ -93,4 +93,4 @@ void ResolveScopes (ObjData* Obj);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -35,8 +35,11 @@
|
||||
|
||||
/* common */
|
||||
#include "xmalloc.h"
|
||||
|
||||
/* ld65 */
|
||||
|
||||
/* ld65 */
|
||||
#include "fileio.h"
|
||||
#include "objdata.h"
|
||||
#include "segments.h"
|
||||
#include "span.h"
|
||||
|
||||
|
||||
@ -48,7 +51,7 @@
|
||||
|
||||
|
||||
Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size)
|
||||
/* Create and return a new span */
|
||||
/* Create and return a new span */
|
||||
{
|
||||
/* Allocate memory */
|
||||
Span* S = xmalloc (sizeof (*S));
|
||||
@ -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)
|
||||
/* Free a span structure */
|
||||
{
|
||||
@ -77,7 +112,7 @@ void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs,
|
||||
unsigned long Size)
|
||||
/* Either add a new span to the ones already in the given collection, or - if
|
||||
* possible - merge it with adjacent ones that already exist.
|
||||
*/
|
||||
*/
|
||||
{
|
||||
unsigned I;
|
||||
|
||||
|
@ -38,6 +38,8 @@
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* common */
|
||||
#include "coll.h"
|
||||
|
||||
@ -49,6 +51,7 @@
|
||||
|
||||
|
||||
|
||||
struct ObjData;
|
||||
struct Segment;
|
||||
|
||||
|
||||
@ -77,6 +80,12 @@ struct Span {
|
||||
Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size);
|
||||
/* 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);
|
||||
/* Free a span structure */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user