From: Christian Groessler Date: Thu, 20 Mar 2014 01:01:21 +0000 (+0100) Subject: Extend the map file to include a table of exports sorted by value. X-Git-Tag: V2.15~96^2~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d72e62cae20954d0b7ce23bc8e908a61e4f2e634;p=cc65 Extend the map file to include a table of exports sorted by value. --- diff --git a/src/ld65/exports.c b/src/ld65/exports.c index 9caa2ba57..937883d0d 100644 --- a/src/ld65/exports.c +++ b/src/ld65/exports.c @@ -870,8 +870,8 @@ static char GetAddrSizeCode (unsigned char AddrSize) -void PrintExportMap (FILE* F) -/* Print an export map to the given file */ +void PrintExportMapByName (FILE* F) +/* Print an export map, sorted by symbol name, to the given file */ { unsigned I; unsigned Count; @@ -902,6 +902,61 @@ void PrintExportMap (FILE* F) +static int CmpExpValue (const void* I1, const void* I2) +/* Compare function for qsort */ +{ + long V1 = GetExportVal (ExpPool [*(unsigned *)I1]); + long V2 = GetExportVal (ExpPool [*(unsigned *)I2]); + + return V1 < V2 ? -1 : V1 == V2 ? 0 : 1; +} + + + +void PrintExportMapByValue (FILE* F) +/* Print an export map, sorted by symbol value, to the given file */ +{ + unsigned I; + unsigned Count; + unsigned *ExpValXlat; + + /* Create a translation table where the symbols are sorted by value. */ + ExpValXlat = xmalloc (ExpCount * sizeof (unsigned)); + for (I = 0; I < ExpCount; ++I) { + /* Initialize table with current sort order. */ + ExpValXlat [I] = I; + } + + /* Sort them by value */ + qsort (ExpValXlat, ExpCount, sizeof (unsigned), CmpExpValue); + + /* Print all exports */ + Count = 0; + for (I = 0; I < ExpCount; ++I) { + const Export* E = ExpPool [ExpValXlat [I]]; + + /* Print unreferenced symbols only if explictly requested */ + if (VerboseMap || E->ImpCount > 0 || SYM_IS_CONDES (E->Type)) { + fprintf (F, + "%-25s %06lX %c%c%c%c ", + GetString (E->Name), + GetExportVal (E), + E->ImpCount? 'R' : ' ', + SYM_IS_LABEL (E->Type)? 'L' : 'E', + GetAddrSizeCode ((unsigned char) E->AddrSize), + SYM_IS_CONDES (E->Type)? 'I' : ' '); + if (++Count == 2) { + Count = 0; + fprintf (F, "\n"); + } + } + } + fprintf (F, "\n"); + xfree (ExpValXlat); +} + + + void PrintImportMap (FILE* F) /* Print an import map to the given file */ { diff --git a/src/ld65/exports.h b/src/ld65/exports.h index 2b7c55bed..2c0bbca95 100644 --- a/src/ld65/exports.h +++ b/src/ld65/exports.h @@ -186,8 +186,11 @@ void CheckUnresolvedImports (ExpCheckFunc F, void* Data); * called (see the comments on ExpCheckFunc in the data section). */ -void PrintExportMap (FILE* F); -/* Print an export map to the given file */ +void PrintExportMapByName (FILE* F); +/* Print an export map to the given file (sorted by symbol name) */ + +void PrintExportMapByValue (FILE* F); +/* Print an export map to the given file (sorted by export value) */ void PrintImportMap (FILE* F); /* Print an import map to the given file */ diff --git a/src/ld65/mapfile.c b/src/ld65/mapfile.c index 6b13e46ec..e1d0e8098 100644 --- a/src/ld65/mapfile.c +++ b/src/ld65/mapfile.c @@ -111,11 +111,17 @@ void CreateMapFile (int ShortMap) /* The remainder is not written for short map files */ if (!ShortMap) { - /* Write the exports list */ + /* Write the exports list by name */ fprintf (F, "\n\n" - "Exports list:\n" - "-------------\n"); - PrintExportMap (F); + "Exports list by name:\n" + "---------------------\n"); + PrintExportMapByName (F); + + /* Write the exports list by value */ + fprintf (F, "\n\n" + "Exports list by value\n" + "---------------------\n"); + PrintExportMapByValue (F); /* Write the imports list */ fprintf (F, "\n\n"