diff --git a/src/ld65/bin.c b/src/ld65/bin.c index c5386114a..f2d46f0ec 100644 --- a/src/ld65/bin.c +++ b/src/ld65/bin.c @@ -271,8 +271,8 @@ static int BinUnresolved (unsigned Name attribute ((unused)), void* D) void BinWriteTarget (BinDesc* D, struct File* F) /* Write a binary output file */ -{ - Memory* M; +{ + unsigned I; /* Place the filename in the control structure */ D->Filename = GetString (F->Name); @@ -297,11 +297,11 @@ void BinWriteTarget (BinDesc* D, struct File* F) Print (stdout, 1, "Opened `%s'...\n", D->Filename); /* Dump all memory areas */ - M = F->MemList; - while (M) { + for (I = 0; I < CollCount (&F->MemList); ++I) { + /* Get this entry */ + Memory* M = CollAtUnchecked (&F->MemList, I); Print (stdout, 1, " Dumping `%s'\n", GetString (M->Name)); BinWriteMem (D, M); - M = M->FNext; } /* Close the file */ diff --git a/src/ld65/config.c b/src/ld65/config.c index e5533bdd6..d54e1f632 100644 --- a/src/ld65/config.c +++ b/src/ld65/config.c @@ -41,7 +41,6 @@ /* common */ #include "bitops.h" #include "check.h" -#include "coll.h" #include "print.h" #include "xmalloc.h" #include "xsprintf.h" @@ -170,13 +169,7 @@ static void FileInsert (File* F, Memory* M) /* Insert the memory area into the files list */ { M->F = F; - if (F->MemList == 0) { - /* First entry */ - F->MemList = M; - } else { - F->MemLast->FNext = M; - } - F->MemLast = M; + CollAppend (&F->MemList, M); } @@ -272,8 +265,7 @@ static File* NewFile (unsigned Name) F->Name = Name; F->Flags = 0; F->Format = BINFMT_DEFAULT; - F->MemList = 0; - F->MemLast = 0; + InitCollection (&F->MemList); /* Insert the struct into the list */ CollAppend (&FileList, F); @@ -298,7 +290,6 @@ static Memory* NewMemory (unsigned Name) /* Initialize the fields */ M->Name = Name; - M->FNext = 0; M->Attr = 0; M->Flags = 0; M->Start = 0; @@ -1723,7 +1714,7 @@ void CfgWriteTarget (void) File* F = CollAtUnchecked (&FileList, I); /* 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? */ 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 * loading into these memory areas in this file as dumped. - */ - Memory* M = F->MemList; - while (M) { + */ + unsigned J; + for (J = 0; J < CollCount (&F->MemList); ++J) { MemListNode* N; + /* Get this entry */ + Memory* M = CollAtUnchecked (&F->MemList, J); + /* Debugging */ Print (stdout, 2, "Skipping `%s'...\n", GetString (M->Name)); @@ -1773,8 +1767,6 @@ void CfgWriteTarget (void) /* Next segment node */ N = N->Next; } - /* Next memory area */ - M = M->FNext; } } } diff --git a/src/ld65/config.h b/src/ld65/config.h index eae3a1d81..49fe786bb 100644 --- a/src/ld65/config.h +++ b/src/ld65/config.h @@ -38,6 +38,9 @@ +/* common */ +#include "coll.h" + /* ld65 */ #include "segments.h" @@ -53,10 +56,9 @@ typedef struct File File; struct File { unsigned Name; /* Name index of the file */ - unsigned Flags; - unsigned Format; /* Output format */ - struct Memory* MemList; /* List of memory areas in this file */ - struct Memory* MemLast; /* Last memory area in this file */ + unsigned Flags; + unsigned Format; /* Output format */ + Collection MemList; /* List of memory areas in this file */ }; /* Segment list node. Needed because there are two lists (RUN & LOAD) */ @@ -70,7 +72,6 @@ struct MemListNode { typedef struct Memory Memory; struct Memory { unsigned Name; /* Name index of the memory section */ - Memory* FNext; /* Next in file list */ unsigned Attr; /* Which values are valid? */ unsigned Flags; /* Set of bitmapped flags */ unsigned long Start; /* Start address */ diff --git a/src/ld65/o65.c b/src/ld65/o65.c index 87d3bc7d6..bc2ae6f61 100644 --- a/src/ld65/o65.c +++ b/src/ld65/o65.c @@ -1221,10 +1221,8 @@ void O65SetExport (O65Desc* D, unsigned Ident) static void O65SetupSegments (O65Desc* D, File* F) /* Setup segment assignments */ -{ - Memory* M; - MemListNode* N; - SegDesc* S; +{ + unsigned I; unsigned TextIdx, DataIdx, BssIdx, ZPIdx; /* Initialize the counters */ @@ -1234,14 +1232,16 @@ static void O65SetupSegments (O65Desc* D, File* F) D->ZPCount = 0; /* Walk over the memory list */ - M = F->MemList; - while (M) { + for (I = 0; I < CollCount (&F->MemList); ++I) { + /* Get this entry */ + Memory* M = CollAtUnchecked (&F->MemList, I); + /* Walk through the segment list and count the segment types */ - N = M->SegList; + MemListNode* N = M->SegList; while (N) { /* Get the segment from the list node */ - S = N->Seg; + SegDesc* S = N->Seg; /* Check the segment type. */ switch (O65SegType (S)) { @@ -1255,8 +1255,6 @@ static void O65SetupSegments (O65Desc* D, File* F) /* Next segment node */ N = N->Next; } - /* Next memory area */ - M = M->FNext; } /* 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 */ TextIdx = DataIdx = BssIdx = ZPIdx = 0; - M = F->MemList; - while (M) { + for (I = 0; I < CollCount (&F->MemList); ++I) { + /* 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) { /* Get the segment from the list node */ - S = N->Seg; + SegDesc* S = N->Seg; /* Check the segment type. */ switch (O65SegType (S)) { @@ -1288,8 +1288,6 @@ static void O65SetupSegments (O65Desc* D, File* F) /* Next segment node */ N = N->Next; } - /* Next memory area */ - M = M->FNext; } }