Generalized the CodeRange structure used for line infos and renamed it to Span.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5112 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -77,20 +77,20 @@ void PrintDbgInfo (ObjData* O, FILE* F)
|
|||||||
unsigned Type = LI_GET_TYPE (LI->Type);
|
unsigned Type = LI_GET_TYPE (LI->Type);
|
||||||
unsigned Count = LI_GET_COUNT (LI->Type);
|
unsigned Count = LI_GET_COUNT (LI->Type);
|
||||||
|
|
||||||
/* Get a pointer to the code ranges */
|
/* Get a pointer to the spans */
|
||||||
const Collection* CodeRanges = &LI->CodeRanges;
|
const Collection* Spans = &LI->Spans;
|
||||||
|
|
||||||
/* Code ranges */
|
/* Spans */
|
||||||
for (J = 0; J < CollCount (CodeRanges); ++J) {
|
for (J = 0; J < CollCount (Spans); ++J) {
|
||||||
|
|
||||||
/* Get this code range */
|
/* Get this code range */
|
||||||
const CodeRange* R = CollConstAt (CodeRanges, J);
|
const Span* S = CollConstAt (Spans, J);
|
||||||
|
|
||||||
/* Print it */
|
/* Print it */
|
||||||
fprintf (F,
|
fprintf (F,
|
||||||
"line\tfile=%u,line=%lu,segment=%u,range=0x%lX-0x%lX",
|
"line\tfile=%u,line=%lu,segment=%u,range=0x%lX-0x%lX",
|
||||||
LI->File->Id, GetSourceLine (LI), R->Seg->Id,
|
LI->File->Id, GetSourceLine (LI), S->Seg->Id,
|
||||||
R->Offs, R->Offs + R->Size - 1);
|
S->Offs, S->Offs + S->Size - 1);
|
||||||
|
|
||||||
/* Print type if not LI_TYPE_ASM and count if not zero */
|
/* Print type if not LI_TYPE_ASM and count if not zero */
|
||||||
if (Type != LI_TYPE_ASM) {
|
if (Type != LI_TYPE_ASM) {
|
||||||
@@ -109,4 +109,3 @@ void PrintDbgInfo (ObjData* O, FILE* F)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -55,32 +55,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static CodeRange* NewCodeRange (Segment* Seg, unsigned long Offs, unsigned long Size)
|
|
||||||
/* Create and return a new CodeRange struct */
|
|
||||||
{
|
|
||||||
/* Allocate memory */
|
|
||||||
CodeRange* R = xmalloc (sizeof (CodeRange));
|
|
||||||
|
|
||||||
/* Initialize the fields */
|
|
||||||
R->Seg = Seg;
|
|
||||||
R->Offs = Offs;
|
|
||||||
R->Size = Size;
|
|
||||||
|
|
||||||
/* Return the new struct */
|
|
||||||
return R;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void FreeCodeRange (CodeRange* R)
|
|
||||||
/* Free a CodeRange structure */
|
|
||||||
{
|
|
||||||
/* Just free the memory */
|
|
||||||
xfree (R);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static LineInfo* NewLineInfo (void)
|
static LineInfo* NewLineInfo (void)
|
||||||
/* Create and return a new LineInfo struct with mostly empty fields */
|
/* Create and return a new LineInfo struct with mostly empty fields */
|
||||||
{
|
{
|
||||||
@@ -94,7 +68,7 @@ static LineInfo* NewLineInfo (void)
|
|||||||
LI->Pos.Line = 0;
|
LI->Pos.Line = 0;
|
||||||
LI->Pos.Col = 0;
|
LI->Pos.Col = 0;
|
||||||
LI->Fragments = EmptyCollection;
|
LI->Fragments = EmptyCollection;
|
||||||
LI->CodeRanges = EmptyCollection;
|
LI->Spans = EmptyCollection;
|
||||||
|
|
||||||
/* Return the new struct */
|
/* Return the new struct */
|
||||||
return LI;
|
return LI;
|
||||||
@@ -113,12 +87,12 @@ void FreeLineInfo (LineInfo* LI)
|
|||||||
PRECONDITION (CollCount (&LI->Fragments) == 0);
|
PRECONDITION (CollCount (&LI->Fragments) == 0);
|
||||||
|
|
||||||
/* Free all the code ranges */
|
/* Free all the code ranges */
|
||||||
for (I = 0; I < CollCount (&LI->CodeRanges); ++I) {
|
for (I = 0; I < CollCount (&LI->Spans); ++I) {
|
||||||
FreeCodeRange (CollAtUnchecked (&LI->CodeRanges, I));
|
FreeSpan (CollAtUnchecked (&LI->Spans, I));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the collections */
|
/* Free the collections */
|
||||||
DoneCollection (&LI->CodeRanges);
|
DoneCollection (&LI->Spans);
|
||||||
|
|
||||||
/* Free the structure itself */
|
/* Free the structure itself */
|
||||||
xfree (LI);
|
xfree (LI);
|
||||||
@@ -191,55 +165,6 @@ void ReadLineInfoList (FILE* F, ObjData* O, Collection* LineInfos)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void AddCodeRange (LineInfo* LI, Segment* Seg, unsigned long Offs,
|
|
||||||
unsigned long Size)
|
|
||||||
/* Add a range of code to this line */
|
|
||||||
{
|
|
||||||
unsigned I;
|
|
||||||
|
|
||||||
/* Get a pointer to the collection */
|
|
||||||
Collection* CodeRanges = &LI->CodeRanges;
|
|
||||||
|
|
||||||
/* We will keep the CodeRanges collection sorted by starting offset,
|
|
||||||
* so we have to search for the correct insert position. Since in most
|
|
||||||
* cases, the fragments have increasing order, and there is usually not
|
|
||||||
* more than one or two ranges, we do a linear search.
|
|
||||||
*/
|
|
||||||
for (I = 0; I < CollCount (CodeRanges); ++I) {
|
|
||||||
CodeRange* R = CollAtUnchecked (CodeRanges, I);
|
|
||||||
/* Must be same segment */
|
|
||||||
if (R->Seg == Seg) {
|
|
||||||
if (Offs < R->Offs) {
|
|
||||||
|
|
||||||
/* Got the insert position */
|
|
||||||
if (Offs + Size == R->Offs) {
|
|
||||||
/* Merge the two */
|
|
||||||
R->Offs = Offs;
|
|
||||||
R->Size += Size;
|
|
||||||
} else {
|
|
||||||
/* Insert a new entry */
|
|
||||||
CollInsert (CodeRanges, NewCodeRange (Seg, Offs, Size), I);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Done */
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else if (R->Offs + R->Size == Offs) {
|
|
||||||
/* This is the regular case. Merge the two. */
|
|
||||||
R->Size += Size;
|
|
||||||
|
|
||||||
/* Done */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We must append an entry */
|
|
||||||
CollAppend (CodeRanges, NewCodeRange (Seg, Offs, Size));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void RelocLineInfo (Segment* S)
|
void RelocLineInfo (Segment* S)
|
||||||
/* Relocate the line info for a segment. */
|
/* Relocate the line info for a segment. */
|
||||||
{
|
{
|
||||||
@@ -261,7 +186,8 @@ void RelocLineInfo (Segment* S)
|
|||||||
|
|
||||||
/* Add the range for this fragment to all line infos */
|
/* Add the range for this fragment to all line infos */
|
||||||
for (I = 0; I < CollCount (&Frag->LineInfos); ++I) {
|
for (I = 0; I < CollCount (&Frag->LineInfos); ++I) {
|
||||||
AddCodeRange (CollAt (&Frag->LineInfos, I), S, Offs, Frag->Size);
|
LineInfo* LI = CollAtUnchecked (&Frag->LineInfos, I);
|
||||||
|
AddSpan (&LI->Spans, S, Offs, Frag->Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the offset */
|
/* Update the offset */
|
||||||
|
|||||||
@@ -45,12 +45,13 @@
|
|||||||
#include "filepos.h"
|
#include "filepos.h"
|
||||||
|
|
||||||
/* ld65 */
|
/* ld65 */
|
||||||
|
#include "span.h"
|
||||||
#include "spool.h"
|
#include "spool.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Forwards */
|
/* Forwards */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
@@ -66,15 +67,6 @@ struct Segment;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct CodeRange CodeRange;
|
|
||||||
struct CodeRange {
|
|
||||||
struct Segment* Seg; /* Segment of this code range */
|
|
||||||
unsigned long Offs; /* Offset of code range */
|
|
||||||
unsigned long Size; /* Size of code range */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Structure holding line information. The Pos.Name field is always the
|
/* Structure holding line information. The Pos.Name field is always the
|
||||||
* global string id of the file name. If the line info was read from the
|
* global string id of the file name. If the line info was read from the
|
||||||
* object file, the File pointer is valid, otherwise it is NULL.
|
* object file, the File pointer is valid, otherwise it is NULL.
|
||||||
@@ -85,7 +77,7 @@ struct LineInfo {
|
|||||||
unsigned Type; /* Type of line info */
|
unsigned Type; /* Type of line info */
|
||||||
FilePos Pos; /* Position in file */
|
FilePos Pos; /* Position in file */
|
||||||
Collection Fragments; /* Fragments for this line */
|
Collection Fragments; /* Fragments for this line */
|
||||||
Collection CodeRanges; /* Code ranges for this line */
|
Collection Spans; /* Spans for this line */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ OBJS = asserts.o \
|
|||||||
scanner.o \
|
scanner.o \
|
||||||
scopes.o \
|
scopes.o \
|
||||||
segments.o \
|
segments.o \
|
||||||
|
span.o \
|
||||||
spool.o \
|
spool.o \
|
||||||
tgtcfg.o
|
tgtcfg.o
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ OBJS = asserts.obj \
|
|||||||
scanner.obj \
|
scanner.obj \
|
||||||
scopes.obj \
|
scopes.obj \
|
||||||
segments.obj \
|
segments.obj \
|
||||||
|
span.obj \
|
||||||
spool.obj \
|
spool.obj \
|
||||||
tgtcfg.obj
|
tgtcfg.obj
|
||||||
|
|
||||||
|
|||||||
128
src/ld65/span.c
Normal file
128
src/ld65/span.c
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* span.c */
|
||||||
|
/* */
|
||||||
|
/* A span of data within a segment */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2011, Ullrich von Bassewitz */
|
||||||
|
/* Roemerstrasse 52 */
|
||||||
|
/* D-70794 Filderstadt */
|
||||||
|
/* EMail: uz@cc65.org */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "xmalloc.h"
|
||||||
|
|
||||||
|
/* ld65 */
|
||||||
|
#include "span.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size)
|
||||||
|
/* Create and return a new span */
|
||||||
|
{
|
||||||
|
/* Allocate memory */
|
||||||
|
Span* S = xmalloc (sizeof (*S));
|
||||||
|
|
||||||
|
/* Initialize the fields */
|
||||||
|
S->Seg = Seg;
|
||||||
|
S->Offs = Offs;
|
||||||
|
S->Size = Size;
|
||||||
|
|
||||||
|
/* Return the result */
|
||||||
|
return S;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void FreeSpan (Span* S)
|
||||||
|
/* Free a span structure */
|
||||||
|
{
|
||||||
|
/* Just free the structure */
|
||||||
|
xfree (S);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/* We don't have many spans in a collection, so we do a linear search here.
|
||||||
|
* The collection is kept sorted which eases our work here.
|
||||||
|
*/
|
||||||
|
for (I = 0; I < CollCount (Spans); ++I) {
|
||||||
|
|
||||||
|
/* Get the next span */
|
||||||
|
Span* S = CollAtUnchecked (Spans, I);
|
||||||
|
|
||||||
|
/* Must be same segment, otherwise we cannot merge */
|
||||||
|
if (S->Seg != Seg) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if we can merge it */
|
||||||
|
if (Offs < S->Offs) {
|
||||||
|
|
||||||
|
/* Got the insert position */
|
||||||
|
if (Offs + Size == S->Offs) {
|
||||||
|
/* Merge the two */
|
||||||
|
S->Offs = Offs;
|
||||||
|
S->Size += Size;
|
||||||
|
} else {
|
||||||
|
/* Insert a new entry */
|
||||||
|
CollInsert (Spans, NewSpan (Seg, Offs, Size), I);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Done */
|
||||||
|
return;
|
||||||
|
|
||||||
|
} else if (S->Offs + S->Size == Offs) {
|
||||||
|
|
||||||
|
/* This is the regular case. Merge the two. */
|
||||||
|
S->Size += Size;
|
||||||
|
|
||||||
|
/* Done */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We must append an entry */
|
||||||
|
CollAppend (Spans, NewSpan (Seg, Offs, Size));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
95
src/ld65/span.h
Normal file
95
src/ld65/span.h
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* span.h */
|
||||||
|
/* */
|
||||||
|
/* A span of data within a segment */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2011, Ullrich von Bassewitz */
|
||||||
|
/* Roemerstrasse 52 */
|
||||||
|
/* D-70794 Filderstadt */
|
||||||
|
/* EMail: uz@cc65.org */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SPAN_H
|
||||||
|
#define SPAN_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "coll.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Forwards */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct Segment;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct Span Span;
|
||||||
|
struct Span {
|
||||||
|
struct Segment* Seg; /* Segment of this span */
|
||||||
|
unsigned long Offs; /* Offset of span within segment */
|
||||||
|
unsigned long Size; /* Size of span */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size);
|
||||||
|
/* Create and return a new span */
|
||||||
|
|
||||||
|
void FreeSpan (Span* S);
|
||||||
|
/* Free a span structure */
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of span.h */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user