1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-27 00:29:31 +00:00

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
This commit is contained in:
uz 2010-07-30 20:58:51 +00:00
parent 5bffbc98ff
commit f308a3c4d1
11 changed files with 135 additions and 124 deletions

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2001-2008 Ullrich von Bassewitz */ /* (C) 2001-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -53,17 +53,17 @@ void PrintDbgInfo (ObjData* O, FILE* F)
unsigned I, J; unsigned I, J;
/* Output the files section */ /* Output the files section */
for (I = 0; I < O->FileCount; ++I) { for (I = 0; I < CollCount (&O->Files); ++I) {
const FileInfo* FI = O->Files[I]; const FileInfo* FI = CollConstAt (&O->Files, I);
fprintf (F, "file\t\"%s\",size=%lu,mtime=0x%08lX\n", fprintf (F, "file\t\"%s\",size=%lu,mtime=0x%08lX\n",
GetString (FI->Name), FI->Size, FI->MTime); GetString (FI->Name), FI->Size, FI->MTime);
} }
/* Output the line infos */ /* Output the line infos */
for (I = 0; I < O->LineInfoCount; ++I) { for (I = 0; I < CollCount (&O->LineInfos); ++I) {
/* Get this line info */ /* Get this line info */
const LineInfo* LI = O->LineInfos[I]; const LineInfo* LI = CollConstAt (&O->LineInfos, I);
/* Get a pointer to the code ranges */ /* Get a pointer to the code ranges */
const Collection* CodeRanges = &LI->CodeRanges; const Collection* CodeRanges = &LI->CodeRanges;

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2008 Ullrich von Bassewitz */ /* (C) 1998-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -184,7 +184,7 @@ void ClearDbgSymTable (void)
long GetDbgSymVal (DbgSym* D) long GetDbgSymVal (const DbgSym* D)
/* Get the value of this symbol */ /* Get the value of this symbol */
{ {
CHECK (D->Expr != 0); CHECK (D->Expr != 0);
@ -199,12 +199,12 @@ void PrintDbgSyms (ObjData* O, FILE* F)
unsigned I; unsigned I;
/* Walk through all debug symbols in this module */ /* 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; long Val;
/* Get the next debug symbol */ /* Get the next debug symbol */
DbgSym* D = O->DbgSyms [I]; DbgSym* D = CollAt (&O->DbgSyms, I);
/* Get the symbol value */ /* Get the symbol value */
Val = GetDbgSymVal (D); Val = GetDbgSymVal (D);
@ -237,12 +237,12 @@ void PrintDbgSymLabels (ObjData* O, FILE* F)
unsigned I; unsigned I;
/* Walk through all debug symbols in this module */ /* 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; long Val;
/* Get the next debug symbol */ /* 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) */ /* Emit this symbol only if it is a label (ignore equates) */
if (IS_EXP_EQUATE (D->Type)) { if (IS_EXP_EQUATE (D->Type)) {

View File

@ -79,7 +79,7 @@ struct DbgSym {
DbgSym* ReadDbgSym (FILE* F, ObjData* Obj); DbgSym* ReadDbgSym (FILE* F, ObjData* Obj);
/* Read a debug symbol from a file, insert and return it */ /* 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 */ /* Get the value of this symbol */
void ClearDbgSymTable (void); void ClearDbgSymTable (void);

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2007 Ullrich von Bassewitz */ /* (C) 1998-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -201,7 +201,7 @@ Import* GetExprImport (ExprNode* Expr)
PRECONDITION (Expr->Op == EXPR_SYMBOL); PRECONDITION (Expr->Op == EXPR_SYMBOL);
/* Return the import */ /* 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 */ /* Check that this is really a symbol */
PRECONDITION (Expr->Op == EXPR_SYMBOL); PRECONDITION (Expr->Op == EXPR_SYMBOL);
/* Return the export */ /* Return the export for an import*/
return Expr->Obj->Imports [Expr->V.ImpNum]->Exp; return GetExprImport (Expr)->Exp;
} }
@ -230,7 +230,7 @@ Section* GetExprSection (ExprNode* Expr)
*/ */
if (Expr->Obj) { if (Expr->Obj) {
/* Return the export */ /* Return the export */
return Expr->Obj->Sections[Expr->V.SegNum]; return CollAt (&Expr->Obj->Sections, Expr->V.SegNum);
} else { } else {
return Expr->V.Sec; return Expr->V.Sec;
} }

View File

@ -6,8 +6,8 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2005 Ullrich von Bassewitz */ /* (C) 1998-2010, Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@ -259,16 +259,14 @@ static void LibCheckExports (ObjData* O)
unsigned I; unsigned I;
/* Check all exports */ /* Check all exports */
for (I = 0; I < O->ExportCount; ++I) { for (I = 0; I < CollCount (&O->Exports); ++I) {
if (IsUnresolved (O->Exports[I]->Name)) { const Export* E = CollConstAt (&O->Exports, I);
/* We need this module */ if (IsUnresolved (E->Name)) {
O->Flags |= OBJ_REF; break; /* We need this module, insert the imports and exports */
} O->Flags |= OBJ_REF;
}
/* If we need this module, insert the imports and exports */
if (O->Flags & OBJ_REF) {
InsertObjGlobals (O); InsertObjGlobals (O);
break;
}
} }
} }

View File

@ -6,8 +6,8 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2001 Ullrich von Bassewitz */ /* (C) 2001-2010, Ullrich von Bassewitz */
/* Römerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@ -95,8 +95,8 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O)
ReadFilePos (F, &LI->Pos); ReadFilePos (F, &LI->Pos);
/* Resolve the file index to a pointer to FileInfo struct */ /* Resolve the file index to a pointer to FileInfo struct */
CHECK (LI->Pos.Name < O->FileCount); CHECK (LI->Pos.Name < CollCount (&O->Files));
LI->File = O->Files[LI->Pos.Name]; LI->File = CollAt (&O->Files, LI->Pos.Name);
/* Return the new LineInfo */ /* Return the new LineInfo */
return LI; return LI;
@ -189,3 +189,4 @@ void RelocLineInfo (Segment* S)

View File

@ -6,8 +6,8 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2005 Ullrich von Bassewitz */ /* (C) 1998-2010, Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@ -86,8 +86,8 @@ void CreateMapFile (int ShortMap)
} else { } else {
fprintf (F, "%s:\n", GetObjFileName (O)); fprintf (F, "%s:\n", GetObjFileName (O));
} }
for (J = 0; J < O->SectionCount; ++J) { for (J = 0; J < CollCount (&O->Sections); ++J) {
const Section* S = O->Sections [J]; const Section* S = CollConstAt (&O->Sections, J);
/* Don't include zero sized sections if not explicitly /* Don't include zero sized sections if not explicitly
* requested * requested
*/ */

View File

@ -6,8 +6,8 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2003 Ullrich von Bassewitz */ /* (C) 1998-2010, Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@ -79,19 +79,19 @@ ObjData* NewObjData (void)
O->Flags = 0; O->Flags = 0;
O->Start = 0; O->Start = 0;
O->ExportCount = 0; O->ExportCount = 0;
O->Exports = 0; O->Exports = EmptyCollection;
O->ImportCount = 0; O->ImportCount = 0;
O->Imports = 0; O->Imports = EmptyCollection;
O->DbgSymCount = 0; O->DbgSymCount = 0;
O->DbgSyms = 0; O->DbgSyms = EmptyCollection;
O->LineInfoCount = 0; O->LineInfoCount = 0;
O->LineInfos = 0; O->LineInfos = EmptyCollection;
O->StringCount = 0; O->StringCount = 0;
O->Strings = 0; O->Strings = 0;
O->AssertionCount = 0; O->AssertionCount = 0;
O->Assertions = 0; O->Assertions = EmptyCollection;
O->ScopeCount = 0; O->ScopeCount = 0;
O->Scopes = 0; O->Scopes = EmptyCollection;
/* Return the new entry */ /* Return the new entry */
return O; return O;
@ -105,16 +105,22 @@ void FreeObjData (ObjData* O)
* referenced. * referenced.
*/ */
{ {
unsigned I;
/* Unused ObjData do only have the string pool, Exports and Imports. */ /* Unused ObjData do only have the string pool, Exports and Imports. */
while (O->ExportCount) { for (I = 0; I < CollCount (&O->Exports); ++I) {
FreeExport (O->Exports[--O->ExportCount]); FreeExport (CollAt (&O->Exports, I));
} }
xfree (O->Exports); DoneCollection (&O->Exports);
while (O->ImportCount) { for (I = 0; I < CollCount (&O->Imports); ++I) {
FreeImport (O->Imports[--O->ImportCount]); FreeImport (CollAt (&O->Imports, I));
} }
xfree (O->Imports); DoneCollection (&O->Imports);
DoneCollection (&O->DbgSyms);
DoneCollection (&O->LineInfos);
xfree (O->Strings); xfree (O->Strings);
DoneCollection (&O->Assertions);
DoneCollection (&O->Scopes);
xfree (O); xfree (O);
} }
@ -147,11 +153,11 @@ void InsertObjGlobals (ObjData* O)
unsigned I; unsigned I;
/* Insert exports and imports */ /* Insert exports and imports */
for (I = 0; I < O->ExportCount; ++I) { for (I = 0; I < CollCount (&O->Exports); ++I) {
InsertExport (O->Exports[I]); InsertExport (CollAt (&O->Exports, I));
} }
for (I = 0; I < O->ImportCount; ++I) { for (I = 0; I < CollCount (&O->Imports); ++I) {
InsertImport (O->Imports[I]); InsertImport (CollAt (&O->Imports, I));
} }
} }
@ -193,18 +199,23 @@ const char* GetSourceFileName (const ObjData* O, unsigned Index)
} else { } else {
/* Check the parameter */ /* Check the parameter */
if (Index >= O->FileCount) { if (Index >= CollCount (&O->Files)) {
/* Error() will terminate the program */ /* Error() will terminate the program */
Warning ("Invalid file index (%u) in module `%s' (input file corrupt?)", Warning ("Invalid file index (%u) in module `%s' (input file corrupt?)",
Index, GetObjFileName (O)); Index, GetObjFileName (O));
return "[invalid]"; /* ### */ return "[invalid]"; /* ### */
}
} else {
/* Get a pointer to the file info struct */
const FileInfo* FI = CollAt (&O->Files, Index);
/* Return the name */ /* Return the name */
return GetString (O->Files[Index]->Name); return GetString (FI->Name);
} }
} }
}

