X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fld65%2Fobjdata.c;h=2a7a0ac1d9a9f1161c6fe246da4e2294193c68fc;hb=35e1184901ca38bdb2e56d154ed3b71f6096eacc;hp=2a4c1f6741b3a9bb0f7e7c59c2836f69e4f11585;hpb=bb24d025f6a68c0d1475f82c473ff5102a351db3;p=cc65 diff --git a/src/ld65/objdata.c b/src/ld65/objdata.c index 2a4c1f674..2a7a0ac1d 100644 --- a/src/ld65/objdata.c +++ b/src/ld65/objdata.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2003 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2011, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -43,13 +43,14 @@ #include "error.h" #include "exports.h" #include "fileinfo.h" +#include "library.h" #include "objdata.h" #include "spool.h" /*****************************************************************************/ -/* Data */ +/* Data */ /*****************************************************************************/ @@ -60,7 +61,7 @@ Collection ObjDataList = STATIC_COLLECTION_INITIALIZER; /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ @@ -74,22 +75,26 @@ ObjData* NewObjData (void) /* Initialize the data */ O->Next = 0; O->Name = INVALID_STRING_ID; - O->LibName = INVALID_STRING_ID; + O->Lib = 0; O->MTime = 0; - O->Flags = 0; O->Start = 0; - O->ExportCount = 0; - O->Exports = 0; - O->ImportCount = 0; - O->Imports = 0; - O->DbgSymCount = 0; - O->DbgSyms = 0; - O->LineInfoCount = 0; - O->LineInfos = 0; + O->Flags = 0; + O->HLLSymBaseId = 0; + O->SymBaseId = 0; + O->ScopeBaseId = 0; + O->SpanBaseId = 0; + O->Files = EmptyCollection; + O->Sections = EmptyCollection; + O->Exports = EmptyCollection; + O->Imports = EmptyCollection; + O->DbgSyms = EmptyCollection; + O->HLLDbgSyms = EmptyCollection; + O->LineInfos = EmptyCollection; O->StringCount = 0; O->Strings = 0; - O->AssertionCount = 0; - O->Assertions = 0; + O->Assertions = EmptyCollection; + O->Scopes = EmptyCollection; + O->Spans = EmptyCollection; /* Return the new entry */ return O; @@ -103,16 +108,36 @@ void FreeObjData (ObjData* O) * referenced. */ { - /* Unused ObjData do only have the string pool, Exports and Imports. */ - while (O->ExportCount) { - FreeExport (O->Exports[--O->ExportCount]); + unsigned I; + + for (I = 0; I < CollCount (&O->Files); ++I) { + CollDeleteItem (&((FileInfo*) CollAtUnchecked (&O->Files, I))->Modules, O); } - xfree (O->Exports); - while (O->ImportCount) { - FreeImport (O->Imports[--O->ImportCount]); + DoneCollection (&O->Files); + DoneCollection (&O->Sections); + for (I = 0; I < CollCount (&O->Exports); ++I) { + FreeExport (CollAtUnchecked (&O->Exports, I)); + } + DoneCollection (&O->Exports); + for (I = 0; I < CollCount (&O->Imports); ++I) { + FreeImport (CollAtUnchecked (&O->Imports, I)); + } + DoneCollection (&O->Imports); + DoneCollection (&O->DbgSyms); + DoneCollection (&O->HLLDbgSyms); + + for (I = 0; I < CollCount (&O->LineInfos); ++I) { + FreeLineInfo (CollAtUnchecked (&O->LineInfos, I)); } - xfree (O->Imports); + DoneCollection (&O->LineInfos); xfree (O->Strings); + DoneCollection (&O->Assertions); + DoneCollection (&O->Scopes); + for (I = 0; I < CollCount (&O->Spans); ++I) { + FreeSpan (CollAtUnchecked (&O->Spans, I)); + } + DoneCollection (&O->Spans); + xfree (O); } @@ -145,11 +170,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)); } } @@ -177,26 +202,112 @@ const char* GetObjFileName (const ObjData* O) -const char* GetSourceFileName (const ObjData* O, unsigned Index) -/* Get the name of the source file with the given index. If O is NULL, return - * "[linker generated]" as the file name. - */ +const struct StrBuf* GetObjString (const ObjData* Obj, unsigned Id) +/* Get a string from an object file checking for an invalid index */ { - /* Check if we have an object file */ - if (O == 0) { + return GetStrBuf (MakeGlobalStringId (Obj, Id)); +} - /* No object file */ - return "[linker generated]"; - } else { - /* Check the parameter */ - PRECONDITION (Index < O->FileCount); +struct Section* GetObjSection (const ObjData* O, unsigned Id) +/* Get a section from an object file checking for a valid index */ +{ + if (Id >= CollCount (&O->Sections)) { + Error ("Invalid section index (%u) in module `%s'", + Id, GetObjFileName (O)); + } + return CollAtUnchecked (&O->Sections, Id); +} - /* Return the name */ - return GetString (O->Files[Index]->Name); + +struct Import* GetObjImport (const ObjData* O, unsigned Id) +/* Get an import from an object file checking for a valid index */ +{ + if (Id >= CollCount (&O->Imports)) { + Error ("Invalid import index (%u) in module `%s'", + Id, GetObjFileName (O)); } + return CollAtUnchecked (&O->Imports, Id); +} + + + +struct Export* GetObjExport (const ObjData* O, unsigned Id) +/* Get an export from an object file checking for a valid index */ +{ + if (Id >= CollCount (&O->Exports)) { + Error ("Invalid export index (%u) in module `%s'", + Id, GetObjFileName (O)); + } + return CollAtUnchecked (&O->Exports, Id); +} + + + +struct DbgSym* GetObjDbgSym (const ObjData* O, unsigned Id) +/* Get a debug symbol from an object file checking for a valid index */ +{ + if (Id >= CollCount (&O->DbgSyms)) { + Error ("Invalid debug symbol index (%u) in module `%s'", + Id, GetObjFileName (O)); + } + return CollAtUnchecked (&O->DbgSyms, Id); +} + + + +struct Scope* GetObjScope (const ObjData* O, unsigned Id) +/* Get a scope from an object file checking for a valid index */ +{ + if (Id >= CollCount (&O->Scopes)) { + Error ("Invalid scope index (%u) in module `%s'", + Id, GetObjFileName (O)); + } + return CollAtUnchecked (&O->Scopes, Id); +} + + + +unsigned ObjDataCount (void) +/* Return the total number of modules */ +{ + return CollCount (&ObjDataList); +} + + + +void PrintDbgModules (FILE* F) +/* Output the modules to a debug info file */ +{ + unsigned I; + + /* Output modules */ + for (I = 0; I < CollCount (&ObjDataList); ++I) { + + /* Get this object file */ + const ObjData* O = CollConstAt (&ObjDataList, I); + + /* The main source file is the one at index zero */ + const FileInfo* Source = CollConstAt (&O->Files, 0); + + /* Output the module line */ + fprintf (F, + "mod\tid=%u,name=\"%s\",file=%u", + I, + GetObjFileName (O), + Source->Id); + + /* Add library if any */ + if (O->Lib != 0) { + fprintf (F, ",lib=%u", GetLibId (O->Lib)); + } + + /* Terminate the output line */ + fputc ('\n', F); + } + }