From: uz Date: Sun, 8 Aug 2010 15:35:56 +0000 (+0000) Subject: More collection usage. This has also removed the need for the MemListNode X-Git-Tag: V2.13.3~656 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=34c938e7ac0903d2131b4e10a6c6a3e235f26ed8;p=cc65 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 --- diff --git a/src/ld65/bin.c b/src/ld65/bin.c index f2d46f0ec..df8991305 100644 --- a/src/ld65/bin.c +++ b/src/ld65/bin.c @@ -135,14 +135,14 @@ static void BinWriteMem (BinDesc* D, Memory* M) /* Get the start address of this memory area */ unsigned long Addr = M->Start; - /* Get a pointer to the first segment node */ - MemListNode* N = M->SegList; - while (N) { + /* Walk over all segments in this memory area */ + unsigned I; + for (I = 0; I < CollCount (&M->SegList); ++I) { int DoWrite; - /* Get the segment from the list node */ - SegDesc* S = N->Seg; + /* Get the segment */ + SegDesc* S = CollAtUnchecked (&M->SegList, I); /* Keep the user happy */ Print (stdout, 1, " Writing `%s'\n", GetString (S->Name)); @@ -239,9 +239,6 @@ static void BinWriteMem (BinDesc* D, Memory* M) /* Calculate the new address */ Addr += S->Seg->Size; - - /* Next segment node */ - N = N->Next; } /* 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) /* Write a binary output file */ -{ +{ unsigned I; /* 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); /* Dump all memory areas */ - for (I = 0; I < CollCount (&F->MemList); ++I) { + 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)); diff --git a/src/ld65/config.c b/src/ld65/config.c index 04caa0954..0dae0bc73 100644 --- a/src/ld65/config.c +++ b/src/ld65/config.c @@ -230,18 +230,8 @@ static void SegDescInsert (SegDesc* S) static void MemoryInsert (Memory* M, SegDesc* S) /* Insert the segment descriptor into the memory area list */ { - /* Create a new node for the entry */ - MemListNode* N = xmalloc (sizeof (MemListNode)); - N->Seg = S; - N->Next = 0; - - if (M->SegLast == 0) { - /* First entry */ - M->SegList = N; - } else { - M->SegLast->Next = N; - } - M->SegLast = N; + /* Insert the segment into the segment list of the memory area */ + CollAppend (&M->SegList, S); } @@ -294,8 +284,7 @@ static Memory* NewMemory (unsigned Name) M->FillLevel = 0; M->FillVal = 0; M->Relocatable = 0; - M->SegList = 0; - M->SegLast = 0; + InitCollection (&M->SegList); M->F = 0; /* Insert the struct into the list */ @@ -1576,7 +1565,7 @@ unsigned CfgAssignSegments (void) unsigned I; for (I = 0; I < CollCount (&MemoryList); ++I) { - MemListNode* N; + unsigned J; /* Get this entry */ Memory* M = CollAtUnchecked (&MemoryList, I); @@ -1588,11 +1577,10 @@ unsigned CfgAssignSegments (void) M->Relocatable = RelocatableBinFmt (M->F->Format); /* Walk through the segments in this memory area */ - N = M->SegList; - while (N) { + for (J = 0; J < CollCount (&M->SegList); ++J) { - /* Get the segment from the node */ - SegDesc* S = N->Seg; + /* Get the segment */ + SegDesc* S = CollAtUnchecked (&M->SegList, J); /* Some actions depend on wether this is the load or run memory * area. @@ -1674,8 +1662,6 @@ unsigned CfgAssignSegments (void) /* Calculate the new address */ Addr += S->Seg->Size; - /* Next segment */ - N = N->Next; } /* If requested, define symbols for start and size of the memory area */ @@ -1744,7 +1730,7 @@ void CfgWriteTarget (void) unsigned J; for (J = 0; J < CollCount (&F->MemList); ++J) { - MemListNode* N; + unsigned K; /* Get this entry */ Memory* M = CollAtUnchecked (&F->MemList, J); @@ -1753,15 +1739,12 @@ void CfgWriteTarget (void) Print (stdout, 2, "Skipping `%s'...\n", GetString (M->Name)); /* Walk throught the segments */ - N = M->SegList; - while (N) { - if (N->Seg->Load == M) { + for (K = 0; K < CollCount (&M->SegList); ++K) { + SegDesc* S = CollAtUnchecked (&M->SegList, K); + if (S->Load == M) { /* Load area - mark the segment as dumped */ - N->Seg->Seg->Dumped = 1; + S->Seg->Dumped = 1; } - - /* Next segment node */ - N = N->Next; } } } diff --git a/src/ld65/config.h b/src/ld65/config.h index 3693d76ac..aa455da00 100644 --- a/src/ld65/config.h +++ b/src/ld65/config.h @@ -61,13 +61,6 @@ struct 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 */ typedef struct Memory Memory; struct Memory { @@ -79,8 +72,7 @@ struct Memory { unsigned long FillLevel; /* Actual fill level of segment */ unsigned char FillVal; /* Value used to fill rest of seg */ unsigned char Relocatable; /* Memory area is relocatable */ - MemListNode* SegList; /* List of segments for this section */ - MemListNode* SegLast; /* Last segment in this section */ + Collection SegList; /* List of segments for this section */ File* F; /* File that contains the entry */ }; diff --git a/src/ld65/o65.c b/src/ld65/o65.c index bc2ae6f61..7dbcd8f9b 100644 --- a/src/ld65/o65.c +++ b/src/ld65/o65.c @@ -246,18 +246,16 @@ static void CvtMemoryToSegment (ExprDesc* ED) /* Get the memory area from the expression */ Memory* M = ED->MemRef; - /* Get the list of segments in this memory area */ - MemListNode* N = M->SegList; - /* Remember the "nearest" segment and its offset */ Segment* Nearest = 0; unsigned long Offs = ULONG_MAX; /* 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 */ - SegDesc* S = N->Seg; + /* Get the segment and check if it's a run segment */ + SegDesc* S = CollAtUnchecked (&M->SegList, I); if (S->Run == M) { 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 */ @@ -1221,7 +1216,7 @@ void O65SetExport (O65Desc* D, unsigned Ident) static void O65SetupSegments (O65Desc* D, File* F) /* Setup segment assignments */ -{ +{ unsigned I; unsigned TextIdx, DataIdx, BssIdx, ZPIdx; @@ -1237,11 +1232,11 @@ static void O65SetupSegments (O65Desc* D, File* F) Memory* M = CollAtUnchecked (&F->MemList, I); /* Walk through the segment list and count the segment types */ - MemListNode* N = M->SegList; - while (N) { + unsigned J; + for (J = 0; J < CollCount (&M->SegList); ++J) { - /* Get the segment from the list node */ - SegDesc* S = N->Seg; + /* Get the segment */ + SegDesc* S = CollAtUnchecked (&M->SegList, J); /* Check the segment type. */ switch (O65SegType (S)) { @@ -1249,11 +1244,8 @@ static void O65SetupSegments (O65Desc* D, File* F) case O65SEG_DATA: D->DataCount++; break; case O65SEG_BSS: D->BssCount++; 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); /* Walk over the segment list and check the segment types */ - MemListNode* N = M->SegList; - while (N) { + unsigned J; + for (J = 0; J < CollCount (&M->SegList); ++J) { - /* Get the segment from the list node */ - SegDesc* S = N->Seg; + /* Get the segment */ + SegDesc* S = CollAtUnchecked (&M->SegList, J); /* Check the segment type. */ switch (O65SegType (S)) { @@ -1284,9 +1276,6 @@ static void O65SetupSegments (O65Desc* D, File* F) case O65SEG_ZP: D->ZPSeg [ZPIdx++] = S; break; default: Internal ("Invalid return from O65SegType"); } - - /* Next segment node */ - N = N->Next; } } }