mirror of
https://github.com/cc65/cc65.git
synced 2025-02-10 09:31:08 +00:00
Move SymEntry stuff into its own module
git-svn-id: svn://svn.cc65.org/cc65/trunk@2563 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
2c7218b5d9
commit
48c122e478
@ -37,6 +37,7 @@ OBJS = asserts.o \
|
|||||||
scanner.o \
|
scanner.o \
|
||||||
segment.o \
|
segment.o \
|
||||||
spool.o \
|
spool.o \
|
||||||
|
symentry.o \
|
||||||
symtab.o \
|
symtab.o \
|
||||||
toklist.o \
|
toklist.o \
|
||||||
ulabel.o
|
ulabel.o
|
||||||
|
@ -70,6 +70,7 @@ OBJS = asserts.obj \
|
|||||||
scanner.obj \
|
scanner.obj \
|
||||||
segment.obj \
|
segment.obj \
|
||||||
spool.obj \
|
spool.obj \
|
||||||
|
symentry.obj \
|
||||||
symtab.obj \
|
symtab.obj \
|
||||||
toklist.obj \
|
toklist.obj \
|
||||||
ulabel.obj
|
ulabel.obj
|
||||||
|
95
src/ca65/symentry.c
Normal file
95
src/ca65/symentry.c
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* symentry.c */
|
||||||
|
/* */
|
||||||
|
/* Symbol table entry forward for the ca65 macroassembler */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (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 */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "xmalloc.h"
|
||||||
|
|
||||||
|
/* ca65 */
|
||||||
|
#include "scanner.h"
|
||||||
|
#include "symentry.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SymEntry* SymList = 0; /* List of all symbol table entries */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SymEntry* NewSymEntry (const char* Name)
|
||||||
|
/* Allocate a symbol table entry, initialize and return it */
|
||||||
|
{
|
||||||
|
SymEntry* S;
|
||||||
|
unsigned Len;
|
||||||
|
|
||||||
|
/* Get the length of the name */
|
||||||
|
Len = strlen (Name);
|
||||||
|
|
||||||
|
/* Allocate memory */
|
||||||
|
S = xmalloc (sizeof (SymEntry) + Len);
|
||||||
|
|
||||||
|
/* Initialize the entry */
|
||||||
|
S->Left = 0;
|
||||||
|
S->Right = 0;
|
||||||
|
S->Locals = 0;
|
||||||
|
S->SymTab = 0;
|
||||||
|
S->Pos = CurPos;
|
||||||
|
S->Flags = 0;
|
||||||
|
S->V.Expr = 0;
|
||||||
|
memset (S->ConDesPrio, 0, sizeof (S->ConDesPrio));
|
||||||
|
memcpy (S->Name, Name, Len+1);
|
||||||
|
|
||||||
|
/* Insert it into the list of all entries */
|
||||||
|
S->List = SymList;
|
||||||
|
SymList = S;
|
||||||
|
|
||||||
|
/* Return the initialized entry */
|
||||||
|
return S;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998 Ullrich von Bassewitz */
|
/* (C) 1998-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 */
|
||||||
@ -38,14 +38,70 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "cddefs.h"
|
||||||
|
#include "filepos.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Data */
|
/* Data */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Forward declaration for struct SymEntry */
|
/* Bits for the Flags value in SymEntry */
|
||||||
|
#define SF_NONE 0x0000 /* Empty flag set */
|
||||||
|
#define SF_USER 0x0001 /* User bit */
|
||||||
|
#define SF_TRAMPOLINE 0x0002 /* Trampoline entry */
|
||||||
|
#define SF_EXPORT 0x0004 /* Export this symbol */
|
||||||
|
#define SF_IMPORT 0x0008 /* Import this symbol */
|
||||||
|
#define SF_GLOBAL 0x0010 /* Global symbol */
|
||||||
|
#define SF_ZP 0x0020 /* Declared as zeropage symbol */
|
||||||
|
#define SF_ABS 0x0040 /* Declared as absolute symbol */
|
||||||
|
#define SF_LABEL 0x0080 /* Used as a label */
|
||||||
|
#define SF_FORCED 0x0100 /* Forced import, SF_IMPORT also set */
|
||||||
|
#define SF_FINALIZED 0x0200 /* Symbol is finalized */
|
||||||
|
#define SF_INDEXED 0x0800 /* Index is valid */
|
||||||
|
#define SF_CONST 0x1000 /* The symbol has a constant value */
|
||||||
|
#define SF_MULTDEF 0x2000 /* Multiply defined symbol */
|
||||||
|
#define SF_DEFINED 0x4000 /* Defined */
|
||||||
|
#define SF_REFERENCED 0x8000 /* Referenced */
|
||||||
|
|
||||||
|
/* Structure of a symbol table entry */
|
||||||
typedef struct SymEntry SymEntry;
|
typedef struct SymEntry SymEntry;
|
||||||
|
struct SymEntry {
|
||||||
|
SymEntry* Left; /* Lexically smaller entry */
|
||||||
|
SymEntry* Right; /* Lexically larger entry */
|
||||||
|
SymEntry* List; /* List of all entries */
|
||||||
|
SymEntry* Locals; /* Root of subtree for local symbols */
|
||||||
|
struct SymTable* SymTab; /* Table this symbol is in, 0 for locals */
|
||||||
|
FilePos Pos; /* File position for this symbol */
|
||||||
|
unsigned Flags; /* Symbol flags */
|
||||||
|
unsigned Index; /* Index of import/export entries */
|
||||||
|
union {
|
||||||
|
struct ExprNode* Expr; /* Expression if CONST not set */
|
||||||
|
long Val; /* Value (if CONST set) */
|
||||||
|
SymEntry* Sym; /* Symbol (if trampoline entry) */
|
||||||
|
} V;
|
||||||
|
unsigned char ConDesPrio[CD_TYPE_COUNT]; /* ConDes priorities... */
|
||||||
|
/* ...actually value+1 (used as flag) */
|
||||||
|
char Name [1]; /* Dynamic allocation */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* List of all symbol table entries */
|
||||||
|
extern SymEntry* SymList;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SymEntry* NewSymEntry (const char* Name);
|
||||||
|
/* Allocate a symbol table entry, initialize and return it */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "cddefs.h"
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "hashstr.h"
|
#include "hashstr.h"
|
||||||
#include "symdefs.h"
|
#include "symdefs.h"
|
||||||
@ -59,25 +58,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Bits for the Flags value in SymEntry */
|
/* Combined symbol entry flags used within this module */
|
||||||
#define SF_NONE 0x0000 /* Empty flag set */
|
|
||||||
#define SF_USER 0x0001 /* User bit */
|
|
||||||
#define SF_TRAMPOLINE 0x0002 /* Trampoline entry */
|
|
||||||
#define SF_EXPORT 0x0004 /* Export this symbol */
|
|
||||||
#define SF_IMPORT 0x0008 /* Import this symbol */
|
|
||||||
#define SF_GLOBAL 0x0010 /* Global symbol */
|
|
||||||
#define SF_ZP 0x0020 /* Declared as zeropage symbol */
|
|
||||||
#define SF_ABS 0x0040 /* Declared as absolute symbol */
|
|
||||||
#define SF_LABEL 0x0080 /* Used as a label */
|
|
||||||
#define SF_FORCED 0x0100 /* Forced import, SF_IMPORT also set */
|
|
||||||
#define SF_FINALIZED 0x0200 /* Symbol is finalized */
|
|
||||||
#define SF_INDEXED 0x0800 /* Index is valid */
|
|
||||||
#define SF_CONST 0x1000 /* The symbol has a constant value */
|
|
||||||
#define SF_MULTDEF 0x2000 /* Multiply defined symbol */
|
|
||||||
#define SF_DEFINED 0x4000 /* Defined */
|
|
||||||
#define SF_REFERENCED 0x8000 /* Referenced */
|
|
||||||
|
|
||||||
/* Combined stuff */
|
|
||||||
#define SF_UNDEFMASK (SF_REFERENCED | SF_DEFINED | SF_IMPORT)
|
#define SF_UNDEFMASK (SF_REFERENCED | SF_DEFINED | SF_IMPORT)
|
||||||
#define SF_UNDEFVAL (SF_REFERENCED)
|
#define SF_UNDEFVAL (SF_REFERENCED)
|
||||||
#define SF_EXPMASK (SF_TRAMPOLINE | SF_EXPORT)
|
#define SF_EXPMASK (SF_TRAMPOLINE | SF_EXPORT)
|
||||||
@ -85,28 +66,6 @@
|
|||||||
#define SF_DBGINFOMASK (SF_TRAMPOLINE | SF_DEFINED | SF_EXPORT | SF_IMPORT)
|
#define SF_DBGINFOMASK (SF_TRAMPOLINE | SF_DEFINED | SF_EXPORT | SF_IMPORT)
|
||||||
#define SF_DBGINFOVAL (SF_DEFINED)
|
#define SF_DBGINFOVAL (SF_DEFINED)
|
||||||
|
|
||||||
/* Structure of a symbol table entry */
|
|
||||||
struct SymEntry {
|
|
||||||
SymEntry* Left; /* Lexically smaller entry */
|
|
||||||
SymEntry* Right; /* Lexically larger entry */
|
|
||||||
SymEntry* List; /* List of all entries */
|
|
||||||
SymEntry* Locals; /* Root of subtree for local symbols */
|
|
||||||
struct SymTable* SymTab; /* Table this symbol is in, 0 for locals */
|
|
||||||
FilePos Pos; /* File position for this symbol */
|
|
||||||
unsigned Flags; /* Symbol flags */
|
|
||||||
unsigned Index; /* Index of import/export entries */
|
|
||||||
union {
|
|
||||||
struct ExprNode* Expr; /* Expression if CONST not set */
|
|
||||||
long Val; /* Value (if CONST set) */
|
|
||||||
SymEntry* Sym; /* Symbol (if trampoline entry) */
|
|
||||||
} V;
|
|
||||||
unsigned char ConDesPrio[CD_TYPE_COUNT]; /* ConDes priorities... */
|
|
||||||
/* ...actually value+1 (used as flag) */
|
|
||||||
char Name [1]; /* Dynamic allocation */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Definitions for the hash table */
|
/* Definitions for the hash table */
|
||||||
#define MAIN_HASHTAB_SIZE 213
|
#define MAIN_HASHTAB_SIZE 213
|
||||||
#define SUB_HASHTAB_SIZE 53
|
#define SUB_HASHTAB_SIZE 53
|
||||||
@ -118,16 +77,11 @@ struct SymTable {
|
|||||||
SymEntry* Table [1]; /* Dynamic allocation */
|
SymEntry* Table [1]; /* Dynamic allocation */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Arguments for SymFind */
|
/* Arguments for SymFind */
|
||||||
#define SF_FIND_EXISTING 0
|
#define SF_FIND_EXISTING 0
|
||||||
#define SF_ALLOC_NEW 1
|
#define SF_ALLOC_NEW 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Symbol table variables */
|
/* Symbol table variables */
|
||||||
static SymEntry* SymList = 0; /* List of all symbol table entries */
|
|
||||||
static SymEntry* SymLast = 0; /* Pointer to last defined symbol */
|
static SymEntry* SymLast = 0; /* Pointer to last defined symbol */
|
||||||
static SymTable* SymTab = 0; /* Pointer to current symbol table */
|
static SymTable* SymTab = 0; /* Pointer to current symbol table */
|
||||||
static SymTable* RootTab = 0; /* Root symbol table */
|
static SymTable* RootTab = 0; /* Root symbol table */
|
||||||
@ -150,39 +104,6 @@ static int IsLocal (const char* Name)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static SymEntry* NewSymEntry (const char* Name)
|
|
||||||
/* Allocate a symbol table entry, initialize and return it */
|
|
||||||
{
|
|
||||||
SymEntry* S;
|
|
||||||
unsigned Len;
|
|
||||||
|
|
||||||
/* Get the length of the name */
|
|
||||||
Len = strlen (Name);
|
|
||||||
|
|
||||||
/* Allocate memory */
|
|
||||||
S = xmalloc (sizeof (SymEntry) + Len);
|
|
||||||
|
|
||||||
/* Initialize the entry */
|
|
||||||
S->Left = 0;
|
|
||||||
S->Right = 0;
|
|
||||||
S->Locals = 0;
|
|
||||||
S->SymTab = 0;
|
|
||||||
S->Pos = CurPos;
|
|
||||||
S->Flags = 0;
|
|
||||||
S->V.Expr = 0;
|
|
||||||
memset (S->ConDesPrio, 0, sizeof (S->ConDesPrio));
|
|
||||||
memcpy (S->Name, Name, Len+1);
|
|
||||||
|
|
||||||
/* Insert it into the list of all entries */
|
|
||||||
S->List = SymList;
|
|
||||||
SymList = S;
|
|
||||||
|
|
||||||
/* Return the initialized entry */
|
|
||||||
return S;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static SymTable* NewSymTable (unsigned Size)
|
static SymTable* NewSymTable (unsigned Size)
|
||||||
/* Allocate a symbol table on the heap and return it */
|
/* Allocate a symbol table on the heap and return it */
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user