mirror of
https://github.com/cc65/cc65.git
synced 2025-02-05 20:31:53 +00:00
Fix issue #2044. While doing so, cleanup copy&pasted code.
This commit is contained in:
parent
b688cfa0c0
commit
35c3fe5d0a
@ -889,6 +889,7 @@ static void ParseO65 (void)
|
|||||||
CfgOptionalAssign ();
|
CfgOptionalAssign ();
|
||||||
|
|
||||||
/* Check which attribute was given */
|
/* Check which attribute was given */
|
||||||
|
CfgSymbol* Sym;
|
||||||
switch (AttrTok) {
|
switch (AttrTok) {
|
||||||
|
|
||||||
case CFGTOK_EXPORT:
|
case CFGTOK_EXPORT:
|
||||||
@ -896,8 +897,11 @@ static void ParseO65 (void)
|
|||||||
AttrFlags |= atExport;
|
AttrFlags |= atExport;
|
||||||
/* We expect an identifier */
|
/* We expect an identifier */
|
||||||
CfgAssureIdent ();
|
CfgAssureIdent ();
|
||||||
/* Remember it as an export for later */
|
/* Remember it as an export for later. We do not support o65
|
||||||
NewCfgSymbol (CfgSymO65Export, GetStrBufId (&CfgSVal));
|
* output for the 65816, so the address size is always 16 bit.
|
||||||
|
*/
|
||||||
|
Sym = NewCfgSymbol (CfgSymO65Export, GetStrBufId (&CfgSVal));
|
||||||
|
Sym->AddrSize = ADDR_SIZE_ABS;
|
||||||
/* Eat the identifier token */
|
/* Eat the identifier token */
|
||||||
CfgNextTok ();
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
@ -907,8 +911,11 @@ static void ParseO65 (void)
|
|||||||
AttrFlags |= atImport;
|
AttrFlags |= atImport;
|
||||||
/* We expect an identifier */
|
/* We expect an identifier */
|
||||||
CfgAssureIdent ();
|
CfgAssureIdent ();
|
||||||
/* Remember it as an import for later */
|
/* Remember it as an import for later. We do not support o65
|
||||||
NewCfgSymbol (CfgSymO65Import, GetStrBufId (&CfgSVal));
|
* output for the 65816, so the address size is always 16 bit.
|
||||||
|
*/
|
||||||
|
Sym = NewCfgSymbol (CfgSymO65Import, GetStrBufId (&CfgSVal));
|
||||||
|
Sym->AddrSize = ADDR_SIZE_ABS;
|
||||||
/* Eat the identifier token */
|
/* Eat the identifier token */
|
||||||
CfgNextTok ();
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
@ -808,6 +808,15 @@ static int CmpExpName (const void* K1, const void* K2)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int CmpExpValue (const void* K1, const void* K2)
|
||||||
|
/* Compare function for qsort */
|
||||||
|
{
|
||||||
|
long Diff = GetExportVal (*(Export**)K1) - GetExportVal (*(Export**)K2);
|
||||||
|
return Diff < 0? -1 : Diff > 0? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void CreateExportPool (void)
|
static void CreateExportPool (void)
|
||||||
/* Create an array with pointer to all exports */
|
/* Create an array with pointer to all exports */
|
||||||
{
|
{
|
||||||
@ -880,19 +889,25 @@ static char GetAddrSizeCode (unsigned char AddrSize)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PrintExportMapByName (FILE* F)
|
static void PrintExportMap (Export** Pool, unsigned Count, FILE* F)
|
||||||
/* Print an export map, sorted by symbol name, to the given file */
|
/* Print an export map to the given file */
|
||||||
{
|
{
|
||||||
unsigned I;
|
unsigned I;
|
||||||
unsigned Count;
|
|
||||||
|
|
||||||
/* Print all exports */
|
/* Print all exports */
|
||||||
Count = 0;
|
unsigned Col = 0;
|
||||||
for (I = 0; I < ExpCount; ++I) {
|
for (I = 0; I < Count; ++I) {
|
||||||
const Export* E = ExpPool [I];
|
const Export* E = Pool [I];
|
||||||
|
|
||||||
/* Print unreferenced symbols only if explictly requested */
|
/* Print unreferenced symbols only if explictly requested. If Expr is
|
||||||
if (VerboseMap || E->ImpCount > 0 || SYM_IS_CONDES (E->Type)) {
|
** NULL, the export is undefined. This happens for imports that don't
|
||||||
|
** have a matching export, but if we have one of those, we don't come
|
||||||
|
** here. It does also happen for imports that where satisfied from
|
||||||
|
** elsewhere, like o65 imports defined in the linker config.
|
||||||
|
** So ignore exports here that have an invalid Expr.
|
||||||
|
*/
|
||||||
|
if (E->Expr != 0 &&
|
||||||
|
(VerboseMap || E->ImpCount > 0 || SYM_IS_CONDES (E->Type))) {
|
||||||
fprintf (F,
|
fprintf (F,
|
||||||
"%-25s %06lX %c%c%c%c ",
|
"%-25s %06lX %c%c%c%c ",
|
||||||
GetString (E->Name),
|
GetString (E->Name),
|
||||||
@ -901,8 +916,8 @@ void PrintExportMapByName (FILE* F)
|
|||||||
SYM_IS_LABEL (E->Type)? 'L' : 'E',
|
SYM_IS_LABEL (E->Type)? 'L' : 'E',
|
||||||
GetAddrSizeCode ((unsigned char) E->AddrSize),
|
GetAddrSizeCode ((unsigned char) E->AddrSize),
|
||||||
SYM_IS_CONDES (E->Type)? 'I' : ' ');
|
SYM_IS_CONDES (E->Type)? 'I' : ' ');
|
||||||
if (++Count == 2) {
|
if (++Col == 2) {
|
||||||
Count = 0;
|
Col = 0;
|
||||||
fprintf (F, "\n");
|
fprintf (F, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -912,13 +927,10 @@ void PrintExportMapByName (FILE* F)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int CmpExpValue (const void* I1, const void* I2)
|
void PrintExportMapByName (FILE* F)
|
||||||
/* Compare function for qsort */
|
/* Print an export map, sorted by symbol name, to the given file */
|
||||||
{
|
{
|
||||||
long V1 = GetExportVal (ExpPool [*(unsigned *)I1]);
|
PrintExportMap (ExpPool, ExpCount, F);
|
||||||
long V2 = GetExportVal (ExpPool [*(unsigned *)I2]);
|
|
||||||
|
|
||||||
return V1 < V2 ? -1 : V1 == V2 ? 0 : 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -926,43 +938,16 @@ static int CmpExpValue (const void* I1, const void* I2)
|
|||||||
void PrintExportMapByValue (FILE* F)
|
void PrintExportMapByValue (FILE* F)
|
||||||
/* Print an export map, sorted by symbol value, to the given file */
|
/* Print an export map, sorted by symbol value, to the given file */
|
||||||
{
|
{
|
||||||
unsigned I;
|
/* Create a new pool that is sorted by value */
|
||||||
unsigned Count;
|
Export** Pool = xmalloc (ExpCount * sizeof (Export*));
|
||||||
unsigned *ExpValXlat;
|
memcpy (Pool, ExpPool, ExpCount * sizeof (Export*));
|
||||||
|
qsort (Pool, ExpCount, sizeof (Export*), CmpExpValue);
|
||||||
|
|
||||||
/* Create a translation table where the symbols are sorted by value. */
|
/* Print the exports */
|
||||||
ExpValXlat = xmalloc (ExpCount * sizeof (unsigned));
|
PrintExportMap (Pool, ExpCount, F);
|
||||||
for (I = 0; I < ExpCount; ++I) {
|
|
||||||
/* Initialize table with current sort order. */
|
|
||||||
ExpValXlat [I] = I;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Sort them by value */
|
/* Free the allocated buffer */
|
||||||
qsort (ExpValXlat, ExpCount, sizeof (unsigned), CmpExpValue);
|
xfree (Pool);
|
||||||
|
|
||||||
/* 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user