1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-26 08:32:00 +00:00

Replace more linked lists by collections.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4793 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2010-08-08 15:13:53 +00:00
parent 026724482f
commit ad140bede4
4 changed files with 34 additions and 43 deletions

View File

@ -271,8 +271,8 @@ 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 */
{ {
Memory* M; unsigned I;
/* Place the filename in the control structure */ /* Place the filename in the control structure */
D->Filename = GetString (F->Name); D->Filename = GetString (F->Name);
@ -297,11 +297,11 @@ 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 */
M = F->MemList; for (I = 0; I < CollCount (&F->MemList); ++I) {
while (M) { /* Get this entry */
Memory* M = CollAtUnchecked (&F->MemList, I);
Print (stdout, 1, " Dumping `%s'\n", GetString (M->Name)); Print (stdout, 1, " Dumping `%s'\n", GetString (M->Name));
BinWriteMem (D, M); BinWriteMem (D, M);
M = M->FNext;
} }
/* Close the file */ /* Close the file */

View File

@ -41,7 +41,6 @@
/* common */ /* common */
#include "bitops.h" #include "bitops.h"
#include "check.h" #include "check.h"
#include "coll.h"
#include "print.h" #include "print.h"
#include "xmalloc.h" #include "xmalloc.h"
#include "xsprintf.h" #include "xsprintf.h"
@ -170,13 +169,7 @@ static void FileInsert (File* F, Memory* M)
/* Insert the memory area into the files list */ /* Insert the memory area into the files list */
{ {
M->F = F; M->F = F;
if (F->MemList == 0) { CollAppend (&F->MemList, M);
/* First entry */
F->MemList = M;
} else {
F->MemLast->FNext = M;
}
F->MemLast = M;
} }
@ -272,8 +265,7 @@ static File* NewFile (unsigned Name)
F->Name = Name; F->Name = Name;
F->Flags = 0; F->Flags = 0;
F->Format = BINFMT_DEFAULT; F->Format = BINFMT_DEFAULT;
F->MemList = 0; InitCollection (&F->MemList);
F->MemLast = 0;
/* Insert the struct into the list */ /* Insert the struct into the list */
CollAppend (&FileList, F); CollAppend (&FileList, F);
@ -298,7 +290,6 @@ static Memory* NewMemory (unsigned Name)
/* Initialize the fields */ /* Initialize the fields */
M->Name = Name; M->Name = Name;
M->FNext = 0;
M->Attr = 0; M->Attr = 0;
M->Flags = 0; M->Flags = 0;
M->Start = 0; M->Start = 0;
@ -1723,7 +1714,7 @@ void CfgWriteTarget (void)
File* F = CollAtUnchecked (&FileList, I); File* F = CollAtUnchecked (&FileList, I);
/* We don't need to look at files with no memory areas */ /* We don't need to look at files with no memory areas */
if (F->MemList) { if (CollCount (&F->MemList) > 0) {
/* Is there an output file? */ /* Is there an output file? */
if (SB_GetLen (GetStrBuf (F->Name)) > 0) { if (SB_GetLen (GetStrBuf (F->Name)) > 0) {
@ -1753,12 +1744,15 @@ void CfgWriteTarget (void)
/* No output file. Walk through the list and mark all segments /* No output file. Walk through the list and mark all segments
* loading into these memory areas in this file as dumped. * loading into these memory areas in this file as dumped.
*/ */
Memory* M = F->MemList; unsigned J;
while (M) { for (J = 0; J < CollCount (&F->MemList); ++J) {
MemListNode* N; MemListNode* N;
/* Get this entry */
Memory* M = CollAtUnchecked (&F->MemList, J);
/* Debugging */ /* Debugging */
Print (stdout, 2, "Skipping `%s'...\n", GetString (M->Name)); Print (stdout, 2, "Skipping `%s'...\n", GetString (M->Name));
@ -1773,8 +1767,6 @@ void CfgWriteTarget (void)
/* Next segment node */ /* Next segment node */
N = N->Next; N = N->Next;
} }
/* Next memory area */
M = M->FNext;
} }
} }
} }

