/* ld65 */
#include "condes.h"
#include "error.h"
+#include "exports.h"
+#include "expr.h"
#include "fileio.h"
#include "global.h"
#include "objdata.h"
-#include "expr.h"
-#include "exports.h"
+#include "spool.h"
/* Hash table */
-#define HASHTAB_SIZE 4081
-static Export* HashTab [HASHTAB_SIZE];
+#define HASHTAB_MASK 0x0FFFU
+#define HASHTAB_SIZE (HASHTAB_MASK + 1)
+static Export* HashTab[HASHTAB_SIZE];
/* Import management variables */
static unsigned ImpCount = 0; /* Import count */
-static Export* NewExport (unsigned char Type, const char* Name, ObjData* Obj);
+static Export* NewExport (unsigned char Type, unsigned Name, ObjData* Obj);
/* Create a new export and initialize it */
/* Initialize the fields */
I->Next = 0;
I->Obj = Obj;
- I->V.Name = 0;
+ I->Exp = 0;
+ I->Name = INVALID_STRING_ID;
I->Type = Type;
/* Return the new structure */
/* Insert an import into the table */
{
Export* E;
- unsigned HashVal;
/* As long as the import is not inserted, V.Name is valid */
- const char* Name = I->V.Name;
+ unsigned Name = I->Name;
/* Create a hash value for the given name */
- HashVal = HashStr (Name) % HASHTAB_SIZE;
+ unsigned Hash = (Name & HASHTAB_MASK);
/* Search through the list in that slot and print matching duplicates */
- if (HashTab [HashVal] == 0) {
+ if (HashTab[Hash] == 0) {
/* The slot is empty, we need to insert a dummy export */
- E = HashTab [HashVal] = NewExport (0, Name, 0);
+ E = HashTab[Hash] = NewExport (0, Name, 0);
++ExpCount;
} else {
- E = HashTab [HashVal];
+ E = HashTab [Hash];
while (1) {
- if (strcmp (E->Name, Name) == 0) {
+ if (E->Name == Name) {
/* We have an entry, L points to it */
- break;
+ break;
}
if (E->Next == 0) {
/* End of list an entry not found, insert a dummy */
/* Ok, E now points to a valid exports entry for the given import. Insert
* the import into the imports list and update the counters.
*/
- I->V.Exp = E;
+ I->Exp = E;
I->Next = E->ImpList;
E->ImpList = I;
E->ImpCount++;
I = NewImport (Type, Obj);
/* Read the name */
- I->V.Name = GetObjString (Obj, ReadVar (F));
+ I->Name = MakeGlobalStringId (Obj, ReadVar (F));
/* Read the file position */
ReadFilePos (F, &I->Pos);
-static Export* NewExport (unsigned char Type, const char* Name, ObjData* Obj)
+static Export* NewExport (unsigned char Type, unsigned Name, ObjData* Obj)
/* Create a new export and initialize it */
{
/* Allocate memory */
Export* E = xmalloc (sizeof (Export));
/* Initialize the fields */
+ E->Name = Name;
E->Next = 0;
E->Flags = 0;
E->Obj = Obj;
E->Expr = 0;
E->Type = Type;
memset (E->ConDes, 0, sizeof (E->ConDes));
- if (Name) {
- E->Name = xstrdup (Name);
- } else {
- /* Name will get added later */
- E->Name = 0;
- }
/* Return the new entry */
return E;
Export* L;
Export* Last;
Import* Imp;
- unsigned HashVal;
+ unsigned Hash;
/* Insert the export into any condes tables if needed */
if (IS_EXP_CONDES (E->Type)) {
}
/* Create a hash value for the given name */
- HashVal = HashStr (E->Name) % HASHTAB_SIZE;
+ Hash = (E->Name & HASHTAB_MASK);
/* Search through the list in that slot */
- if (HashTab [HashVal] == 0) {
+ if (HashTab[Hash] == 0) {
/* The slot is empty */
- HashTab [HashVal] = E;
+ HashTab[Hash] = E;
++ExpCount;
} else {
Last = 0;
- L = HashTab [HashVal];
+ L = HashTab[Hash];
do {
- if (strcmp (L->Name, E->Name) == 0) {
- /* This may be an unresolved external */
- if (L->Expr == 0) {
-
- /* This *is* an unresolved external */
- E->Next = L->Next;
- E->ImpCount = L->ImpCount;
- E->ImpList = L->ImpList;
+ if (L->Name == E->Name) {
+ /* This may be an unresolved external */
+ if (L->Expr == 0) {
+
+ /* This *is* an unresolved external */
+ E->Next = L->Next;
+ E->ImpCount = L->ImpCount;
+ E->ImpList = L->ImpList;
if (Last) {
Last->Next = E;
} else {
- HashTab [HashVal] = E;
+ HashTab[Hash] = E;
}
ImpOpen -= E->ImpCount; /* Decrease open imports now */
xfree (L);
*/
Imp = E->ImpList;
while (Imp) {
- Imp->V.Exp = E;
+ Imp->Exp = E;
Imp = Imp->Next;
}
} else {
/* Duplicate entry, ignore it */
- Warning ("Duplicate external identifier: `%s'", L->Name);
+ Warning ("Duplicate external identifier: `%s'",
+ GetString (L->Name));
}
return;
}
Type = Read8 (F);
/* Create a new export without a name */
- E = NewExport (Type, 0, O);
+ E = NewExport (Type, INVALID_STRING_ID, O);
/* Read the constructor/destructor decls if we have any */
ConDesCount = GET_EXP_CONDES_COUNT (Type);
}
/* Read the name */
- E->Name = GetObjString (O, ReadVar (F));
+ E->Name = MakeGlobalStringId (O, ReadVar (F));
/* Read the value */
if (IS_EXP_EXPR (Type)) {
-Export* CreateConstExport (const char* Name, long Value)
+Export* CreateConstExport (unsigned Name, long Value)
/* Create an export for a literal date */
{
/* Create a new export */
-Export* CreateMemoryExport (const char* Name, Memory* Mem, unsigned long Offs)
+Export* CreateMemoryExport (unsigned Name, Memory* Mem, unsigned long Offs)
/* Create an relative export for a memory area offset */
{
/* Create a new export */
-Export* CreateSegmentExport (const char* Name, Segment* Seg, unsigned long Offs)
+Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs)
/* Create a relative export to a segment */
{
/* Create a new export */
-Export* CreateSectionExport (const char* Name, Section* Sec, unsigned long Offs)
+Export* CreateSectionExport (unsigned Name, Section* Sec, unsigned long Offs)
/* Create a relative export to a section */
{
/* Create a new export */
-Export* FindExport (const char* Name)
+Export* FindExport (unsigned Name)
/* Check for an identifier in the list. Return 0 if not found, otherwise
* return a pointer to the export.
*/
{
/* Get a pointer to the list with the symbols hash value */
- Export* L = HashTab [HashStr (Name) % HASHTAB_SIZE];
+ Export* L = HashTab[Name & HASHTAB_MASK];
while (L) {
/* Search through the list in that slot */
- if (strcmp (L->Name, Name) == 0) {
+ if (L->Name == Name) {
/* Entry found */
return L;
}
-int IsUnresolved (const char* Name)
+int IsUnresolved (unsigned Name)
/* Check if this symbol is an unresolved export */
{
/* Find the export */
{
if (E->Expr == 0) {
/* OOPS */
- Internal ("`%s' is an undefined external", E->Name);
+ Internal ("`%s' is an undefined external", GetString (E->Name));
}
return GetExprVal (E->Expr);
}
/* User defined export */
Warning ("Type mismatch for `%s', export in "
"%s(%lu), import in %s(%lu)",
- E->Name, GetSourceFileName (E->Obj, Imp->Pos.Name),
- E->Pos.Line, GetSourceFileName (Imp->Obj, Imp->Pos.Name),
+ GetString (E->Name),
+ GetSourceFileName (E->Obj, Imp->Pos.Name),
+ E->Pos.Line,
+ GetSourceFileName (Imp->Obj, Imp->Pos.Name),
Imp->Pos.Line);
} else {
/* Export created by the linker */
Warning ("Type mismatch for `%s', imported from %s(%lu)",
- E->Name, GetSourceFileName (Imp->Obj, Imp->Pos.Name),
+ GetString (E->Name),
+ GetSourceFileName (Imp->Obj, Imp->Pos.Name),
Imp->Pos.Line);
}
}
Import* Imp = E->ImpList;
fprintf (stderr,
"Unresolved external `%s' referenced in:\n",
- E->Name);
+ GetString (E->Name));
while (Imp) {
const char* Name = GetSourceFileName (Imp->Obj, Imp->Pos.Name);
fprintf (stderr, " %s(%lu)\n", Name, Imp->Pos.Line);
static int CmpExpName (const void* K1, const void* K2)
/* Compare function for qsort */
{
- return strcmp ((*(Export**)K1)->Name, (*(Export**)K2)->Name);
+ return strcmp (GetString ((*(Export**)K1)->Name),
+ GetString ((*(Export**)K2)->Name));
}
/* Walk through the list and insert the exports */
for (I = 0, J = 0; I < sizeof (HashTab) / sizeof (HashTab [0]); ++I) {
- Export* E = HashTab [I];
+ Export* E = HashTab[I];
while (E) {
CHECK (J < ExpCount);
- ExpPool [J++] = E;
+ ExpPool[J++] = E;
E = E->Next;
}
}
if (VerboseMap || E->ImpCount > 0 || IS_EXP_CONDES (E->Type)) {
fprintf (F,
"%-25s %06lX %c%c%c%c ",
- E->Name,
+ GetString (E->Name),
GetExportVal (E),
E->ImpCount? 'R' : ' ',
IS_EXP_LABEL (E->Type)? 'L' : 'E',
/* Print the export */
fprintf (F,
"%s (%s):\n",
- Exp->Name,
+ GetString (Exp->Name),
GetObjFileName (Exp->Obj));
/* Print all imports for this symbol */
/* Print all exports */
for (I = 0; I < ExpCount; ++I) {
const Export* E = ExpPool [I];
- fprintf (F, "al %06lX .%s\n", GetExportVal (E), E->Name);
+ fprintf (F, "al %06lX .%s\n", GetExportVal (E), GetString (E->Name));
}
}
/* Print an error about a circular reference using to define the given export */
{
Error ("Circular reference for symbol `%s', %s(%lu)",
- E->Name, GetSourceFileName (E->Obj, E->Pos.Name), E->Pos.Line);
+ GetString (E->Name),
+ GetSourceFileName (E->Obj, E->Pos.Name),
+ E->Pos.Line);
}
+