More string pool use
git-svn-id: svn://svn.cc65.org/cc65/trunk@2198 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2000 Ullrich von Bassewitz */
|
/* (C) 2000-2003 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* R<>merstrasse 52 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@musoftware.de */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
@@ -37,13 +37,15 @@
|
|||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
#include "coll.h"
|
||||||
#include "hashstr.h"
|
#include "hashstr.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
/* ca65 */
|
/* ca65 */
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "objfile.h"
|
|
||||||
#include "filetab.h"
|
#include "filetab.h"
|
||||||
|
#include "objfile.h"
|
||||||
|
#include "spool.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -56,65 +58,46 @@
|
|||||||
/* An entry in the file table */
|
/* An entry in the file table */
|
||||||
typedef struct FileEntry FileEntry;
|
typedef struct FileEntry FileEntry;
|
||||||
struct FileEntry {
|
struct FileEntry {
|
||||||
|
unsigned Name; /* File name */
|
||||||
FileEntry* Next; /* Next in hash list */
|
FileEntry* Next; /* Next in hash list */
|
||||||
unsigned Index; /* Index of entry */
|
unsigned Index; /* Index of entry */
|
||||||
unsigned long Size; /* Size of file */
|
unsigned long Size; /* Size of file */
|
||||||
unsigned long MTime; /* Time of last modification */
|
unsigned long MTime; /* Time of last modification */
|
||||||
char Name[1]; /* Name, dynamically allocated */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Array of all entries, listed by index */
|
/* Array of all entries, listed by index */
|
||||||
static FileEntry** FileTab = 0;
|
static Collection FileTab = STATIC_COLLECTION_INITIALIZER;
|
||||||
static unsigned FileCount = 0;
|
|
||||||
static unsigned FileMax = 0;
|
|
||||||
|
|
||||||
/* Hash table, hashed by name */
|
/* Hash table, hashed by name */
|
||||||
#define HASHTAB_SIZE 31
|
#define HASHTAB_MASK 0x1FU
|
||||||
|
#define HASHTAB_SIZE (HASHTAB_MASK + 1)
|
||||||
static FileEntry* HashTab[HASHTAB_SIZE];
|
static FileEntry* HashTab[HASHTAB_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Code */
|
/* Code */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static FileEntry* NewFileEntry (const char* Name, unsigned long Size, unsigned long MTime)
|
static FileEntry* NewFileEntry (unsigned Name, unsigned long Size, unsigned long MTime)
|
||||||
/* Create a new FileEntry, insert it into the tables and return it */
|
/* Create a new FileEntry, insert it into the tables and return it */
|
||||||
{
|
{
|
||||||
/* Get the length of the name */
|
|
||||||
unsigned Len = strlen (Name);
|
|
||||||
|
|
||||||
/* Get the hash over the name */
|
/* Get the hash over the name */
|
||||||
unsigned Hash = HashStr (Name) % HASHTAB_SIZE;
|
unsigned Hash = (Name & HASHTAB_MASK);
|
||||||
|
|
||||||
/* Allocate memory for the entry */
|
/* Allocate memory for the entry */
|
||||||
FileEntry* F = xmalloc (sizeof (FileEntry) + Len);
|
FileEntry* F = xmalloc (sizeof (FileEntry));
|
||||||
|
|
||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
F->Index = FileCount+1;
|
F->Name = Name;
|
||||||
|
F->Index = CollCount (&FileTab) + 1; /* First file has index #1 */
|
||||||
F->Size = Size;
|
F->Size = Size;
|
||||||
F->MTime = MTime;
|
F->MTime = MTime;
|
||||||
memcpy (F->Name, Name, Len+1);
|
|
||||||
|
|
||||||
/* Count the entries and grow the file table if needed */
|
|
||||||
if (FileCount >= FileMax) {
|
|
||||||
/* We need to grow the table. Create a new one. */
|
|
||||||
unsigned NewFileMax = (FileMax == 0)? 32 : FileMax * 2;
|
|
||||||
FileEntry** NewFileTab = xmalloc (sizeof (FileEntry*) * NewFileMax);
|
|
||||||
|
|
||||||
/* Copy the old entries */
|
|
||||||
memcpy (NewFileTab, FileTab, sizeof (FileEntry*) * FileCount);
|
|
||||||
|
|
||||||
/* Use the new table */
|
|
||||||
xfree (FileTab);
|
|
||||||
FileTab = NewFileTab;
|
|
||||||
FileMax = NewFileMax;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Insert the file into the file table */
|
/* Insert the file into the file table */
|
||||||
FileTab [FileCount++] = F;
|
CollAppend (&FileTab, F);
|
||||||
|
|
||||||
/* Insert the entry into the hash table */
|
/* Insert the entry into the hash table */
|
||||||
F->Next = HashTab[Hash];
|
F->Next = HashTab[Hash];
|
||||||
@@ -129,21 +112,23 @@ static FileEntry* NewFileEntry (const char* Name, unsigned long Size, unsigned l
|
|||||||
const char* GetFileName (unsigned Name)
|
const char* GetFileName (unsigned Name)
|
||||||
/* Get the name of a file where the name index is known */
|
/* Get the name of a file where the name index is known */
|
||||||
{
|
{
|
||||||
PRECONDITION (Name <= FileCount);
|
const FileEntry* F;
|
||||||
|
|
||||||
if (Name == 0) {
|
if (Name == 0) {
|
||||||
/* Name was defined outside any file scope, use the name of the first
|
/* Name was defined outside any file scope, use the name of the first
|
||||||
* file instead. Errors are then reported with a file position of
|
* file instead. Errors are then reported with a file position of
|
||||||
* line zero in the first file.
|
* line zero in the first file.
|
||||||
*/
|
*/
|
||||||
if (FileCount == 0) {
|
if (CollCount (&FileTab) == 0) {
|
||||||
/* No files defined until now */
|
/* No files defined until now */
|
||||||
return "(outside file scope)";
|
return "(outside file scope)";
|
||||||
} else {
|
} else {
|
||||||
return FileTab [0]->Name;
|
F = CollConstAt (&FileTab, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return FileTab [Name-1]->Name;
|
F = CollConstAt (&FileTab, Name-1);
|
||||||
}
|
}
|
||||||
|
return GetString (F->Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -151,14 +136,17 @@ const char* GetFileName (unsigned Name)
|
|||||||
unsigned GetFileIndex (const char* Name)
|
unsigned GetFileIndex (const char* Name)
|
||||||
/* Return the file index for the given file name. */
|
/* Return the file index for the given file name. */
|
||||||
{
|
{
|
||||||
|
/* Get the string pool index from the name */
|
||||||
|
unsigned NameIdx = GetStringId (Name);
|
||||||
|
|
||||||
/* Get the hash over the name */
|
/* Get the hash over the name */
|
||||||
unsigned Hash = HashStr (Name) % HASHTAB_SIZE;
|
unsigned Hash = (NameIdx & HASHTAB_MASK);
|
||||||
|
|
||||||
/* Search the linear hash list */
|
/* Search the linear hash list */
|
||||||
FileEntry* F = HashTab[Hash];
|
FileEntry* F = HashTab[Hash];
|
||||||
while (F) {
|
while (F) {
|
||||||
/* Is it this one? */
|
/* Is it this one? */
|
||||||
if (strcmp (Name, F->Name) == 0) {
|
if (NameIdx == F->Name) {
|
||||||
/* Found, return the index */
|
/* Found, return the index */
|
||||||
return F->Index;
|
return F->Index;
|
||||||
}
|
}
|
||||||
@@ -179,7 +167,7 @@ unsigned AddFile (const char* Name, unsigned long Size, unsigned long MTime)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Create a new file entry and insert it into the tables */
|
/* Create a new file entry and insert it into the tables */
|
||||||
FileEntry* F = NewFileEntry (Name, Size, MTime);
|
FileEntry* F = NewFileEntry (GetStringId (Name), Size, MTime);
|
||||||
|
|
||||||
/* Return the index */
|
/* Return the index */
|
||||||
return F->Index;
|
return F->Index;
|
||||||
@@ -196,16 +184,16 @@ void WriteFiles (void)
|
|||||||
ObjStartFiles ();
|
ObjStartFiles ();
|
||||||
|
|
||||||
/* Write the file count */
|
/* Write the file count */
|
||||||
ObjWriteVar (FileCount);
|
ObjWriteVar (CollCount (&FileTab));
|
||||||
|
|
||||||
/* Write the file data */
|
/* Write the file data */
|
||||||
for (I = 0; I < FileCount; ++I) {
|
for (I = 0; I < CollCount (&FileTab); ++I) {
|
||||||
/* Get a pointer to the entry */
|
/* Get a pointer to the entry */
|
||||||
FileEntry* F = FileTab[I];
|
const FileEntry* F = CollConstAt (&FileTab, I);
|
||||||
/* Write the fields */
|
/* Write the fields */
|
||||||
|
ObjWriteVar (F->Name);
|
||||||
ObjWrite32 (F->MTime);
|
ObjWrite32 (F->MTime);
|
||||||
ObjWrite32 (F->Size);
|
ObjWrite32 (F->Size);
|
||||||
ObjWriteStr (F->Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Done writing files */
|
/* Done writing files */
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2000 Ullrich von Bassewitz */
|
/* (C) 2000-2003 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* R<EFBFBD>merstrasse 52 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
|
|||||||
@@ -69,6 +69,16 @@ INLINE unsigned GetStringId (const char* S)
|
|||||||
# define GetStringId(S) SP_Add (&StrPool, (S))
|
# define GetStringId(S) SP_Add (&StrPool, (S))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE const char* GetString (unsigned Index)
|
||||||
|
/* Convert a string index into a string */
|
||||||
|
{
|
||||||
|
return SP_Get (&StrPool, Index);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define GetString(Index) SP_Get (&StrPool, (Index))
|
||||||
|
#endif
|
||||||
|
|
||||||
void WriteStrPool (void);
|
void WriteStrPool (void);
|
||||||
/* Write the string pool to the object file */
|
/* Write the string pool to the object file */
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2000-2001 Ullrich von Bassewitz */
|
/* (C) 2000-2003 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* R<>merstrasse 52 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@musoftware.de */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/* common */
|
||||||
#include "abend.h"
|
#include "abend.h"
|
||||||
#include "debugflag.h"
|
#include "debugflag.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
@@ -51,12 +52,19 @@
|
|||||||
void* xmalloc (size_t Size)
|
void* xmalloc (size_t Size)
|
||||||
/* Allocate memory, check for out of memory condition. Do some debugging */
|
/* Allocate memory, check for out of memory condition. Do some debugging */
|
||||||
{
|
{
|
||||||
/* Allocate memory */
|
void* P = 0;
|
||||||
void* P = malloc (Size);
|
|
||||||
|
|
||||||
/* Check for errors */
|
/* Allow zero sized requests and return NULL in this case */
|
||||||
if (P == 0 && Size != 0) {
|
if (Size) {
|
||||||
AbEnd ("Out of memory - requested block size = %lu", (unsigned long) Size);
|
|
||||||
|
/* Allocate memory */
|
||||||
|
P = malloc (Size);
|
||||||
|
|
||||||
|
/* Check for errors */
|
||||||
|
if (P == 0) {
|
||||||
|
AbEnd ("Out of memory - requested block size = %lu",
|
||||||
|
(unsigned long) Size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a pointer to the block */
|
/* Return a pointer to the block */
|
||||||
|
|||||||
@@ -834,6 +834,7 @@ static void ParseO65 (void)
|
|||||||
unsigned AttrFlags = atNone;
|
unsigned AttrFlags = atNone;
|
||||||
|
|
||||||
/* Remember the attributes read */
|
/* Remember the attributes read */
|
||||||
|
unsigned CfgSValId;
|
||||||
unsigned OS = 0; /* Initialize to keep gcc happy */
|
unsigned OS = 0; /* Initialize to keep gcc happy */
|
||||||
unsigned Version = 0;
|
unsigned Version = 0;
|
||||||
|
|
||||||
@@ -857,19 +858,21 @@ static void ParseO65 (void)
|
|||||||
AttrFlags |= atExport;
|
AttrFlags |= atExport;
|
||||||
/* We expect an identifier */
|
/* We expect an identifier */
|
||||||
CfgAssureIdent ();
|
CfgAssureIdent ();
|
||||||
|
/* Convert the string into a string index */
|
||||||
|
CfgSValId = GetStringId (CfgSVal);
|
||||||
/* Check if the export symbol is also defined as an import. */
|
/* Check if the export symbol is also defined as an import. */
|
||||||
if (O65GetImport (O65FmtDesc, CfgSVal) != 0) {
|
if (O65GetImport (O65FmtDesc, CfgSValId) != 0) {
|
||||||
CfgError ("Exported symbol `%s' cannot be an import", CfgSVal);
|
CfgError ("Exported symbol `%s' cannot be an import", CfgSVal);
|
||||||
}
|
}
|
||||||
/* Check if we have this symbol defined already. The entry
|
/* Check if we have this symbol defined already. The entry
|
||||||
* routine will check this also, but we get a more verbose
|
* routine will check this also, but we get a more verbose
|
||||||
* error message when checking it here.
|
* error message when checking it here.
|
||||||
*/
|
*/
|
||||||
if (O65GetExport (O65FmtDesc, CfgSVal) != 0) {
|
if (O65GetExport (O65FmtDesc, CfgSValId) != 0) {
|
||||||
CfgError ("Duplicate exported symbol: `%s'", CfgSVal);
|
CfgError ("Duplicate exported symbol: `%s'", CfgSVal);
|
||||||
}
|
}
|
||||||
/* Insert the symbol into the table */
|
/* Insert the symbol into the table */
|
||||||
O65SetExport (O65FmtDesc, CfgSVal);
|
O65SetExport (O65FmtDesc, CfgSValId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_IMPORT:
|
case CFGTOK_IMPORT:
|
||||||
@@ -877,19 +880,21 @@ static void ParseO65 (void)
|
|||||||
AttrFlags |= atImport;
|
AttrFlags |= atImport;
|
||||||
/* We expect an identifier */
|
/* We expect an identifier */
|
||||||
CfgAssureIdent ();
|
CfgAssureIdent ();
|
||||||
|
/* Convert the string into a string index */
|
||||||
|
CfgSValId = GetStringId (CfgSVal);
|
||||||
/* Check if the imported symbol is also defined as an export. */
|
/* Check if the imported symbol is also defined as an export. */
|
||||||
if (O65GetExport (O65FmtDesc, CfgSVal) != 0) {
|
if (O65GetExport (O65FmtDesc, CfgSValId) != 0) {
|
||||||
CfgError ("Imported symbol `%s' cannot be an export", CfgSVal);
|
CfgError ("Imported symbol `%s' cannot be an export", CfgSVal);
|
||||||
}
|
}
|
||||||
/* Check if we have this symbol defined already. The entry
|
/* Check if we have this symbol defined already. The entry
|
||||||
* routine will check this also, but we get a more verbose
|
* routine will check this also, but we get a more verbose
|
||||||
* error message when checking it here.
|
* error message when checking it here.
|
||||||
*/
|
*/
|
||||||
if (O65GetImport (O65FmtDesc, CfgSVal) != 0) {
|
if (O65GetImport (O65FmtDesc, CfgSValId) != 0) {
|
||||||
CfgError ("Duplicate imported symbol: `%s'", CfgSVal);
|
CfgError ("Duplicate imported symbol: `%s'", CfgSVal);
|
||||||
}
|
}
|
||||||
/* Insert the symbol into the table */
|
/* Insert the symbol into the table */
|
||||||
O65SetImport (O65FmtDesc, CfgSVal);
|
O65SetImport (O65FmtDesc, CfgSValId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_TYPE:
|
case CFGTOK_TYPE:
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2001 Ullrich von Bassewitz */
|
/* (C) 2001-2003 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* R<EFBFBD>merstrasse 52 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
@@ -34,9 +34,10 @@
|
|||||||
|
|
||||||
|
|
||||||
/* ld65 */
|
/* ld65 */
|
||||||
|
#include "dbginfo.h"
|
||||||
#include "fileinfo.h"
|
#include "fileinfo.h"
|
||||||
#include "lineinfo.h"
|
#include "lineinfo.h"
|
||||||
#include "dbginfo.h"
|
#include "spool.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +55,8 @@ void PrintDbgInfo (ObjData* O, FILE* F)
|
|||||||
/* Output the files section */
|
/* Output the files section */
|
||||||
for (I = 0; I < O->FileCount; ++I) {
|
for (I = 0; I < O->FileCount; ++I) {
|
||||||
const FileInfo* FI = O->Files[I];
|
const FileInfo* FI = O->Files[I];
|
||||||
fprintf (F, "file\t\"%s\", %lu, %lu\n", FI->Name, FI->Size, FI->MTime);
|
fprintf (F, "file\t\"%s\", %lu, %lu\n",
|
||||||
|
GetString (FI->Name), FI->Size, FI->MTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Output the lines */
|
/* Output the lines */
|
||||||
@@ -72,7 +74,7 @@ void PrintDbgInfo (ObjData* O, FILE* F)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Name and line number */
|
/* Name and line number */
|
||||||
fprintf (F, "line\t\"%s\", %lu", LI->File->Name, LI->Pos.Line);
|
fprintf (F, "line\t\"%s\", %lu", GetString (LI->File->Name), LI->Pos.Line);
|
||||||
|
|
||||||
/* Code ranges */
|
/* Code ranges */
|
||||||
for (J = 0; J < CollCount (CodeRanges); ++J) {
|
for (J = 0; J < CollCount (CodeRanges); ++J) {
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1999-2001 Ullrich von Bassewitz */
|
/* (C) 1999-2003 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* R<EFBFBD>merstrasse 52 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@musoftware.de */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
@@ -42,6 +42,7 @@
|
|||||||
/* ld65 */
|
/* ld65 */
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "extsyms.h"
|
#include "extsyms.h"
|
||||||
|
#include "spool.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -53,20 +54,21 @@
|
|||||||
|
|
||||||
/* Structure holding an external symbol */
|
/* Structure holding an external symbol */
|
||||||
struct ExtSym {
|
struct ExtSym {
|
||||||
|
unsigned Name; /* Name index */
|
||||||
ExtSym* List; /* Next entry in list of all symbols */
|
ExtSym* List; /* Next entry in list of all symbols */
|
||||||
ExtSym* Next; /* Next entry in hash list */
|
ExtSym* Next; /* Next entry in hash list */
|
||||||
unsigned Flags; /* Generic flags */
|
unsigned Flags; /* Generic flags */
|
||||||
unsigned Num; /* Number of external symbol */
|
unsigned Num; /* Number of external symbol */
|
||||||
char Name [1]; /* Name - dynamically allocated */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* External symbol table structure */
|
/* External symbol table structure */
|
||||||
#define HASHTAB_SIZE 53
|
#define HASHTAB_MASK 0x3FU
|
||||||
|
#define HASHTAB_SIZE (HASHTAB_MASK + 1)
|
||||||
struct ExtSymTab {
|
struct ExtSymTab {
|
||||||
ExtSym* Root; /* List of symbols */
|
ExtSym* Root; /* List of symbols */
|
||||||
ExtSym* Last; /* Pointer to last symbol */
|
ExtSym* Last; /* Pointer to last symbol */
|
||||||
unsigned Count; /* Number of symbols */
|
unsigned Count; /* Number of symbols */
|
||||||
ExtSym* HashTab [HASHTAB_SIZE];
|
ExtSym* HashTab[HASHTAB_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -77,30 +79,27 @@ struct ExtSymTab {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ExtSym* NewExtSym (ExtSymTab* Tab, const char* Name)
|
ExtSym* NewExtSym (ExtSymTab* Tab, unsigned Name)
|
||||||
/* Create a new external symbol and insert it into the table */
|
/* Create a new external symbol and insert it into the table */
|
||||||
{
|
{
|
||||||
/* Get the hash value of the string */
|
/* Get the hash value of the string */
|
||||||
unsigned Hash = HashStr (Name) % HASHTAB_SIZE;
|
unsigned Hash = (Name & HASHTAB_MASK);
|
||||||
|
|
||||||
/* Get the length of the name */
|
|
||||||
unsigned Len = strlen (Name);
|
|
||||||
|
|
||||||
/* Check for duplicates */
|
/* Check for duplicates */
|
||||||
ExtSym* E = GetExtSym (Tab, Name); /* Don't care about duplicate hash here... */
|
ExtSym* E = GetExtSym (Tab, Name);
|
||||||
if (E != 0) {
|
if (E != 0) {
|
||||||
/* We do already have a symbol with this name */
|
/* We do already have a symbol with this name */
|
||||||
Error ("Duplicate external symbol `%s'", Name);
|
Error ("Duplicate external symbol `%s'", GetString (Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate memory for the structure */
|
/* Allocate memory for the structure */
|
||||||
E = xmalloc (sizeof (ExtSym) + Len);
|
E = xmalloc (sizeof (ExtSym));
|
||||||
|
|
||||||
/* Initialize the structure */
|
/* Initialize the structure */
|
||||||
|
E->Name = Name;
|
||||||
E->List = 0;
|
E->List = 0;
|
||||||
E->Flags = 0;
|
E->Flags = 0;
|
||||||
E->Num = Tab->Count;
|
E->Num = Tab->Count;
|
||||||
memcpy (E->Name, Name, Len+1);
|
|
||||||
|
|
||||||
/* Insert the entry into the list of all symbols */
|
/* Insert the entry into the list of all symbols */
|
||||||
if (Tab->Last == 0) {
|
if (Tab->Last == 0) {
|
||||||
@@ -114,8 +113,8 @@ ExtSym* NewExtSym (ExtSymTab* Tab, const char* Name)
|
|||||||
++Tab->Count;
|
++Tab->Count;
|
||||||
|
|
||||||
/* Insert the symbol into the hash table */
|
/* Insert the symbol into the hash table */
|
||||||
E->Next = Tab->HashTab [Hash];
|
E->Next = Tab->HashTab[Hash];
|
||||||
Tab->HashTab [Hash] = E;
|
Tab->HashTab[Hash] = E;
|
||||||
|
|
||||||
/* Done, return the created entry */
|
/* Done, return the created entry */
|
||||||
return E;
|
return E;
|
||||||
@@ -171,18 +170,18 @@ void FreeExtSymTab (ExtSymTab* Tab)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ExtSym* GetExtSym (const ExtSymTab* Tab, const char* Name)
|
ExtSym* GetExtSym (const ExtSymTab* Tab, unsigned Name)
|
||||||
/* Return the entry for the external symbol with the given name. Return NULL
|
/* Return the entry for the external symbol with the given name. Return NULL
|
||||||
* if there is no such symbol.
|
* if there is no such symbol.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Hash the name */
|
/* Hash the name */
|
||||||
unsigned Hash = HashStr (Name) % HASHTAB_SIZE;
|
unsigned Hash = (Name & HASHTAB_MASK);
|
||||||
|
|
||||||
/* Check the linked list */
|
/* Check the linked list */
|
||||||
ExtSym* E = Tab->HashTab [Hash];
|
ExtSym* E = Tab->HashTab[Hash];
|
||||||
while (E) {
|
while (E) {
|
||||||
if (strcmp (E->Name, Name) == 0) {
|
if (E->Name == Name) {
|
||||||
/* Found it */
|
/* Found it */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -221,8 +220,8 @@ unsigned ExtSymNum (const ExtSym* E)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char* ExtSymName (const ExtSym* E)
|
unsigned ExtSymName (const ExtSym* E)
|
||||||
/* Return the symbol name */
|
/* Return the symbol name index */
|
||||||
{
|
{
|
||||||
return E->Name;
|
return E->Name;
|
||||||
}
|
}
|
||||||
@@ -237,3 +236,4 @@ const ExtSym* ExtSymNext (const ExtSym* E)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ typedef struct ExtSymTab ExtSymTab;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ExtSym* NewExtSym (ExtSymTab* Tab, const char* Name);
|
ExtSym* NewExtSym (ExtSymTab* Tab, unsigned Name);
|
||||||
/* Create a new external symbol and insert it into the list */
|
/* Create a new external symbol and insert it into the list */
|
||||||
|
|
||||||
ExtSymTab* NewExtSymTab (void);
|
ExtSymTab* NewExtSymTab (void);
|
||||||
@@ -67,7 +67,7 @@ ExtSymTab* NewExtSymTab (void);
|
|||||||
void FreeExtSymTab (ExtSymTab* Tab);
|
void FreeExtSymTab (ExtSymTab* Tab);
|
||||||
/* Free an external symbol structure */
|
/* Free an external symbol structure */
|
||||||
|
|
||||||
ExtSym* GetExtSym (const ExtSymTab* Tab, const char* Name);
|
ExtSym* GetExtSym (const ExtSymTab* Tab, unsigned Name);
|
||||||
/* Return the entry for the external symbol with the given name. Return NULL
|
/* Return the entry for the external symbol with the given name. Return NULL
|
||||||
* if there is no such symbol.
|
* if there is no such symbol.
|
||||||
*/
|
*/
|
||||||
@@ -83,8 +83,8 @@ const ExtSym* ExtSymList (const ExtSymTab* Tab);
|
|||||||
unsigned ExtSymNum (const ExtSym* E);
|
unsigned ExtSymNum (const ExtSym* E);
|
||||||
/* Return the number of an external symbol */
|
/* Return the number of an external symbol */
|
||||||
|
|
||||||
const char* ExtSymName (const ExtSym* E);
|
unsigned ExtSymName (const ExtSym* E);
|
||||||
/* Return the symbol name */
|
/* Return the symbol name index */
|
||||||
|
|
||||||
const ExtSym* ExtSymNext (const ExtSym* E);
|
const ExtSym* ExtSymNext (const ExtSym* E);
|
||||||
/* Return the next symbol in the list */
|
/* Return the next symbol in the list */
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ FileInfo* ReadFileInfo (FILE* F, ObjData* O attribute ((unused)))
|
|||||||
FileInfo* FI = NewFileInfo ();
|
FileInfo* FI = NewFileInfo ();
|
||||||
|
|
||||||
/* Read the fields from the file */
|
/* Read the fields from the file */
|
||||||
|
FI->Name = ReadVar (F);
|
||||||
FI->MTime = Read32 (F);
|
FI->MTime = Read32 (F);
|
||||||
FI->Size = Read32 (F);
|
FI->Size = Read32 (F);
|
||||||
FI->Name = ReadStr (F);
|
|
||||||
|
|
||||||
/* Return the new struct */
|
/* Return the new struct */
|
||||||
return FI;
|
return FI;
|
||||||
|
|||||||
@@ -57,9 +57,9 @@
|
|||||||
|
|
||||||
typedef struct FileInfo FileInfo;
|
typedef struct FileInfo FileInfo;
|
||||||
struct FileInfo {
|
struct FileInfo {
|
||||||
|
unsigned Name; /* File name index */
|
||||||
unsigned long MTime; /* Time of last modification */
|
unsigned long MTime; /* Time of last modification */
|
||||||
unsigned long Size; /* Size of the file */
|
unsigned long Size; /* Size of the file */
|
||||||
char* Name; /* File name */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
/* (C) 1999-2003 Ullrich von Bassewitz */
|
||||||
/* R<>merstrasse 52 */
|
/* R<>merstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@@ -316,7 +316,7 @@ static void O65ParseExpr (ExprNode* Expr, ExprDesc* D, int Sign)
|
|||||||
CircularRefError (E);
|
CircularRefError (E);
|
||||||
} else if (E->Expr == 0) {
|
} else if (E->Expr == 0) {
|
||||||
/* Dummy export, must be an o65 imported symbol */
|
/* Dummy export, must be an o65 imported symbol */
|
||||||
ExtSym* S = O65GetImport (D->D, GetString (E->Name));
|
ExtSym* S = O65GetImport (D->D, E->Name);
|
||||||
CHECK (S != 0);
|
CHECK (S != 0);
|
||||||
if (D->ExtRef) {
|
if (D->ExtRef) {
|
||||||
/* We cannot have more than one external reference in o65 */
|
/* We cannot have more than one external reference in o65 */
|
||||||
@@ -820,7 +820,7 @@ static void O65WriteImports (O65Desc* D)
|
|||||||
S = ExtSymList (D->Imports);
|
S = ExtSymList (D->Imports);
|
||||||
while (S) {
|
while (S) {
|
||||||
/* Get the name */
|
/* Get the name */
|
||||||
const char* Name = ExtSymName (S);
|
const char* Name = GetString (ExtSymName (S));
|
||||||
/* And write it to the output file */
|
/* And write it to the output file */
|
||||||
WriteData (D->F, Name, strlen (Name) + 1);
|
WriteData (D->F, Name, strlen (Name) + 1);
|
||||||
/* Next symbol */
|
/* Next symbol */
|
||||||
@@ -863,13 +863,14 @@ static void O65WriteExports (O65Desc* D)
|
|||||||
ExprDesc ED;
|
ExprDesc ED;
|
||||||
|
|
||||||
/* Get the name */
|
/* Get the name */
|
||||||
const char* Name = ExtSymName (S);
|
unsigned NameIdx = ExtSymName (S);
|
||||||
|
const char* Name = GetString (NameIdx);
|
||||||
|
|
||||||
/* Get the export for this symbol. We've checked before that this
|
/* Get the export for this symbol. We've checked before that this
|
||||||
* export does really exist, so if it is unresolved, or if we don't
|
* export does really exist, so if it is unresolved, or if we don't
|
||||||
* find it, there is an error in the linker code.
|
* find it, there is an error in the linker code.
|
||||||
*/
|
*/
|
||||||
Export* E = FindExport (GetStringId (Name));
|
Export* E = FindExport (NameIdx);
|
||||||
if (E == 0 || IsUnresolvedExport (E)) {
|
if (E == 0 || IsUnresolvedExport (E)) {
|
||||||
Internal ("Unresolved export `%s' found in O65WriteExports", Name);
|
Internal ("Unresolved export `%s' found in O65WriteExports", Name);
|
||||||
}
|
}
|
||||||
@@ -1105,7 +1106,7 @@ void O65SetOS (O65Desc* D, unsigned OS, unsigned Version, unsigned Id)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ExtSym* O65GetImport (O65Desc* D, const char* Ident)
|
ExtSym* O65GetImport (O65Desc* D, unsigned Ident)
|
||||||
/* Return the imported symbol or NULL if not found */
|
/* Return the imported symbol or NULL if not found */
|
||||||
{
|
{
|
||||||
/* Retrieve the symbol from the table */
|
/* Retrieve the symbol from the table */
|
||||||
@@ -1114,7 +1115,7 @@ ExtSym* O65GetImport (O65Desc* D, const char* Ident)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void O65SetImport (O65Desc* D, const char* Ident)
|
void O65SetImport (O65Desc* D, unsigned Ident)
|
||||||
/* Set an imported identifier */
|
/* Set an imported identifier */
|
||||||
{
|
{
|
||||||
/* Insert the entry into the table */
|
/* Insert the entry into the table */
|
||||||
@@ -1123,7 +1124,7 @@ void O65SetImport (O65Desc* D, const char* Ident)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ExtSym* O65GetExport (O65Desc* D, const char* Ident)
|
ExtSym* O65GetExport (O65Desc* D, unsigned Ident)
|
||||||
/* Return the exported symbol or NULL if not found */
|
/* Return the exported symbol or NULL if not found */
|
||||||
{
|
{
|
||||||
/* Retrieve the symbol from the table */
|
/* Retrieve the symbol from the table */
|
||||||
@@ -1132,15 +1133,15 @@ ExtSym* O65GetExport (O65Desc* D, const char* Ident)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void O65SetExport (O65Desc* D, const char* Ident)
|
void O65SetExport (O65Desc* D, unsigned Ident)
|
||||||
/* Set an exported identifier */
|
/* Set an exported identifier */
|
||||||
{
|
{
|
||||||
/* Get the export for this symbol and check if it does exist and is
|
/* Get the export for this symbol and check if it does exist and is
|
||||||
* a resolved symbol.
|
* a resolved symbol.
|
||||||
*/
|
*/
|
||||||
Export* E = FindExport (GetStringId (Ident));
|
Export* E = FindExport (Ident);
|
||||||
if (E == 0 || IsUnresolvedExport (E)) {
|
if (E == 0 || IsUnresolvedExport (E)) {
|
||||||
Error ("Unresolved export: `%s'", Ident);
|
Error ("Unresolved export: `%s'", GetString (Ident));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert the entry into the table */
|
/* Insert the entry into the table */
|
||||||
@@ -1229,7 +1230,7 @@ static int O65Unresolved (unsigned Name, void* D)
|
|||||||
/* Called if an unresolved symbol is encountered */
|
/* Called if an unresolved symbol is encountered */
|
||||||
{
|
{
|
||||||
/* Check if the symbol is an imported o65 symbol */
|
/* Check if the symbol is an imported o65 symbol */
|
||||||
if (O65GetImport (D, GetString (Name)) != 0) {
|
if (O65GetImport (D, Name) != 0) {
|
||||||
/* This is an external symbol, relax... */
|
/* This is an external symbol, relax... */
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1999-2001 Ullrich von Bassewitz */
|
/* (C) 1999-2003 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* R<EFBFBD>merstrasse 52 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
@@ -101,16 +101,16 @@ void O65SetOption (O65Desc* D, unsigned Type, const void* Data, unsigned DataLen
|
|||||||
void O65SetOS (O65Desc* D, unsigned OS, unsigned Version, unsigned Id);
|
void O65SetOS (O65Desc* D, unsigned OS, unsigned Version, unsigned Id);
|
||||||
/* Set an option describing the target operating system */
|
/* Set an option describing the target operating system */
|
||||||
|
|
||||||
ExtSym* O65GetImport (O65Desc* D, const char* Ident);
|
ExtSym* O65GetImport (O65Desc* D, unsigned Ident);
|
||||||
/* Return the imported symbol or NULL if not found */
|
/* Return the imported symbol or NULL if not found */
|
||||||
|
|
||||||
void O65SetImport (O65Desc* D, const char* Ident);
|
void O65SetImport (O65Desc* D, unsigned Ident);
|
||||||
/* Set an imported identifier */
|
/* Set an imported identifier */
|
||||||
|
|
||||||
ExtSym* O65GetExport (O65Desc* D, const char* Ident);
|
ExtSym* O65GetExport (O65Desc* D, unsigned Ident);
|
||||||
/* Return the exported symbol or NULL if not found */
|
/* Return the exported symbol or NULL if not found */
|
||||||
|
|
||||||
void O65SetExport (O65Desc* D, const char* Ident);
|
void O65SetExport (O65Desc* D, unsigned Ident);
|
||||||
/* Set an exported identifier */
|
/* Set an exported identifier */
|
||||||
|
|
||||||
void O65WriteTarget (O65Desc* D, File* F);
|
void O65WriteTarget (O65Desc* D, File* F);
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ const char* GetSourceFileName (const ObjData* O, unsigned Index)
|
|||||||
PRECONDITION (Index < O->FileCount);
|
PRECONDITION (Index < O->FileCount);
|
||||||
|
|
||||||
/* Return the name */
|
/* Return the name */
|
||||||
return O->Files[Index]->Name;
|
return GetString (O->Files[Index]->Name);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user