From af3a5e6e15d7a7cc7042727b9f34ad808fdd01bc Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 7 Aug 2011 11:33:28 +0000 Subject: [PATCH] Output library information to the debug file. git-svn-id: svn://svn.cc65.org/cc65/trunk@5127 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ld65/dbgfile.c | 13 ++++---- src/ld65/library.c | 76 ++++++++++++++++++++++++++++++++++++++++++---- src/ld65/library.h | 30 +++++++++++++++--- src/ld65/mapfile.c | 5 +-- src/ld65/objdata.c | 2 +- src/ld65/objdata.h | 7 +++-- 6 files changed, 110 insertions(+), 23 deletions(-) diff --git a/src/ld65/dbgfile.c b/src/ld65/dbgfile.c index a4f8216a4..fff633d61 100644 --- a/src/ld65/dbgfile.c +++ b/src/ld65/dbgfile.c @@ -43,6 +43,7 @@ #include "error.h" #include "fileinfo.h" #include "global.h" +#include "library.h" #include "lineinfo.h" #include "scopes.h" #include "segments.h" @@ -104,7 +105,10 @@ void CreateDbgFile (void) /* Assign the base ids to the modules */ AssignBaseIds (); - /* Output modules */ + /* Output libraries */ + PrintDbgLibraries (F); + + /* Output modules */ for (I = 0; I < CollCount (&ObjDataList); ++I) { /* Get this object file */ @@ -121,11 +125,8 @@ void CreateDbgFile (void) Source->Id); /* Add library if any */ - if (O->LibName != INVALID_STRING_ID) { - fprintf (F, - ",lib=\"%s\",mtime=0x%08lX", - GetString (O->LibName), - O->MTime); + if (O->Lib != 0) { + fprintf (F, ",lib=%u", GetLibId (O->Lib)); } /* Terminate the output line */ diff --git a/src/ld65/library.c b/src/ld65/library.c index c99b7dbba..56fd1d3a5 100644 --- a/src/ld65/library.c +++ b/src/ld65/library.c @@ -65,6 +65,7 @@ /* Library data structure */ typedef struct Library Library; struct Library { + unsigned Id; /* Id of library */ unsigned Name; /* String id of the name */ FILE* F; /* Open file stream */ LibHeader Header; /* Library header */ @@ -74,6 +75,9 @@ struct Library { /* List of open libraries */ static Collection OpenLibs = STATIC_COLLECTION_INITIALIZER; +/* List of used libraries */ +static Collection Libraries = STATIC_COLLECTION_INITIALIZER; + /* Flag for library grouping */ static int Grouping = 0; @@ -92,6 +96,7 @@ static Library* NewLibrary (FILE* F, const char* Name) Library* L = xmalloc (sizeof (*L)); /* Initialize the fields */ + L->Id = ~0U; L->Name = GetStringId (Name); L->F = F; L->Modules = EmptyCollection; @@ -102,13 +107,23 @@ static Library* NewLibrary (FILE* F, const char* Name) -static void FreeLibrary (Library* L) -/* Free a library structure */ +static void CloseLibrary (Library* L) +/* Close a library file and remove the list of modules */ { /* Close the library file */ if (fclose (L->F) != 0) { Error ("Error closing `%s': %s", GetString (L->Name), strerror (errno)); } + L->F = 0; +} + + + +static void FreeLibrary (Library* L) +/* Free a library structure */ +{ + /* Close the library */ + CloseLibrary (L); /* Free the module index */ DoneCollection (&L->Modules); @@ -196,7 +211,7 @@ static ObjData* ReadIndexEntry (Library* L) ObjData* O = NewObjData (); /* Remember from which library this module is */ - O->LibName = L->Name; + O->Lib = L; /* Module name */ O->Name = ReadStr (L->F); @@ -365,7 +380,8 @@ static void LibResolve (void) /* Walk over all modules in this library and add the files list and * sections for all referenced modules. */ - for (J = 0; J < CollCount (&L->Modules); ++J) { + J = 0; + while (J < CollCount (&L->Modules)) { /* Get the object data */ ObjData* O = CollAtUnchecked (&L->Modules, J); @@ -398,16 +414,30 @@ static void LibResolve (void) /* Insert the object into the list of all used object files */ InsertObjData (O); + /* Process next object file in library */ + ++J; + } else { /* Unreferenced object file, remove it */ FreeObjData (O); + CollDelete (&L->Modules, J); } } - /* Close the file and delete the library data */ - FreeLibrary (L); + /* If we have referenced modules in this library, assign it an id + * (which is the index in the library collection) and keep it. + */ + if (CollCount (&L->Modules) > 0) { + CloseLibrary (L); + L->Id = CollCount (&Libraries); + CollAppend (&Libraries, L); + } else { + /* Delete the library */ + FreeLibrary (L); + CollDelete (&OpenLibs, I); + } } /* We're done with all open libraries, clear the OpenLibs collection */ @@ -480,3 +510,37 @@ void LibCheckGroup (void) +const char* GetLibFileName (const Library* L) +/* Get the name of a library */ +{ + return GetString (L->Name); +} + + + +unsigned GetLibId (const Library* L) +/* Get the id of a library file. */ +{ + return L->Id; +} + + + +void PrintDbgLibraries (FILE* F) +/* Output the libraries to a debug info file */ +{ + unsigned I; + + /* Output information about all libraries */ + for (I = 0; I < CollCount (&Libraries); ++I) { + /* Get the library */ + const Library* L = CollAtUnchecked (&Libraries, I); + + /* Output the info */ + fprintf (F, "library\tid=%u,name=\"%s\"\n", L->Id, GetString (L->Name)); + } +} + + + + diff --git a/src/ld65/library.h b/src/ld65/library.h index 6360106c9..6cae0d8cf 100644 --- a/src/ld65/library.h +++ b/src/ld65/library.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2005 Ullrich von Bassewitz */ -/* Römerstraße 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 */ @@ -39,7 +39,18 @@ /*****************************************************************************/ -/* Code */ +/* Data */ +/*****************************************************************************/ + + + +/* Opaque structure */ +struct Library; + + + +/*****************************************************************************/ +/* Code */ /*****************************************************************************/ @@ -64,6 +75,15 @@ void LibEndGroup (void); void LibCheckGroup (void); /* Check if there are open library groups */ +const char* GetLibFileName (const struct Library* L); +/* Get the name of a library */ + +unsigned GetLibId (const struct Library* L); +/* Get the id of a library file. */ + +void PrintDbgLibraries (FILE* F); +/* Output the libraries to a debug info file */ + /* End of library.h */ diff --git a/src/ld65/mapfile.c b/src/ld65/mapfile.c index d7d90e2d6..c9aad3f56 100644 --- a/src/ld65/mapfile.c +++ b/src/ld65/mapfile.c @@ -43,6 +43,7 @@ #include "exports.h" #include "global.h" #include "error.h" +#include "library.h" #include "mapfile.h" #include "objdata.h" #include "segments.h" @@ -80,9 +81,9 @@ void CreateMapFile (int ShortMap) const ObjData* O = CollConstAt (&ObjDataList, I); /* Output the data */ - if (O->LibName != INVALID_STRING_ID) { + if (O->Lib) { /* The file is from a library */ - fprintf (F, "%s(%s):\n", GetString (O->LibName), GetObjFileName (O)); + fprintf (F, "%s(%s):\n", GetLibFileName (O->Lib), GetObjFileName (O)); } else { fprintf (F, "%s:\n", GetObjFileName (O)); } diff --git a/src/ld65/objdata.c b/src/ld65/objdata.c index e12fd65bb..9e3d5692c 100644 --- a/src/ld65/objdata.c +++ b/src/ld65/objdata.c @@ -74,7 +74,7 @@ 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->Start = 0; O->Flags = 0; diff --git a/src/ld65/objdata.h b/src/ld65/objdata.h index 9cab25092..679242795 100644 --- a/src/ld65/objdata.h +++ b/src/ld65/objdata.h @@ -52,6 +52,7 @@ /* Forwards */ +struct Library; struct Scope; struct Section; @@ -63,11 +64,11 @@ typedef struct ObjData ObjData; struct ObjData { ObjData* Next; /* Linked list of all objects */ unsigned Name; /* Module name */ - unsigned LibName; /* Name of library */ + struct Library* Lib; /* Library where module comes from */ unsigned long MTime; /* Time of last modification */ - ObjHeader Header; /* Header of file */ + ObjHeader Header; /* Header of file */ unsigned long Start; /* Start offset of data in library */ - unsigned Flags; + unsigned Flags; unsigned FileBaseId; /* Debug info base id for files */ unsigned SymBaseId; /* Debug info base id for symbols */