Changed the object file and library format. There is now an additional

string table in the object file that (currently) holds all identifiers
from the import, export and debug info sections. The plan is to put all
strings into this table, so we have them in a central place and don't
waste memory. Apart from that, the indices are unique, so comparing strings
should be a lot easier than before (as soon as the programs take advantage
of this fact, which is currently not the case).


git-svn-id: svn://svn.cc65.org/cc65/trunk@2169 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-05-25 17:57:50 +00:00
parent 487ded2ce2
commit 76e67e2f97
41 changed files with 804 additions and 401 deletions

View File

@@ -66,7 +66,7 @@ extern const Collection EmptyCollection;
#define STATIC_COLLECTION_INITIALIZER { 0, 0, 0 }
/* Initializer for auto collections */
#define AUTO_COLLECTION_INITIALIZER EmptyCollection;
#define AUTO_COLLECTION_INITIALIZER EmptyCollection
@@ -285,4 +285,4 @@ void CollSort (Collection* C,

View File

@@ -1,15 +1,15 @@
/*****************************************************************************/
/* */
/* libdefs.h */
/* libdefs.h */
/* */
/* Library file definitions */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -46,7 +46,7 @@
/* Defines for magic and version */
#define LIB_MAGIC 0x7A55616E
#define LIB_VERSION 0x0009
#define LIB_VERSION 0x000A
/* Size of an library file header */
#define LIB_HDR_SIZE 12
@@ -54,8 +54,8 @@
/* Header structure for the library */
typedef struct LibHeader_ LibHeader;
struct LibHeader_ {
typedef struct LibHeader LibHeader;
struct LibHeader {
unsigned long Magic; /* 32: Magic number */
unsigned Version; /* 16: Version number */
unsigned Flags; /* 16: flags */

View File

@@ -26,6 +26,7 @@ OBJS = abend.o \
segdefs.o \
segnames.o \
strbuf.o \
strpool.o \
strutil.o \
target.o \
tgttrans.o \

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -46,10 +46,10 @@
/* Defines for magic and version */
#define OBJ_MAGIC 0x616E7A55
#define OBJ_VERSION 0x0009
#define OBJ_VERSION 0x000A
/* Size of an object file header */
#define OBJ_HDR_SIZE 64
#define OBJ_HDR_SIZE 72
/* Flag bits */
#define OBJ_FLAGS_DBGINFO 0x0001 /* File has debug info */
@@ -57,8 +57,8 @@
/* Header structure */
typedef struct ObjHeader_ ObjHeader;
struct ObjHeader_ {
typedef struct ObjHeader ObjHeader;
struct ObjHeader {
unsigned long Magic; /* 32: Magic number */
unsigned Version; /* 16: Version number */
unsigned Flags; /* 16: flags */
@@ -76,6 +76,8 @@ struct ObjHeader_ {
unsigned long DbgSymSize; /* 32: Size of debug symbols */
unsigned long LineInfoOffs; /* 32: Offset to list of line infos */
unsigned long LineInfoSize; /* 32: Size of line infos */
unsigned long StrPoolOffs; /* 32: Offset to string pool */
unsigned long StrPoolSize; /* 32: Size of string pool */
};

View File

@@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2002 Ullrich von Bassewitz */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@@ -45,30 +45,37 @@
/* Available segment types */
#define SEGTYPE_DEFAULT 0
#define SEGTYPE_ABS 1
#define SEGTYPE_ZP 2
#define SEGTYPE_FAR 3
#define SEGTYPE_DEFAULT 0
#define SEGTYPE_ABS 1
#define SEGTYPE_ZP 2
#define SEGTYPE_FAR 3
/* Fragment types in the object file */
#define FRAG_TYPEMASK 0x38 /* Mask the type of the fragment */
#define FRAG_BYTEMASK 0x07 /* Mask for byte count */
#define FRAG_TYPEMASK 0x38 /* Mask the type of the fragment */
#define FRAG_BYTEMASK 0x07 /* Mask for byte count */
#define FRAG_CHECKMASK 0xC0 /* Mask for check type */
#define FRAG_LITERAL 0x00 /* Literal data */
/* Fragment types */
#define FRAG_LITERAL 0x00 /* Literal data */
#define FRAG_EXPR 0x08 /* Expression */
#define FRAG_EXPR8 0x09 /* 8 bit expression */
#define FRAG_EXPR16 0x0A /* 16 bit expression */
#define FRAG_EXPR24 0x0B /* 24 bit expression */
#define FRAG_EXPR32 0x0C /* 32 bit expression */
#define FRAG_EXPR 0x08 /* Expression */
#define FRAG_EXPR8 0x09 /* 8 bit expression */
#define FRAG_EXPR16 0x0A /* 16 bit expression */
#define FRAG_EXPR24 0x0B /* 24 bit expression */
#define FRAG_EXPR32 0x0C /* 32 bit expression */
#define FRAG_SEXPR 0x10 /* Signed expression */
#define FRAG_SEXPR8 0x11 /* 8 bit signed expression */
#define FRAG_SEXPR16 0x12 /* 16 bit signed expression */
#define FRAG_SEXPR24 0x13 /* 24 bit signed expression */
#define FRAG_SEXPR32 0x14 /* 32 bit signed expression */
#define FRAG_SEXPR 0x10 /* Signed expression */
#define FRAG_SEXPR8 0x11 /* 8 bit signed expression */
#define FRAG_SEXPR16 0x12 /* 16 bit signed expression */
#define FRAG_SEXPR24 0x13 /* 24 bit signed expression */
#define FRAG_SEXPR32 0x14 /* 32 bit signed expression */
#define FRAG_FILL 0x20 /* Fill bytes */
#define FRAG_FILL 0x20 /* Fill bytes */
/* Fragment checks */
#define FRAG_CHECK_NONE 0x00 /* No checks applied */
#define FRAG_CHECK_WARN 0x40 /* Check and warn */
#define FRAG_CHECK_ERROR 0x80 /* Check and abort */

View File

@@ -60,8 +60,8 @@
/* A string pool entry */
struct StrPoolEntry {
StrPoolEntry* Next; /* Pointer to next entry in hash chain */
struct StringPoolEntry {
StringPoolEntry* Next; /* Pointer to next entry in hash chain */
unsigned Hash; /* Full hash value */
unsigned Id; /* The numeric string id */
unsigned Len; /* Length of the string (excluding terminator) */
@@ -71,19 +71,19 @@ struct StrPoolEntry {
/*****************************************************************************/
/* struct StrPoolEntry */
/* struct StringPoolEntry */
/*****************************************************************************/
static StrPoolEntry* NewStrPoolEntry (const char* S, unsigned Hash, unsigned Id)
static StringPoolEntry* NewStringPoolEntry (const char* S, unsigned Hash, unsigned Id)
/* Create a new string pool entry and return it. */
{
/* Get the length of the string */
unsigned Len = strlen (S);
/* Allocate memory */
StrPoolEntry* E = xmalloc (sizeof (StrPoolEntry) + Len);
StringPoolEntry* E = xmalloc (sizeof (StringPoolEntry) + Len);
/* Initialize the fields */
E->Next = 0;
@@ -104,7 +104,7 @@ static StrPoolEntry* NewStrPoolEntry (const char* S, unsigned Hash, unsigned Id)
StrPool* InitStrPool (StrPool* P)
StringPool* InitStringPool (StringPool* P)
/* Initialize a string pool */
{
unsigned I;
@@ -122,7 +122,7 @@ StrPool* InitStrPool (StrPool* P)
void DoneStrPool (StrPool* P)
void DoneStringPool (StringPool* P)
/* Free the data of a string pool (but not the data itself) */
{
unsigned I;
@@ -144,20 +144,20 @@ void DoneStrPool (StrPool* P)
StrPool* NewStrPool (void)
StringPool* NewStringPool (void)
/* Allocate, initialize and return a new string pool */
{
/* Allocate memory, initialize and return it */
return InitStrPool (xmalloc (sizeof (StrPool)));
return InitStringPool (xmalloc (sizeof (StringPool)));
}
void FreeStrPool (StrPool* P)
void FreeStringPool (StringPool* P)
/* Free a string pool */
{
/* Free all entries */
DoneStrPool (P);
DoneStringPool (P);
/* Free the string pool itself */
xfree (P);
@@ -165,11 +165,11 @@ void FreeStrPool (StrPool* P)
const char* SP_Get (const StrPool* P, unsigned Index)
const char* SP_Get (const StringPool* P, unsigned Index)
/* Return a string from the pool. Index must exist, otherwise FAIL is called. */
{
/* Get the collection entry */
const StrPoolEntry* E = CollConstAt (&P->Entries, Index);
const StringPoolEntry* E = CollConstAt (&P->Entries, Index);
/* Return the string from the entry */
return E->S;
@@ -177,7 +177,7 @@ const char* SP_Get (const StrPool* P, unsigned Index)
unsigned SP_Add (StrPool* P, const char* S)
unsigned SP_Add (StringPool* P, const char* S)
/* Add a string to the buffer and return the index. If the string does already
* exist in the pool, SP_Add will just return the index of the existing string.
*/
@@ -189,7 +189,7 @@ unsigned SP_Add (StrPool* P, const char* S)
unsigned RHash = Hash % (sizeof (P->Tab)/sizeof (P->Tab[0]));
/* Search for an existing entry */
StrPoolEntry* E = P->Tab[RHash];
StringPoolEntry* E = P->Tab[RHash];
while (E) {
if (E->Hash == Hash && strcmp (E->S, S) == 0) {
/* Found, return the id of the existing string */
@@ -199,7 +199,7 @@ unsigned SP_Add (StrPool* P, const char* S)
}
/* We didn't find the entry, so create a new one */
E = NewStrPoolEntry (S, Hash, CollCount (&P->Entries));
E = NewStringPoolEntry (S, Hash, CollCount (&P->Entries));
/* Insert the new entry into the entry collection */
CollAppend (&P->Entries, E);
@@ -217,50 +217,3 @@ unsigned SP_Add (StrPool* P, const char* S)
unsigned SP_AddBuf (StrPool* P, const void* Buffer, unsigned Size)
/* Add strings from a string buffer. Buffer must contain a list of zero
* terminated strings. These strings are added to the pool, starting with
* the current index. The number of strings added is returned.
* Beware: The function will do only loose range checking for the buffer
* limits, so a SEGV may occur if the last string in the buffer is not
* correctly terminated.
*/
{
/* Cast the buffer pointer to something useful */
const char* Buf = Buffer;
/* Remember the current number of strings in the buffer. */
unsigned OldCount = SB_GetCount (P);
/* Add all strings from the buffer */
while (Size) {
/* Add the next entry */
unsigned Id = SP_Add (P, Buf);
/* Get the entry from the id */
const StrPoolEntry* E = CollConstAt (&P->Entries, Id);
/* Skip this string */
Buf += E->Len + 1;
Size -= E->Len + 1;
}
/* Return the number of strings added */
return SB_GetCount (P) - OldCount;
}
void SP_Build (StrPool* P, const void* Buffer, unsigned Size)
/* Delete existing data and use the data from Buffer instead. */
{
/* Delete old data */
DoneStrPool (P);
/* Add the buffer data */
SP_AddBuf (P, Buffer, Size);
}

View File

@@ -60,16 +60,26 @@
/* Opaque entry */
typedef struct StrPoolEntry StrPoolEntry;
/* Opaque string pool entry */
typedef struct StringPoolEntry StringPoolEntry;
typedef struct StrPool StrPool;
struct StrPool {
StrPoolEntry* Tab[211]; /* Entry hash table */
Collection Entries; /* Entries sorted by number */
unsigned TotalSize; /* Total size of all string data */
/* A string pool */
typedef struct StringPool StringPool;
struct StringPool {
Collection Entries; /* Entries sorted by number */
unsigned TotalSize; /* Total size of all string data */
StringPoolEntry* Tab[211]; /* Entry hash table */
};
/* A string pool initializer. We do only initialize the first field, all
* others will get zeroed out by the compiler.
*/
#define STATIC_STRINGPOOL_INITIALIZER { \
STATIC_COLLECTION_INITIALIZER, \
0, \
{ 0 } \
}
/*****************************************************************************/
@@ -78,39 +88,34 @@ struct StrPool {
StrPool* InitStrPool (StrPool* P);
StringPool* InitStringPool (StringPool* P);
/* Initialize a string pool */
void DoneStrPool (StrPool* P);
void DoneStringPool (StringPool* P);
/* Free the data of a string pool (but not the data itself) */
StrPool* NewStrPool (void);
StringPool* NewStringPool (void);
/* Allocate, initialize and return a new string pool */
void FreeStrPool (StrPool* P);
void FreeStringPool (StringPool* P);
/* Free a string pool */
void SP_Use (char* Buffer, unsigned Size);
/* Delete existing data and use the data from Buffer instead. Buffer must be
* allocated on the heap and will be freed using xfree() if necessary.
*/
const char* SP_Get (const StrPool* P, unsigned Index);
const char* SP_Get (const StringPool* P, unsigned Index);
/* Return a string from the pool. Index must exist, otherwise FAIL is called. */
unsigned SP_Add (StrPool* P, const char* S);
unsigned SP_Add (StringPool* P, const char* S);
/* Add a string to the buffer and return the index. If the string does already
* exist in the pool, SP_Add will just return the index of the existing string.
*/
#if defined(HAVE_INLINE)
INLINE unsigned SB_GetCount (const StrPool* P)
INLINE unsigned SP_GetCount (const StringPool* P)
/* Return the number of strings in the pool */
{
return CollCount (&P->Entries);
}
#else
# define SB_GetCount(P) CollCount (&(P)->Entries)
# define SP_GetCount(P) CollCount (&(P)->Entries)
#endif