More collection usage. This has also removed the need for the MemListNode
structure. git-svn-id: svn://svn.cc65.org/cc65/trunk@4795 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -135,14 +135,14 @@ static void BinWriteMem (BinDesc* D, Memory* M)
|
|||||||
/* Get the start address of this memory area */
|
/* Get the start address of this memory area */
|
||||||
unsigned long Addr = M->Start;
|
unsigned long Addr = M->Start;
|
||||||
|
|
||||||
/* Get a pointer to the first segment node */
|
/* Walk over all segments in this memory area */
|
||||||
MemListNode* N = M->SegList;
|
unsigned I;
|
||||||
while (N) {
|
for (I = 0; I < CollCount (&M->SegList); ++I) {
|
||||||
|
|
||||||
int DoWrite;
|
int DoWrite;
|
||||||
|
|
||||||
/* Get the segment from the list node */
|
/* Get the segment */
|
||||||
SegDesc* S = N->Seg;
|
SegDesc* S = CollAtUnchecked (&M->SegList, I);
|
||||||
|
|
||||||
/* Keep the user happy */
|
/* Keep the user happy */
|
||||||
Print (stdout, 1, " Writing `%s'\n", GetString (S->Name));
|
Print (stdout, 1, " Writing `%s'\n", GetString (S->Name));
|
||||||
@@ -239,9 +239,6 @@ static void BinWriteMem (BinDesc* D, Memory* M)
|
|||||||
|
|
||||||
/* Calculate the new address */
|
/* Calculate the new address */
|
||||||
Addr += S->Seg->Size;
|
Addr += S->Seg->Size;
|
||||||
|
|
||||||
/* Next segment node */
|
|
||||||
N = N->Next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If a fill was requested, fill the remaining space */
|
/* If a fill was requested, fill the remaining space */
|
||||||
@@ -271,7 +268,7 @@ static int BinUnresolved (unsigned Name attribute ((unused)), void* D)
|
|||||||
|
|
||||||
void BinWriteTarget (BinDesc* D, struct File* F)
|
void BinWriteTarget (BinDesc* D, struct File* F)
|
||||||
/* Write a binary output file */
|
/* Write a binary output file */
|
||||||
{
|
{
|
||||||
unsigned I;
|
unsigned I;
|
||||||
|
|
||||||
/* Place the filename in the control structure */
|
/* Place the filename in the control structure */
|
||||||
@@ -297,7 +294,7 @@ void BinWriteTarget (BinDesc* D, struct File* F)
|
|||||||
Print (stdout, 1, "Opened `%s'...\n", D->Filename);
|
Print (stdout, 1, "Opened `%s'...\n", D->Filename);
|
||||||
|
|
||||||
/* Dump all memory areas */
|
/* Dump all memory areas */
|
||||||
for (I = 0; I < CollCount (&F->MemList); ++I) {
|
for (I = 0; I < CollCount (&F->MemList); ++I) {
|
||||||
/* Get this entry */
|
/* Get this entry */
|
||||||
Memory* M = CollAtUnchecked (&F->MemList, I);
|
Memory* M = CollAtUnchecked (&F->MemList, I);
|
||||||
Print (stdout, 1, " Dumping `%s'\n", GetString (M->Name));
|
Print (stdout, 1, " Dumping `%s'\n", GetString (M->Name));
|
||||||
|
|||||||
@@ -230,18 +230,8 @@ static void SegDescInsert (SegDesc* S)
|
|||||||
static void MemoryInsert (Memory* M, SegDesc* S)
|
static void MemoryInsert (Memory* M, SegDesc* S)
|
||||||
/* Insert the segment descriptor into the memory area list */
|
/* Insert the segment descriptor into the memory area list */
|
||||||
{
|
{
|
||||||
/* Create a new node for the entry */
|
/* Insert the segment into the segment list of the memory area */
|
||||||
MemListNode* N = xmalloc (sizeof (MemListNode));
|
CollAppend (&M->SegList, S);
|
||||||
N->Seg = S;
|
|
||||||
N->Next = 0;
|
|
||||||
|
|
||||||
if (M->SegLast == 0) {
|
|
||||||
/* First entry */
|
|
||||||
M->SegList = N;
|
|
||||||
} else {
|
|
||||||
M->SegLast->Next = N;
|
|
||||||
}
|
|
||||||
M->SegLast = N;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -294,8 +284,7 @@ static Memory* NewMemory (unsigned Name)
|
|||||||
M->FillLevel = 0;
|
M->FillLevel = 0;
|
||||||
M->FillVal = 0;
|
M->FillVal = 0;
|
||||||
M->Relocatable = 0;
|
M->Relocatable = 0;
|
||||||
M->SegList = 0;
|
InitCollection (&M->SegList);
|
||||||
M->SegLast = 0;
|
|
||||||
M->F = 0;
|
M->F = 0;
|
||||||
|
|
||||||
/* Insert the struct into the list */
|
/* Insert the struct into the list */
|
||||||
@@ -1576,7 +1565,7 @@ unsigned CfgAssignSegments (void)
|
|||||||
unsigned I;
|
unsigned I;
|
||||||
for (I = 0; I < CollCount (&MemoryList); ++I) {
|
for (I = 0; I < CollCount (&MemoryList); ++I) {
|
||||||
|
|
||||||
MemListNode* N;
|
unsigned J;
|
||||||
|
|
||||||
/* Get this entry */
|
/* Get this entry */
|
||||||
Memory* M = CollAtUnchecked (&MemoryList, I);
|
Memory* M = CollAtUnchecked (&MemoryList, I);
|
||||||
@@ -1588,11 +1577,10 @@ unsigned CfgAssignSegments (void)
|
|||||||
M->Relocatable = RelocatableBinFmt (M->F->Format);
|
M->Relocatable = RelocatableBinFmt (M->F->Format);
|
||||||
|
|
||||||
/* Walk through the segments in this memory area */
|
/* Walk through the segments in this memory area */
|
||||||
N = M->SegList;
|
for (J = 0; J < CollCount (&M->SegList); ++J) {
|
||||||
while (N) {
|
|
||||||
|
|
||||||
/* Get the segment from the node */
|
/* Get the segment */
|
||||||
SegDesc* S = N->Seg;
|
SegDesc* S = CollAtUnchecked (&M->SegList, J);
|
||||||
|
|
||||||
/* Some actions depend on wether this is the load or run memory
|
/* Some actions depend on wether this is the load or run memory
|
||||||
* area.
|
* area.
|
||||||
@@ -1674,8 +1662,6 @@ unsigned CfgAssignSegments (void)
|
|||||||
/* Calculate the new address */
|
/* Calculate the new address */
|
||||||
Addr += S->Seg->Size;
|
Addr += S->Seg->Size;
|
||||||
|
|
||||||
/* Next segment */
|
|
||||||
N = N->Next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If requested, define symbols for start and size of the memory area */
|
/* If requested, define symbols for start and size of the memory area */
|
||||||
@@ -1744,7 +1730,7 @@ void CfgWriteTarget (void)
|
|||||||
unsigned J;
|
unsigned J;
|
||||||
for (J = 0; J < CollCount (&F->MemList); ++J) {
|
for (J = 0; J < CollCount (&F->MemList); ++J) {
|
||||||
|
|
||||||
MemListNode* N;
|
unsigned K;
|
||||||
|
|
||||||
/* Get this entry */
|
/* Get this entry */
|
||||||
Memory* M = CollAtUnchecked (&F->MemList, J);
|
Memory* M = CollAtUnchecked (&F->MemList, J);
|
||||||
@@ -1753,15 +1739,12 @@ void CfgWriteTarget (void)
|
|||||||
Print (stdout, 2, "Skipping `%s'...\n", GetString (M->Name));
|
Print (stdout, 2, "Skipping `%s'...\n", GetString (M->Name));
|
||||||
|
|
||||||
/* Walk throught the segments */
|
/* Walk throught the segments */
|
||||||
N = M->SegList;
|
for (K = 0; K < CollCount (&M->SegList); ++K) {
|
||||||
while (N) {
|
SegDesc* S = CollAtUnchecked (&M->SegList, K);
|
||||||
if (N->Seg->Load == M) {
|
if (S->Load == M) {
|
||||||
/* Load area - mark the segment as dumped */
|
/* Load area - mark the segment as dumped */
|
||||||
N->Seg->Seg->Dumped = 1;
|
S->Seg->Dumped = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next segment node */
|
|
||||||
N = N->Next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,13 +61,6 @@ struct File {
|
|||||||
Collection MemList; /* List of memory areas in this file */
|
Collection MemList; /* List of memory areas in this file */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Segment list node. Needed because there are two lists (RUN & LOAD) */
|
|
||||||
typedef struct MemListNode MemListNode;
|
|
||||||
struct MemListNode {
|
|
||||||
MemListNode* Next; /* Next entry */
|
|
||||||
struct SegDesc* Seg; /* Segment */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Memory list entry */
|
/* Memory list entry */
|
||||||
typedef struct Memory Memory;
|
typedef struct Memory Memory;
|
||||||
struct Memory {
|
struct Memory {
|
||||||
@@ -79,8 +72,7 @@ struct Memory {
|
|||||||
unsigned long FillLevel; /* Actual fill level of segment */
|
unsigned long FillLevel; /* Actual fill level of segment */
|
||||||
unsigned char FillVal; /* Value used to fill rest of seg */
|
unsigned char FillVal; /* Value used to fill rest of seg */
|
||||||
unsigned char Relocatable; /* Memory area is relocatable */
|
unsigned char Relocatable; /* Memory area is relocatable */
|
||||||
MemListNode* SegList; /* List of segments for this section */
|
Collection SegList; /* List of segments for this section */
|
||||||
MemListNode* SegLast; /* Last segment in this section */
|
|
||||||
File* F; /* File that contains the entry */
|
File* F; /* File that contains the entry */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -246,18 +246,16 @@ static void CvtMemoryToSegment (ExprDesc* ED)
|
|||||||
/* Get the memory area from the expression */
|
/* Get the memory area from the expression */
|
||||||
Memory* M = ED->MemRef;
|
Memory* M = ED->MemRef;
|
||||||
|
|
||||||
/* Get the list of segments in this memory area */
|
|
||||||
MemListNode* N = M->SegList;
|
|
||||||
|
|
||||||
/* Remember the "nearest" segment and its offset */
|
/* Remember the "nearest" segment and its offset */
|
||||||
Segment* Nearest = 0;
|
Segment* Nearest = 0;
|
||||||
unsigned long Offs = ULONG_MAX;
|
unsigned long Offs = ULONG_MAX;
|
||||||
|
|
||||||
/* Walk over all segments */
|
/* Walk over all segments */
|
||||||
while (N != 0) {
|
unsigned I;
|
||||||
|
for (I = 0; I < CollCount (&M->SegList); ++I) {
|
||||||
|
|
||||||
/* Get the segment from this node and check if it's a run segment */
|
/* Get the segment and check if it's a run segment */
|
||||||
SegDesc* S = N->Seg;
|
SegDesc* S = CollAtUnchecked (&M->SegList, I);
|
||||||
if (S->Run == M) {
|
if (S->Run == M) {
|
||||||
|
|
||||||
unsigned long O;
|
unsigned long O;
|
||||||
@@ -277,9 +275,6 @@ static void CvtMemoryToSegment (ExprDesc* ED)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next segment */
|
|
||||||
N = N->Next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we found a segment, use it and adjust the offset */
|
/* If we found a segment, use it and adjust the offset */
|
||||||
@@ -1221,7 +1216,7 @@ void O65SetExport (O65Desc* D, unsigned Ident)
|
|||||||
|
|
||||||
static void O65SetupSegments (O65Desc* D, File* F)
|
static void O65SetupSegments (O65Desc* D, File* F)
|
||||||
/* Setup segment assignments */
|
/* Setup segment assignments */
|
||||||
{
|
{
|
||||||
unsigned I;
|
unsigned I;
|
||||||
unsigned TextIdx, DataIdx, BssIdx, ZPIdx;
|
unsigned TextIdx, DataIdx, BssIdx, ZPIdx;
|
||||||
|
|
||||||
@@ -1237,11 +1232,11 @@ static void O65SetupSegments (O65Desc* D, File* F)
|
|||||||
Memory* M = CollAtUnchecked (&F->MemList, I);
|
Memory* M = CollAtUnchecked (&F->MemList, I);
|
||||||
|
|
||||||
/* Walk through the segment list and count the segment types */
|
/* Walk through the segment list and count the segment types */
|
||||||
MemListNode* N = M->SegList;
|
unsigned J;
|
||||||
while (N) {
|
for (J = 0; J < CollCount (&M->SegList); ++J) {
|
||||||
|
|
||||||
/* Get the segment from the list node */
|
/* Get the segment */
|
||||||
SegDesc* S = N->Seg;
|
SegDesc* S = CollAtUnchecked (&M->SegList, J);
|
||||||
|
|
||||||
/* Check the segment type. */
|
/* Check the segment type. */
|
||||||
switch (O65SegType (S)) {
|
switch (O65SegType (S)) {
|
||||||
@@ -1249,11 +1244,8 @@ static void O65SetupSegments (O65Desc* D, File* F)
|
|||||||
case O65SEG_DATA: D->DataCount++; break;
|
case O65SEG_DATA: D->DataCount++; break;
|
||||||
case O65SEG_BSS: D->BssCount++; break;
|
case O65SEG_BSS: D->BssCount++; break;
|
||||||
case O65SEG_ZP: D->ZPCount++; break;
|
case O65SEG_ZP: D->ZPCount++; break;
|
||||||
default: Internal ("Invalid return from O65SegType");
|
default: Internal ("Invalid return from O65SegType");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next segment node */
|
|
||||||
N = N->Next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1270,11 +1262,11 @@ static void O65SetupSegments (O65Desc* D, File* F)
|
|||||||
Memory* M = CollAtUnchecked (&F->MemList, I);
|
Memory* M = CollAtUnchecked (&F->MemList, I);
|
||||||
|
|
||||||
/* Walk over the segment list and check the segment types */
|
/* Walk over the segment list and check the segment types */
|
||||||
MemListNode* N = M->SegList;
|
unsigned J;
|
||||||
while (N) {
|
for (J = 0; J < CollCount (&M->SegList); ++J) {
|
||||||
|
|
||||||
/* Get the segment from the list node */
|
/* Get the segment */
|
||||||
SegDesc* S = N->Seg;
|
SegDesc* S = CollAtUnchecked (&M->SegList, J);
|
||||||
|
|
||||||
/* Check the segment type. */
|
/* Check the segment type. */
|
||||||
switch (O65SegType (S)) {
|
switch (O65SegType (S)) {
|
||||||
@@ -1284,9 +1276,6 @@ static void O65SetupSegments (O65Desc* D, File* F)
|
|||||||
case O65SEG_ZP: D->ZPSeg [ZPIdx++] = S; break;
|
case O65SEG_ZP: D->ZPSeg [ZPIdx++] = S; break;
|
||||||
default: Internal ("Invalid return from O65SegType");
|
default: Internal ("Invalid return from O65SegType");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next segment node */
|
|
||||||
N = N->Next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user