diff --git a/src/ld65/dbgfile.c b/src/ld65/dbgfile.c index 956dcdc22..20c64a1ec 100644 --- a/src/ld65/dbgfile.c +++ b/src/ld65/dbgfile.c @@ -102,6 +102,19 @@ void CreateDbgFile (void) /* Output version information */ fprintf (F, "version\tmajor=2,minor=0\n"); + /* Output a line with the item numbers so the debug info module is able + * to preallocate the required memory. + */ + fprintf ( + F, + "info\tlib=%u,mod=%u,seg=%u,file=%u,scope=%u\n", + LibraryCount (), + ObjDataCount (), + SegmentCount (), + FileInfoCount (), + ScopeCount () + ); + /* Assign the ids to the items */ AssignIds (); diff --git a/src/ld65/fileinfo.c b/src/ld65/fileinfo.c index 36a93f856..6c17fbd4a 100644 --- a/src/ld65/fileinfo.c +++ b/src/ld65/fileinfo.c @@ -193,6 +193,14 @@ FileInfo* ReadFileInfo (FILE* F, ObjData* O) +unsigned FileInfoCount (void) +/* Return the total number of file infos */ +{ + return CollCount (&FileInfos); +} + + + void AssignFileInfoIds (void) /* Remove unused file infos and assign the ids to the remaining ones */ { diff --git a/src/ld65/fileinfo.h b/src/ld65/fileinfo.h index 23c5b4700..c4efc5a3a 100644 --- a/src/ld65/fileinfo.h +++ b/src/ld65/fileinfo.h @@ -75,6 +75,9 @@ struct FileInfo { FileInfo* ReadFileInfo (FILE* F, ObjData* O); /* Read a file info from a file and return it */ +unsigned FileInfoCount (void); +/* Return the total number of file infos */ + void AssignFileInfoIds (void); /* Assign the ids to the file infos */ diff --git a/src/ld65/library.c b/src/ld65/library.c index 56fd1d3a5..b74816e9c 100644 --- a/src/ld65/library.c +++ b/src/ld65/library.c @@ -76,7 +76,7 @@ struct Library { static Collection OpenLibs = STATIC_COLLECTION_INITIALIZER; /* List of used libraries */ -static Collection Libraries = STATIC_COLLECTION_INITIALIZER; +static Collection LibraryList = STATIC_COLLECTION_INITIALIZER; /* Flag for library grouping */ static int Grouping = 0; @@ -431,8 +431,8 @@ static void LibResolve (void) */ if (CollCount (&L->Modules) > 0) { CloseLibrary (L); - L->Id = CollCount (&Libraries); - CollAppend (&Libraries, L); + L->Id = CollCount (&LibraryList); + CollAppend (&LibraryList, L); } else { /* Delete the library */ FreeLibrary (L); @@ -526,15 +526,23 @@ unsigned GetLibId (const Library* L) +unsigned LibraryCount (void) +/* Return the total number of libraries */ +{ + return CollCount (&LibraryList); +} + + + 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) { + for (I = 0; I < CollCount (&LibraryList); ++I) { /* Get the library */ - const Library* L = CollAtUnchecked (&Libraries, I); + const Library* L = CollAtUnchecked (&LibraryList, 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 6cae0d8cf..425b32181 100644 --- a/src/ld65/library.h +++ b/src/ld65/library.h @@ -81,6 +81,9 @@ const char* GetLibFileName (const struct Library* L); unsigned GetLibId (const struct Library* L); /* Get the id of a library file. */ +unsigned LibraryCount (void); +/* Return the total number of libraries */ + void PrintDbgLibraries (FILE* F); /* Output the libraries to a debug info file */ diff --git a/src/ld65/objdata.c b/src/ld65/objdata.c index 1635c14a0..15336b35d 100644 --- a/src/ld65/objdata.c +++ b/src/ld65/objdata.c @@ -216,6 +216,14 @@ struct Scope* GetObjScope (ObjData* O, unsigned 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 */ { diff --git a/src/ld65/objdata.h b/src/ld65/objdata.h index 349384d7a..975acef01 100644 --- a/src/ld65/objdata.h +++ b/src/ld65/objdata.h @@ -145,6 +145,9 @@ struct Section* GetObjSection (ObjData* Obj, unsigned Id); struct Scope* GetObjScope (ObjData* Obj, unsigned Id); /* Get a scope from an object file checking for a valid index */ +unsigned ObjDataCount (void); +/* Return the total number of modules */ + void PrintDbgModules (FILE* F); /* Output the modules to a debug info file */ diff --git a/src/ld65/scopes.c b/src/ld65/scopes.c index c315ec9cd..4f06b6d23 100644 --- a/src/ld65/scopes.c +++ b/src/ld65/scopes.c @@ -98,6 +98,25 @@ Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id) +unsigned ScopeCount (void) +/* Return the total number of scopes */ +{ + + /* Count scopes from all modules we have linked into the output file */ + unsigned I; + unsigned Count = 0; + for (I = 0; I < CollCount (&ObjDataList); ++I) { + /* Get the object file */ + const ObjData* O = CollAtUnchecked (&ObjDataList, I); + + /* Account for the scopes in this file */ + Count += CollCount (&O->Scopes); + } + return Count; +} + + + void PrintDbgScopes (FILE* F) /* Output the scopes to a debug info file */ { @@ -132,7 +151,7 @@ void PrintDbgScopes (FILE* F) if (SCOPE_HAS_LABEL (S->Flags)) { fprintf (F, ",sym=%u", O->SymBaseId + S->LabelId); } - + /* Terminate the output line */ fputc ('\n', F); } diff --git a/src/ld65/scopes.h b/src/ld65/scopes.h index 6c772e430..60c1c71b1 100644 --- a/src/ld65/scopes.h +++ b/src/ld65/scopes.h @@ -62,7 +62,7 @@ struct Scope { ObjData* Obj; /* Object file that contains the scope */ unsigned ParentId; /* Id of parent scope */ unsigned LabelId; /* Id of the scope label if any */ - unsigned LexicalLevel; /* Lexical level */ + unsigned LexicalLevel; /* Lexical level */ unsigned Flags; unsigned Type; /* Type of scope */ unsigned Name; /* Name of scope */ @@ -81,6 +81,9 @@ struct Scope { Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id); /* Read a scope from a file, insert and return it */ +unsigned ScopeCount (void); +/* Return the total number of scopes */ + void PrintDbgScopes (FILE* F); /* Output the scopes to a debug info file */ diff --git a/src/ld65/segments.c b/src/ld65/segments.c index 10f23bbe2..ae709d0eb 100644 --- a/src/ld65/segments.c +++ b/src/ld65/segments.c @@ -347,7 +347,7 @@ void SegDump (void) unsigned I; unsigned long Count; unsigned char* Data; - + for (I = 0; I < CollCount (&SegmentList); ++I) { const Segment* Seg = CollConstAt (&SegmentList, I); Section* S = Seg->SecRoot; @@ -546,6 +546,14 @@ void SegWrite (const char* TgtName, FILE* Tgt, Segment* S, SegWriteFunc F, void* +unsigned SegmentCount (void) +/* Return the total number of segments */ +{ + return CollCount (&SegmentList); +} + + + static int CmpSegStart (const void* K1, const void* K2) /* Compare function for qsort */ { @@ -613,7 +621,7 @@ void PrintSegmentMap (FILE* F) void PrintDbgSegments (FILE* F) /* Output the segments to the debug file */ -{ +{ /* Walk over all segments */ unsigned I; for (I = 0; I < CollCount (&SegmentList); ++I) { diff --git a/src/ld65/segments.h b/src/ld65/segments.h index 5d7e10532..32d7ab114 100644 --- a/src/ld65/segments.h +++ b/src/ld65/segments.h @@ -147,6 +147,9 @@ void SegWrite (const char* TgtName, FILE* Tgt, Segment* S, SegWriteFunc F, void* * called (see description of SegWriteFunc above). */ +unsigned SegmentCount (void); +/* Return the total number of segments */ + void PrintSegmentMap (FILE* F); /* Print a segment map to the given file */