From: uz Date: Fri, 30 Jul 2010 20:58:51 +0000 (+0000) Subject: Use collections in the object file structure instead of managing the items X-Git-Tag: V2.13.3~678 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f308a3c4d1d8dc4e03b6b3545fec82d02b0bca1c;p=cc65 Use collections in the object file structure instead of managing the items manually. git-svn-id: svn://svn.cc65.org/cc65/trunk@4773 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ld65/dbginfo.c b/src/ld65/dbginfo.c index e2725b4fd..8af831ba3 100644 --- a/src/ld65/dbginfo.c +++ b/src/ld65/dbginfo.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2001-2008 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2001-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -53,17 +53,17 @@ void PrintDbgInfo (ObjData* O, FILE* F) unsigned I, J; /* Output the files section */ - for (I = 0; I < O->FileCount; ++I) { - const FileInfo* FI = O->Files[I]; + for (I = 0; I < CollCount (&O->Files); ++I) { + const FileInfo* FI = CollConstAt (&O->Files, I); fprintf (F, "file\t\"%s\",size=%lu,mtime=0x%08lX\n", GetString (FI->Name), FI->Size, FI->MTime); } /* Output the line infos */ - for (I = 0; I < O->LineInfoCount; ++I) { + for (I = 0; I < CollCount (&O->LineInfos); ++I) { /* Get this line info */ - const LineInfo* LI = O->LineInfos[I]; + const LineInfo* LI = CollConstAt (&O->LineInfos, I); /* Get a pointer to the code ranges */ const Collection* CodeRanges = &LI->CodeRanges; diff --git a/src/ld65/dbgsyms.c b/src/ld65/dbgsyms.c index 661ced084..f52e082d7 100644 --- a/src/ld65/dbgsyms.c +++ b/src/ld65/dbgsyms.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2008 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -82,7 +82,7 @@ static DbgSym* NewDbgSym (unsigned char Type, unsigned char AddrSize, ObjData* O D->Flags = 0; D->Obj = O; D->Expr = 0; - D->Name = 0; + D->Name = 0; D->Type = Type; D->AddrSize = AddrSize; @@ -99,9 +99,9 @@ static DbgSym* GetDbgSym (DbgSym* D, long Val) { /* Create the hash. We hash over the symbol value */ unsigned Hash = ((Val >> 24) & 0xFF) ^ - ((Val >> 16) & 0xFF) ^ - ((Val >> 8) & 0xFF) ^ - ((Val >> 0) & 0xFF); + ((Val >> 16) & 0xFF) ^ + ((Val >> 8) & 0xFF) ^ + ((Val >> 0) & 0xFF); /* Check for this symbol */ DbgSym* Sym = DbgSymPool[Hash]; @@ -184,7 +184,7 @@ void ClearDbgSymTable (void) -long GetDbgSymVal (DbgSym* D) +long GetDbgSymVal (const DbgSym* D) /* Get the value of this symbol */ { CHECK (D->Expr != 0); @@ -199,12 +199,12 @@ void PrintDbgSyms (ObjData* O, FILE* F) unsigned I; /* Walk through all debug symbols in this module */ - for (I = 0; I < O->DbgSymCount; ++I) { + for (I = 0; I < CollCount (&O->DbgSyms); ++I) { long Val; /* Get the next debug symbol */ - DbgSym* D = O->DbgSyms [I]; + DbgSym* D = CollAt (&O->DbgSyms, I); /* Get the symbol value */ Val = GetDbgSymVal (D); @@ -237,12 +237,12 @@ void PrintDbgSymLabels (ObjData* O, FILE* F) unsigned I; /* Walk through all debug symbols in this module */ - for (I = 0; I < O->DbgSymCount; ++I) { + for (I = 0; I < CollCount (&O->DbgSyms); ++I) { long Val; /* Get the next debug symbol */ - DbgSym* D = O->DbgSyms [I]; + DbgSym* D = CollAt (&O->DbgSyms, I); /* Emit this symbol only if it is a label (ignore equates) */ if (IS_EXP_EQUATE (D->Type)) { diff --git a/src/ld65/dbgsyms.h b/src/ld65/dbgsyms.h index 6a3e5cfa6..5ad169453 100644 --- a/src/ld65/dbgsyms.h +++ b/src/ld65/dbgsyms.h @@ -79,7 +79,7 @@ struct DbgSym { DbgSym* ReadDbgSym (FILE* F, ObjData* Obj); /* Read a debug symbol from a file, insert and return it */ -long GetDbgSymVal (DbgSym* D); +long GetDbgSymVal (const DbgSym* D); /* Get the value of this symbol */ void ClearDbgSymTable (void); diff --git a/src/ld65/expr.c b/src/ld65/expr.c index faa9bbde5..94f910d7a 100644 --- a/src/ld65/expr.c +++ b/src/ld65/expr.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2007 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -201,7 +201,7 @@ Import* GetExprImport (ExprNode* Expr) PRECONDITION (Expr->Op == EXPR_SYMBOL); /* Return the import */ - return Expr->Obj->Imports [Expr->V.ImpNum]; + return CollAt (&Expr->Obj->Imports, Expr->V.ImpNum); } @@ -212,8 +212,8 @@ Export* GetExprExport (ExprNode* Expr) /* Check that this is really a symbol */ PRECONDITION (Expr->Op == EXPR_SYMBOL); - /* Return the export */ - return Expr->Obj->Imports [Expr->V.ImpNum]->Exp; + /* Return the export for an import*/ + return GetExprImport (Expr)->Exp; } @@ -230,7 +230,7 @@ Section* GetExprSection (ExprNode* Expr) */ if (Expr->Obj) { /* Return the export */ - return Expr->Obj->Sections[Expr->V.SegNum]; + return CollAt (&Expr->Obj->Sections, Expr->V.SegNum); } else { return Expr->V.Sec; } @@ -343,7 +343,7 @@ long GetExprVal (ExprNode* Expr) case EXPR_BOOLXOR: return (GetExprVal (Expr->Left) != 0) ^ (GetExprVal (Expr->Right) != 0); - + case EXPR_MAX: Left = GetExprVal (Expr->Left); Right = GetExprVal (Expr->Right); diff --git a/src/ld65/library.c b/src/ld65/library.c index 0086c212f..228f6c2ee 100644 --- a/src/ld65/library.c +++ b/src/ld65/library.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2005 Ullrich von Bassewitz */ -/* Römerstraße 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -259,17 +259,15 @@ static void LibCheckExports (ObjData* O) unsigned I; /* Check all exports */ - for (I = 0; I < O->ExportCount; ++I) { - if (IsUnresolved (O->Exports[I]->Name)) { - /* We need this module */ - O->Flags |= OBJ_REF; break; + for (I = 0; I < CollCount (&O->Exports); ++I) { + const Export* E = CollConstAt (&O->Exports, I); + if (IsUnresolved (E->Name)) { + /* We need this module, insert the imports and exports */ + O->Flags |= OBJ_REF; + InsertObjGlobals (O); + break; } } - - /* If we need this module, insert the imports and exports */ - if (O->Flags & OBJ_REF) { - InsertObjGlobals (O); - } } diff --git a/src/ld65/lineinfo.c b/src/ld65/lineinfo.c index 92374f974..2db205782 100644 --- a/src/ld65/lineinfo.c +++ b/src/ld65/lineinfo.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2001 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2001-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -95,8 +95,8 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O) ReadFilePos (F, &LI->Pos); /* Resolve the file index to a pointer to FileInfo struct */ - CHECK (LI->Pos.Name < O->FileCount); - LI->File = O->Files[LI->Pos.Name]; + CHECK (LI->Pos.Name < CollCount (&O->Files)); + LI->File = CollAt (&O->Files, LI->Pos.Name); /* Return the new LineInfo */ return LI; @@ -189,3 +189,4 @@ void RelocLineInfo (Segment* S) + diff --git a/src/ld65/mapfile.c b/src/ld65/mapfile.c index c1bc4cf90..d7d90e2d6 100644 --- a/src/ld65/mapfile.c +++ b/src/ld65/mapfile.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2005 Ullrich von Bassewitz */ -/* Römerstraße 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -86,8 +86,8 @@ void CreateMapFile (int ShortMap) } else { fprintf (F, "%s:\n", GetObjFileName (O)); } - for (J = 0; J < O->SectionCount; ++J) { - const Section* S = O->Sections [J]; + for (J = 0; J < CollCount (&O->Sections); ++J) { + const Section* S = CollConstAt (&O->Sections, J); /* Don't include zero sized sections if not explicitly * requested */ diff --git a/src/ld65/objdata.c b/src/ld65/objdata.c index ebdf3948f..3365b665f 100644 --- a/src/ld65/objdata.c +++ b/src/ld65/objdata.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2003 Ullrich von Bassewitz */ -/* Römerstraße 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -49,7 +49,7 @@ /*****************************************************************************/ -/* Data */ +/* Data */ /*****************************************************************************/ @@ -60,7 +60,7 @@ Collection ObjDataList = STATIC_COLLECTION_INITIALIZER; /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ @@ -79,19 +79,19 @@ ObjData* NewObjData (void) O->Flags = 0; O->Start = 0; O->ExportCount = 0; - O->Exports = 0; + O->Exports = EmptyCollection; O->ImportCount = 0; - O->Imports = 0; + O->Imports = EmptyCollection; O->DbgSymCount = 0; - O->DbgSyms = 0; + O->DbgSyms = EmptyCollection; O->LineInfoCount = 0; - O->LineInfos = 0; + O->LineInfos = EmptyCollection; O->StringCount = 0; O->Strings = 0; O->AssertionCount = 0; - O->Assertions = 0; + O->Assertions = EmptyCollection; O->ScopeCount = 0; - O->Scopes = 0; + O->Scopes = EmptyCollection; /* Return the new entry */ return O; @@ -105,16 +105,22 @@ void FreeObjData (ObjData* O) * referenced. */ { + unsigned I; + /* Unused ObjData do only have the string pool, Exports and Imports. */ - while (O->ExportCount) { - FreeExport (O->Exports[--O->ExportCount]); + for (I = 0; I < CollCount (&O->Exports); ++I) { + FreeExport (CollAt (&O->Exports, I)); } - xfree (O->Exports); - while (O->ImportCount) { - FreeImport (O->Imports[--O->ImportCount]); + DoneCollection (&O->Exports); + for (I = 0; I < CollCount (&O->Imports); ++I) { + FreeImport (CollAt (&O->Imports, I)); } - xfree (O->Imports); + DoneCollection (&O->Imports); + DoneCollection (&O->DbgSyms); + DoneCollection (&O->LineInfos); xfree (O->Strings); + DoneCollection (&O->Assertions); + DoneCollection (&O->Scopes); xfree (O); } @@ -147,11 +153,11 @@ void InsertObjGlobals (ObjData* O) unsigned I; /* Insert exports and imports */ - for (I = 0; I < O->ExportCount; ++I) { - InsertExport (O->Exports[I]); + for (I = 0; I < CollCount (&O->Exports); ++I) { + InsertExport (CollAt (&O->Exports, I)); } - for (I = 0; I < O->ImportCount; ++I) { - InsertImport (O->Imports[I]); + for (I = 0; I < CollCount (&O->Imports); ++I) { + InsertImport (CollAt (&O->Imports, I)); } } @@ -193,16 +199,21 @@ const char* GetSourceFileName (const ObjData* O, unsigned Index) } else { /* Check the parameter */ - if (Index >= O->FileCount) { + if (Index >= CollCount (&O->Files)) { /* Error() will terminate the program */ Warning ("Invalid file index (%u) in module `%s' (input file corrupt?)", Index, GetObjFileName (O)); return "[invalid]"; /* ### */ - } - /* Return the name */ - return GetString (O->Files[Index]->Name); + } else { + /* Get a pointer to the file info struct */ + const FileInfo* FI = CollAt (&O->Files, Index); + + /* Return the name */ + return GetString (FI->Name); + + } } } diff --git a/src/ld65/objdata.h b/src/ld65/objdata.h index e538320aa..ca39f38a0 100644 --- a/src/ld65/objdata.h +++ b/src/ld65/objdata.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2003 Ullrich von Bassewitz */ -/* Römerstraße 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -65,23 +65,23 @@ struct ObjData { unsigned long Start; /* Start offset of data in library */ unsigned Flags; unsigned FileCount; /* Input file count */ - struct FileInfo** Files; /* List of input files */ + Collection Files; /* List of input files */ unsigned SectionCount; /* Count of sections in this object */ - struct Section** Sections; /* List of all sections */ + Collection Sections; /* List of all sections */ unsigned ExportCount; /* Count of exports */ - struct Export** Exports; /* List of all exports */ + Collection Exports; /* List of all exports */ unsigned ImportCount; /* Count of imports */ - struct Import** Imports; /* List of all imports */ + Collection Imports; /* List of all imports */ unsigned DbgSymCount; /* Count of debug symbols */ - struct DbgSym** DbgSyms; /* List of debug symbols */ + Collection DbgSyms; /* List of debug symbols */ unsigned LineInfoCount; /* Count of additional line infos */ - struct LineInfo** LineInfos; /* List of additional line infos */ + Collection LineInfos; /* List of additional line infos */ unsigned StringCount; /* Count of strings */ unsigned* Strings; /* List of global string indices */ unsigned AssertionCount; /* Count of module assertions */ - struct Assertion** Assertions; /* List of module assertions */ + Collection Assertions; /* List of module assertions */ unsigned ScopeCount; /* Count of scopes */ - struct Scope** Scopes; /* List of scopes */ + Collection Scopes; /* List of scopes */ }; @@ -131,10 +131,10 @@ const char* GetObjFileName (const ObjData* O); INLINE int ObjHasFiles (const ObjData* O) /* Return true if the files list does exist */ { - return (O != 0 && O->Files != 0); + return (O != 0 && CollCount (&O->Files) != 0); } #else -# define ObjHasFiles(O) ((O) != 0 && (O)->Files != 0) +# define ObjHasFiles(O) ((O) != 0 && CollCount ((O)->Files) != 0) #endif const char* GetSourceFileName (const ObjData* O, unsigned Index); diff --git a/src/ld65/objfile.c b/src/ld65/objfile.c index bea9fda69..0de4c70ee 100644 --- a/src/ld65/objfile.c +++ b/src/ld65/objfile.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2003 Ullrich von Bassewitz */ -/* Römerstraße 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -120,9 +120,9 @@ void ObjReadFiles (FILE* F, unsigned long Pos, ObjData* O) /* Read the data */ O->FileCount = ReadVar (F); - O->Files = xmalloc (O->FileCount * sizeof (O->Files[0])); + CollGrow (&O->Files, O->FileCount); for (I = 0; I < O->FileCount; ++I) { - O->Files[I] = ReadFileInfo (F, O); + CollAppend (&O->Files, ReadFileInfo (F, O)); } } @@ -138,9 +138,9 @@ void ObjReadSections (FILE* F, unsigned long Pos, ObjData* O) /* Read the data */ O->SectionCount = ReadVar (F); - O->Sections = xmalloc (O->SectionCount * sizeof (O->Sections[0])); + CollGrow (&O->Sections, O->SectionCount); for (I = 0; I < O->SectionCount; ++I) { - O->Sections [I] = ReadSection (F, O); + CollAppend (&O->Sections, ReadSection (F, O)); } } @@ -156,9 +156,9 @@ void ObjReadImports (FILE* F, unsigned long Pos, ObjData* O) /* Read the data */ O->ImportCount = ReadVar (F); - O->Imports = xmalloc (O->ImportCount * sizeof (O->Imports[0])); + CollGrow (&O->Imports, O->ImportCount); for (I = 0; I < O->ImportCount; ++I) { - O->Imports [I] = ReadImport (F, O); + CollAppend (&O->Imports, ReadImport (F, O)); } } @@ -174,9 +174,9 @@ void ObjReadExports (FILE* F, unsigned long Pos, ObjData* O) /* Read the data */ O->ExportCount = ReadVar (F); - O->Exports = xmalloc (O->ExportCount * sizeof (O->Exports[0])); + CollGrow (&O->Exports, O->ExportCount); for (I = 0; I < O->ExportCount; ++I) { - O->Exports [I] = ReadExport (F, O); + CollAppend (&O->Exports, ReadExport (F, O)); } } @@ -192,9 +192,9 @@ void ObjReadDbgSyms (FILE* F, unsigned long Pos, ObjData* O) /* Read the data */ O->DbgSymCount = ReadVar (F); - O->DbgSyms = xmalloc (O->DbgSymCount * sizeof (O->DbgSyms[0])); + CollGrow (&O->DbgSyms, O->DbgSymCount); for (I = 0; I < O->DbgSymCount; ++I) { - O->DbgSyms [I] = ReadDbgSym (F, O); + CollAppend (&O->DbgSyms, ReadDbgSym (F, O)); } } @@ -210,9 +210,9 @@ void ObjReadLineInfos (FILE* F, unsigned long Pos, ObjData* O) /* Read the data */ O->LineInfoCount = ReadVar (F); - O->LineInfos = xmalloc (O->LineInfoCount * sizeof (O->LineInfos[0])); + CollGrow (&O->LineInfos, O->LineInfoCount); for (I = 0; I < O->LineInfoCount; ++I) { - O->LineInfos[I] = ReadLineInfo (F, O); + CollAppend (&O->LineInfos, ReadLineInfo (F, O)); } } @@ -246,9 +246,9 @@ void ObjReadAssertions (FILE* F, unsigned long Pos, ObjData* O) /* Read the data */ O->AssertionCount = ReadVar (F); - O->Assertions = xmalloc (O->AssertionCount * sizeof (O->Assertions[0])); + CollGrow (&O->Assertions, O->AssertionCount); for (I = 0; I < O->AssertionCount; ++I) { - O->Assertions[I] = ReadAssertion (F, O); + CollAppend (&O->Assertions, ReadAssertion (F, O)); } } @@ -264,9 +264,9 @@ void ObjReadScopes (FILE* F, unsigned long Pos, ObjData* O) /* Read the data */ O->ScopeCount = ReadVar (F); - O->Scopes = xmalloc (O->ScopeCount * sizeof (O->Scopes[0])); + CollGrow (&O->Scopes, O->ScopeCount); for (I = 0; I < O->ScopeCount; ++I) { - O->Scopes[I] = 0; /* ReadScope (F, O); ### not implemented */ + CollAppend (&O->Scopes, 0); /* ReadScope (F, O); ### not implemented */ } } diff --git a/src/ld65/segments.c b/src/ld65/segments.c index 1fb7fcbd7..11943dc77 100644 --- a/src/ld65/segments.c +++ b/src/ld65/segments.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2003 Ullrich von Bassewitz */ -/* Römerstraße 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -276,15 +276,16 @@ Section* ReadSection (FILE* F, ObjData* O) LineInfoIndex = ReadVar (F); if (LineInfoIndex) { --LineInfoIndex; - if (LineInfoIndex >= O->LineInfoCount) { + if (LineInfoIndex >= CollCount (&O->LineInfos)) { Internal ("In module `%s', file `%s', line %lu: Invalid line " "info with index %u (max count %u)", GetObjFileName (O), GetSourceFileName (O, Frag->Pos.Name), - Frag->Pos.Line, LineInfoIndex, O->LineInfoCount); + Frag->Pos.Line, LineInfoIndex, + CollCount (&O->LineInfos)); } /* Point from the fragment to the line info... */ - Frag->LI = O->LineInfos[LineInfoIndex]; + Frag->LI = CollAt (&O->LineInfos, LineInfoIndex); /* ...and back from the line info to the fragment */ CollAppend (&Frag->LI->Fragments, Frag); }