1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-19 06:31:31 +00:00

Add an optional type to a span.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5253 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-21 19:44:02 +00:00
parent f2de523b5d
commit 913db79017
3 changed files with 35 additions and 16 deletions

View File

@ -43,6 +43,7 @@
#include "objfile.h" #include "objfile.h"
#include "segment.h" #include "segment.h"
#include "span.h" #include "span.h"
#include "spool.h"
@ -155,7 +156,7 @@ static Span* NewSpan (Segment* Seg, unsigned long Start, unsigned long End)
S->Seg = Seg; S->Seg = Seg;
S->Start = Start; S->Start = Start;
S->End = End; S->End = End;
S->Type = 0; S->Type = EMPTY_STRING_ID;
/* Return the new struct */ /* Return the new struct */
return S; return S;
@ -183,9 +184,11 @@ static Span* MergeSpan (Span* S)
Span* E = HT_Find (&SpanTab, S); Span* E = HT_Find (&SpanTab, S);
if (E) { if (E) {
/* If S has a type and E not, move the type */ /* If S has a type and E not, move the type */
CHECK (E->Type == 0); if (S->Type != EMPTY_STRING_ID) {
CHECK (E->Type == EMPTY_STRING_ID);
E->Type = S->Type; E->Type = S->Type;
S->Type = 0; }
/* Free S and return E */ /* Free S and return E */
FreeSpan (S); FreeSpan (S);
return E; return E;
@ -199,6 +202,14 @@ static Span* MergeSpan (Span* S)
void SetSpanType (Span* S, const StrBuf* Type)
/* Set the generic type of the span to Type */
{
S->Type = GetStrBufId (Type);
}
Span* OpenSpan (void) Span* OpenSpan (void)
/* Open a span for the active segment and return it. */ /* Open a span for the active segment and return it. */
{ {
@ -377,6 +388,7 @@ void WriteSpans (void)
ObjWriteVar (S->Seg->Num); ObjWriteVar (S->Seg->Num);
ObjWriteVar (S->Start); ObjWriteVar (S->Start);
ObjWriteVar (S->End - S->Start); ObjWriteVar (S->End - S->Start);
ObjWriteVar (S->Type);
} }
/* Free the collection with the spans */ /* Free the collection with the spans */

View File

@ -43,6 +43,7 @@
#include "gentype.h" #include "gentype.h"
#include "hashtab.h" #include "hashtab.h"
#include "inline.h" #include "inline.h"
#include "strbuf.h"
@ -84,6 +85,9 @@ INLINE unsigned long GetSpanSize (const Span* R)
# define GetSpanSize(R) ((R)->End - (R)->Start) # define GetSpanSize(R) ((R)->End - (R)->Start)
#endif #endif
void SetSpanType (Span* S, const StrBuf* Type);
/* Set the generic type of the span to Type */
Span* OpenSpan (void); Span* OpenSpan (void);
/* Open a span for the active segment and return it. */ /* Open a span for the active segment and return it. */

View File

@ -42,6 +42,7 @@
#include "objdata.h" #include "objdata.h"
#include "segments.h" #include "segments.h"
#include "span.h" #include "span.h"
#include "spool.h"
@ -57,6 +58,7 @@ struct Span {
unsigned Sec; /* Section id of this span */ unsigned Sec; /* Section id of this span */
unsigned long Offs; /* Offset of span within segment */ unsigned long Offs; /* Offset of span within segment */
unsigned long Size; /* Size of span */ unsigned long Size; /* Size of span */
unsigned Type; /* Generic type of the data */
}; };
@ -67,17 +69,14 @@ struct Span {
static Span* NewSpan (unsigned Id, unsigned Sec, unsigned long Offs, unsigned long Size) static Span* NewSpan (unsigned Id)
/* Create and return a new span */ /* Create and return a new span */
{ {
/* Allocate memory */ /* Allocate memory */
Span* S = xmalloc (sizeof (*S)); Span* S = xmalloc (sizeof (Span));
/* Initialize the fields */ /* Initialize the fields as necessary */
S->Id = Id; S->Id = Id;
S->Sec = Sec;
S->Offs = Offs;
S->Size = Size;
/* Return the result */ /* Return the result */
return S; return S;
@ -85,14 +84,18 @@ static Span* NewSpan (unsigned Id, unsigned Sec, unsigned long Offs, unsigned lo
Span* ReadSpan (FILE* F, ObjData* O attribute ((unused)), unsigned Id) Span* ReadSpan (FILE* F, ObjData* O, unsigned Id)
/* Read a Span from a file and return it */ /* Read a Span from a file and return it */
{ {
/* Create a new Span and return it */ /* Create a new Span and initialize it */
unsigned SecId = ReadVar (F); Span* S = NewSpan (Id);
unsigned long Offs = ReadVar (F); S->Sec = ReadVar (F);
unsigned Size = ReadVar (F); S->Offs = ReadVar (F);
return NewSpan (Id, SecId, Offs, Size); S->Size = ReadVar (F);
S->Type = MakeGlobalStringId (O, ReadVar (F));
/* Return the new span */
return S;
} }