1
0
mirror of https://github.com/cc65/cc65.git synced 2025-03-04 00:30:35 +00:00

Replace single linked list of sections in a segment by a collection.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5208 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-18 11:58:16 +00:00
parent 2abd77ffe5
commit d3017665d2
2 changed files with 19 additions and 27 deletions

View File

@ -92,8 +92,7 @@ static Segment* NewSegment (unsigned Name, unsigned char AddrSize)
/* Initialize the fields */ /* Initialize the fields */
S->Name = Name; S->Name = Name;
S->Next = 0; S->Next = 0;
S->SecRoot = 0; S->Sections = EmptyCollection;
S->SecLast = 0;
S->PC = 0; S->PC = 0;
S->Size = 0; S->Size = 0;
S->AlignObj = 0; S->AlignObj = 0;
@ -183,13 +182,7 @@ Section* NewSection (Segment* Seg, unsigned char Align, unsigned char AddrSize)
S->Offs = Seg->Size; /* Current size is offset */ S->Offs = Seg->Size; /* Current size is offset */
/* Insert the section into the segment */ /* Insert the section into the segment */
if (Seg->SecRoot == 0) { CollAppend (&Seg->Sections, S);
/* First section in this segment */
Seg->SecRoot = S;
} else {
Seg->SecLast->Next = S;
}
Seg->SecLast = S;
/* Return the struct */ /* Return the struct */
return S; return S;
@ -311,8 +304,12 @@ int IsBSSType (Segment* S)
*/ */
{ {
/* Loop over all sections */ /* Loop over all sections */
Section* Sec = S->SecRoot; unsigned I;
while (Sec) { for (I = 0; I < CollCount (&S->Sections); ++I) {
/* Get the next section */
Section* Sec = CollAtUnchecked (&S->Sections, I);
/* Loop over all fragments */ /* Loop over all fragments */
Fragment* F = Sec->FragRoot; Fragment* F = Sec->FragRoot;
while (F) { while (F) {
@ -331,7 +328,6 @@ int IsBSSType (Segment* S)
} }
F = F->Next; F = F->Next;
} }
Sec = Sec->Next;
} }
return 1; return 1;
} }
@ -341,15 +337,15 @@ int IsBSSType (Segment* S)
void SegDump (void) void SegDump (void)
/* Dump the segments and it's contents */ /* Dump the segments and it's contents */
{ {
unsigned I; unsigned I, J;
unsigned long Count; unsigned long Count;
unsigned char* Data; unsigned char* Data;
for (I = 0; I < CollCount (&SegmentList); ++I) { for (I = 0; I < CollCount (&SegmentList); ++I) {
const Segment* Seg = CollConstAt (&SegmentList, I); Segment* Seg = CollAtUnchecked (&SegmentList, I);
Section* S = Seg->SecRoot;
printf ("Segment: %s (%lu)\n", GetString (Seg->Name), Seg->Size); printf ("Segment: %s (%lu)\n", GetString (Seg->Name), Seg->Size);
while (S) { for (J = 0; J < CollCount (&Seg->Sections); ++J) {
Section* S = CollAtUnchecked (&Seg->Sections, J);
unsigned J; unsigned J;
Fragment* F = S->FragRoot; Fragment* F = S->FragRoot;
printf (" Section:\n"); printf (" Section:\n");
@ -393,7 +389,6 @@ void SegDump (void)
} }
F = F->Next; F = F->Next;
} }
S = S->Next;
} }
} }
} }
@ -449,7 +444,7 @@ void SegWrite (const char* TgtName, FILE* Tgt, Segment* S, SegWriteFunc F, void*
* called (see description of SegWriteFunc above). * called (see description of SegWriteFunc above).
*/ */
{ {
Section* Sec; unsigned I;
int Sign; int Sign;
unsigned long Offs = 0; unsigned long Offs = 0;
@ -459,8 +454,8 @@ void SegWrite (const char* TgtName, FILE* Tgt, Segment* S, SegWriteFunc F, void*
S->OutputOffs = (unsigned long) ftell (Tgt); S->OutputOffs = (unsigned long) ftell (Tgt);
/* Loop over all sections in this segment */ /* Loop over all sections in this segment */
Sec = S->SecRoot; for (I = 0; I < CollCount (&S->Sections); ++I) {
while (Sec) { Section* Sec = CollAtUnchecked (&S->Sections, I);
Fragment* Frag; Fragment* Frag;
/* Output were this section is from */ /* Output were this section is from */
@ -535,9 +530,6 @@ void SegWrite (const char* TgtName, FILE* Tgt, Segment* S, SegWriteFunc F, void*
/* Next fragment */ /* Next fragment */
Frag = Frag->Next; Frag = Frag->Next;
} }
/* Next section */
Sec = Sec->Next;
} }
} }

View File

@ -41,6 +41,7 @@
#include <stdio.h> #include <stdio.h>
/* common */ /* common */
#include "coll.h"
#include "exprdefs.h" #include "exprdefs.h"
@ -57,8 +58,7 @@ struct Segment {
unsigned Name; /* Name index of the segment */ unsigned Name; /* Name index of the segment */
unsigned Id; /* Segment id for debug info */ unsigned Id; /* Segment id for debug info */
Segment* Next; /* Hash list */ Segment* Next; /* Hash list */
struct Section* SecRoot; /* Section list */ Collection Sections; /* Sections in this segment */
struct Section* SecLast; /* Pointer to last section */
unsigned long PC; /* PC were this segment is located */ unsigned long PC; /* PC were this segment is located */
unsigned long Size; /* Size of data so far */ unsigned long Size; /* Size of data so far */
struct ObjData* AlignObj; /* Module that requested the alignment */ struct ObjData* AlignObj; /* Module that requested the alignment */