View File

@ -38,6 +38,9 @@
/* common */
#include "coll.h"
/* ld65 */ /* ld65 */
#include "segments.h" #include "segments.h"
@ -53,10 +56,9 @@
typedef struct File File; typedef struct File File;
struct File { struct File {
unsigned Name; /* Name index of the file */ unsigned Name; /* Name index of the file */
unsigned Flags; unsigned Flags;
unsigned Format; /* Output format */ unsigned Format; /* Output format */
struct Memory* MemList; /* List of memory areas in this file */ Collection MemList; /* List of memory areas in this file */
struct Memory* MemLast; /* Last memory area in this file */
}; };
/* Segment list node. Needed because there are two lists (RUN & LOAD) */ /* Segment list node. Needed because there are two lists (RUN & LOAD) */
@ -70,7 +72,6 @@ struct MemListNode {
typedef struct Memory Memory; typedef struct Memory Memory;
struct Memory { struct Memory {
unsigned Name; /* Name index of the memory section */ unsigned Name; /* Name index of the memory section */
Memory* FNext; /* Next in file list */
unsigned Attr; /* Which values are valid? */ unsigned Attr; /* Which values are valid? */
unsigned Flags; /* Set of bitmapped flags */ unsigned Flags; /* Set of bitmapped flags */
unsigned long Start; /* Start address */ unsigned long Start; /* Start address */

View File

@ -1221,10 +1221,8 @@ 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 */
{ {
Memory* M; unsigned I;
MemListNode* N;
SegDesc* S;
unsigned TextIdx, DataIdx, BssIdx, ZPIdx; unsigned TextIdx, DataIdx, BssIdx, ZPIdx;
/* Initialize the counters */ /* Initialize the counters */
@ -1234,14 +1232,16 @@ static void O65SetupSegments (O65Desc* D, File* F)
D->ZPCount = 0; D->ZPCount = 0;
/* Walk over the memory list */ /* Walk over the memory list */
M = F->MemList; for (I = 0; I < CollCount (&F->MemList); ++I) {
while (M) { /* Get this entry */
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 */
N = M->SegList; MemListNode* N = M->SegList;
while (N) { while (N) {
/* Get the segment from the list node */ /* Get the segment from the list node */
S = N->Seg; SegDesc* S = N->Seg;
/* Check the segment type. */ /* Check the segment type. */
switch (O65SegType (S)) { switch (O65SegType (S)) {
@ -1255,8 +1255,6 @@ static void O65SetupSegments (O65Desc* D, File* F)
/* Next segment node */ /* Next segment node */
N = N->Next; N = N->Next;
} }
/* Next memory area */
M = M->FNext;
} }
/* Allocate memory according to the numbers */ /* Allocate memory according to the numbers */
@ -1267,14 +1265,16 @@ static void O65SetupSegments (O65Desc* D, File* F)
/* Walk again through the list and setup the segment arrays */ /* Walk again through the list and setup the segment arrays */
TextIdx = DataIdx = BssIdx = ZPIdx = 0; TextIdx = DataIdx = BssIdx = ZPIdx = 0;
M = F->MemList; for (I = 0; I < CollCount (&F->MemList); ++I) {
while (M) { /* Get this entry */
Memory* M = CollAtUnchecked (&F->MemList, I);
N = M->SegList; /* Walk over the segment list and check the segment types */
MemListNode* N = M->SegList;
while (N) { while (N) {
/* Get the segment from the list node */ /* Get the segment from the list node */
S = N->Seg; SegDesc* S = N->Seg;
/* Check the segment type. */ /* Check the segment type. */
switch (O65SegType (S)) { switch (O65SegType (S)) {
@ -1288,8 +1288,6 @@ static void O65SetupSegments (O65Desc* D, File* F)
/* Next segment node */ /* Next segment node */
N = N->Next; N = N->Next;
} }
/* Next memory area */
M = M->FNext;
} }
} }