View File

@ -6,8 +6,8 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2003 Ullrich von Bassewitz */ /* (C) 1998-2010, Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@ -65,23 +65,23 @@ struct ObjData {
unsigned long Start; /* Start offset of data in library */ unsigned long Start; /* Start offset of data in library */
unsigned Flags; unsigned Flags;
unsigned FileCount; /* Input file count */ 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 */ 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 */ unsigned ExportCount; /* Count of exports */
struct Export** Exports; /* List of all exports */ Collection Exports; /* List of all exports */
unsigned ImportCount; /* Count of imports */ unsigned ImportCount; /* Count of imports */
struct Import** Imports; /* List of all imports */ Collection Imports; /* List of all imports */
unsigned DbgSymCount; /* Count of debug symbols */ 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 */ 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 StringCount; /* Count of strings */
unsigned* Strings; /* List of global string indices */ unsigned* Strings; /* List of global string indices */
unsigned AssertionCount; /* Count of module assertions */ unsigned AssertionCount; /* Count of module assertions */
struct Assertion** Assertions; /* List of module assertions */ Collection Assertions; /* List of module assertions */
unsigned ScopeCount; /* Count of scopes */ 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) INLINE int ObjHasFiles (const ObjData* O)
/* Return true if the files list does exist */ /* Return true if the files list does exist */
{ {
return (O != 0 && O->Files != 0); return (O != 0 && CollCount (&O->Files) != 0);
} }
#else #else
# define ObjHasFiles(O) ((O) != 0 && (O)->Files != 0) # define ObjHasFiles(O) ((O) != 0 && CollCount ((O)->Files) != 0)
#endif #endif
const char* GetSourceFileName (const ObjData* O, unsigned Index); const char* GetSourceFileName (const ObjData* O, unsigned Index);

View File

@ -6,8 +6,8 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2003 Ullrich von Bassewitz */ /* (C) 1998-2010, Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@ -120,9 +120,9 @@ void ObjReadFiles (FILE* F, unsigned long Pos, ObjData* O)
/* Read the data */ /* Read the data */
O->FileCount = ReadVar (F); 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) { 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 */ /* Read the data */
O->SectionCount = ReadVar (F); 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) { 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 */ /* Read the data */
O->ImportCount = ReadVar (F); 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) { 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 */ /* Read the data */
O->ExportCount = ReadVar (F); 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) { 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 */ /* Read the data */
O->DbgSymCount = ReadVar (F); 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) { 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 */ /* Read the data */
O->LineInfoCount = ReadVar (F); 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) { 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 */ /* Read the data */
O->AssertionCount = ReadVar (F); 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) { 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 */ /* Read the data */
O->ScopeCount = ReadVar (F); 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) { 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 */
} }
} }

View File

@ -6,8 +6,8 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2003 Ullrich von Bassewitz */ /* (C) 1998-2010, Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@ -276,15 +276,16 @@ Section* ReadSection (FILE* F, ObjData* O)
LineInfoIndex = ReadVar (F); LineInfoIndex = ReadVar (F);
if (LineInfoIndex) { if (LineInfoIndex) {
--LineInfoIndex; --LineInfoIndex;
if (LineInfoIndex >= O->LineInfoCount) { if (LineInfoIndex >= CollCount (&O->LineInfos)) {
Internal ("In module `%s', file `%s', line %lu: Invalid line " Internal ("In module `%s', file `%s', line %lu: Invalid line "
"info with index %u (max count %u)", "info with index %u (max count %u)",
GetObjFileName (O), GetObjFileName (O),
GetSourceFileName (O, Frag->Pos.Name), 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... */ /* 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 */ /* ...and back from the line info to the fragment */
CollAppend (&Frag->LI->Fragments, Frag); CollAppend (&Frag->LI->Fragments, Frag);
} }