2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* */
|
|
|
|
|
/* symentry.h */
|
|
|
|
|
/* */
|
|
|
|
|
/* Symbol table entry forward for the ca65 macroassembler */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
2003-10-22 21:24:37 +00:00
|
|
|
|
/* (C) 1998-2003 Ullrich von Bassewitz */
|
2003-11-11 13:57:30 +00:00
|
|
|
|
/* R<>merstra<72>e 52 */
|
2003-10-22 21:24:37 +00:00
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* 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. */
|
|
|
|
|
/* */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SYMENTRY_H
|
|
|
|
|
#define SYMENTRY_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-10-22 21:24:37 +00:00
|
|
|
|
/* common */
|
|
|
|
|
#include "cddefs.h"
|
2003-10-31 20:21:48 +00:00
|
|
|
|
#include "coll.h"
|
2003-10-22 21:24:37 +00:00
|
|
|
|
#include "filepos.h"
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#include "inline.h"
|
|
|
|
|
|
|
|
|
|
/* ca65 */
|
|
|
|
|
#include "spool.h"
|
2003-10-22 21:24:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Data */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-10-22 21:24:37 +00:00
|
|
|
|
/* Bits for the Flags value in SymEntry */
|
|
|
|
|
#define SF_NONE 0x0000 /* Empty flag set */
|
2003-10-31 20:21:48 +00:00
|
|
|
|
#define SF_USER 0x0001 /* User bit */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#define SF_UNUSED 0x0002 /* Unused entry */
|
2003-10-31 20:21:48 +00:00
|
|
|
|
#define SF_EXPORT 0x0004 /* Export this symbol */
|
|
|
|
|
#define SF_IMPORT 0x0008 /* Import this symbol */
|
|
|
|
|
#define SF_GLOBAL 0x0010 /* Global symbol */
|
2003-12-03 09:18:31 +00:00
|
|
|
|
#define SF_LOCAL 0x0020 /* Cheap local symbol */
|
2003-10-22 21:24:37 +00:00
|
|
|
|
#define SF_LABEL 0x0080 /* Used as a label */
|
|
|
|
|
#define SF_FORCED 0x0100 /* Forced import, SF_IMPORT also set */
|
|
|
|
|
#define SF_INDEXED 0x0800 /* Index is valid */
|
|
|
|
|
#define SF_MULTDEF 0x2000 /* Multiply defined symbol */
|
|
|
|
|
#define SF_DEFINED 0x4000 /* Defined */
|
|
|
|
|
#define SF_REFERENCED 0x8000 /* Referenced */
|
|
|
|
|
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Arguments for SymFind... */
|
|
|
|
|
#define SYM_FIND_EXISTING 0
|
|
|
|
|
#define SYM_ALLOC_NEW 1
|
|
|
|
|
|
2003-10-22 21:24:37 +00:00
|
|
|
|
/* Structure of a symbol table entry */
|
2000-11-02 22:11:48 +00:00
|
|
|
|
typedef struct SymEntry SymEntry;
|
2003-10-22 21:24:37 +00:00
|
|
|
|
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 {
|
2003-12-03 09:18:31 +00:00
|
|
|
|
struct ExprNode* Expr; /* Symbol expression */
|
2003-10-22 21:24:37 +00:00
|
|
|
|
SymEntry* Sym; /* Symbol (if trampoline entry) */
|
|
|
|
|
} V;
|
2003-10-31 20:21:48 +00:00
|
|
|
|
Collection ExprRefs; /* Expressions using this symbol */
|
2003-11-07 19:28:37 +00:00
|
|
|
|
unsigned char ExportSize; /* Export address size */
|
|
|
|
|
unsigned char AddrSize; /* Address size of label */
|
2003-12-03 09:18:31 +00:00
|
|
|
|
unsigned char ConDesPrio[CD_TYPE_COUNT]; /* ConDes priorities... */
|
2003-10-22 21:24:37 +00:00
|
|
|
|
/* ...actually value+1 (used as flag) */
|
2003-10-31 20:21:48 +00:00
|
|
|
|
unsigned Name; /* Name index in global string pool */
|
2003-10-22 21:24:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* List of all symbol table entries */
|
|
|
|
|
extern SymEntry* SymList;
|
|
|
|
|
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Pointer to last defined symbol */
|
|
|
|
|
extern SymEntry* SymLast;
|
|
|
|
|
|
2003-10-22 21:24:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Code */
|
2003-10-22 21:24:37 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-03 09:18:31 +00:00
|
|
|
|
SymEntry* NewSymEntry (const char* Name, unsigned Flags);
|
2003-10-22 21:24:37 +00:00
|
|
|
|
/* Allocate a symbol table entry, initialize and return it */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-11-13 22:03:24 +00:00
|
|
|
|
int SymSearchTree (SymEntry* T, const char* Name, SymEntry** E);
|
|
|
|
|
/* Search in the given tree for a name. If we find the symbol, the function
|
|
|
|
|
* will return 0 and put the entry pointer into E. If we did not find the
|
|
|
|
|
* symbol, and the tree is empty, E is set to NULL. If the tree is not empty,
|
|
|
|
|
* E will be set to the last entry, and the result of the function is <0 if
|
|
|
|
|
* the entry should be inserted on the left side, and >0 if it should get
|
|
|
|
|
* inserted on the right side.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-10-31 20:21:48 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
INLINE void SymAddExprRef (SymEntry* Sym, struct ExprNode* Expr)
|
|
|
|
|
/* Add an expression reference to this symbol */
|
2003-10-31 20:21:48 +00:00
|
|
|
|
{
|
|
|
|
|
CollAppend (&Sym->ExprRefs, Expr);
|
|
|
|
|
}
|
|
|
|
|
#else
|
2003-11-06 11:22:31 +00:00
|
|
|
|
#define SymAddExprRef(Sym,Expr) CollAppend (&(Sym)->ExprRefs, Expr)
|
2003-10-31 20:21:48 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(HAVE_INLINE)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
INLINE void SymDelExprRef (SymEntry* Sym, struct ExprNode* Expr)
|
|
|
|
|
/* Delete an expression reference to this symbol */
|
2003-10-31 20:21:48 +00:00
|
|
|
|
{
|
|
|
|
|
CollDeleteItem (&Sym->ExprRefs, Expr);
|
|
|
|
|
}
|
|
|
|
|
#else
|
2003-11-06 11:22:31 +00:00
|
|
|
|
#define SymDelExprRef(Sym,Expr) CollDeleteItem (&(Sym)->ExprRefs, Expr)
|
2003-10-31 20:21:48 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
void SymTransferExprRefs (SymEntry* From, SymEntry* To);
|
|
|
|
|
/* Transfer all expression references from one symbol to another. */
|
|
|
|
|
|
2003-11-13 00:21:31 +00:00
|
|
|
|
void SymDef (SymEntry* Sym, ExprNode* Expr, unsigned char AddrSize, unsigned Flags);
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Mark a symbol as defined */
|
|
|
|
|
|
|
|
|
|
void SymRef (SymEntry* Sym);
|
|
|
|
|
/* Mark the given symbol as referenced */
|
|
|
|
|
|
2003-11-13 00:21:31 +00:00
|
|
|
|
void SymImport (SymEntry* Sym, unsigned char AddrSize, unsigned Flags);
|
2003-11-07 19:28:37 +00:00
|
|
|
|
/* Mark the given symbol as an imported symbol */
|
|
|
|
|
|
2003-11-13 00:21:31 +00:00
|
|
|
|
void SymExport (SymEntry* Sym, unsigned char AddrSize, unsigned Flags);
|
2003-11-07 19:28:37 +00:00
|
|
|
|
/* Mark the given symbol as an exported symbol */
|
|
|
|
|
|
2003-11-13 00:21:31 +00:00
|
|
|
|
void SymGlobal (SymEntry* Sym, unsigned char AddrSize, unsigned Flags);
|
2003-11-07 19:28:37 +00:00
|
|
|
|
/* Mark the given symbol as a global symbol, that is, as a symbol that is
|
|
|
|
|
* either imported or exported.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-11-13 00:21:31 +00:00
|
|
|
|
void SymConDes (SymEntry* Sym, unsigned char AddrSize, unsigned Type, unsigned Prio);
|
|
|
|
|
/* Mark the given symbol as a module constructor/destructor. This will also
|
|
|
|
|
* mark the symbol as an export. Initializers may never be zero page symbols.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE int SymIsDef (const SymEntry* S)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Return true if the given symbol is already defined */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
{
|
|
|
|
|
return (S->Flags & SF_DEFINED) != 0;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define SymIsDef(S) (((S)->Flags & SF_DEFINED) != 0)
|
|
|
|
|
#endif
|
2003-11-06 11:22:31 +00:00
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE int SymIsRef (const SymEntry* S)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Return true if the given symbol has been referenced */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
{
|
|
|
|
|
return (S->Flags & SF_REFERENCED) != 0;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define SymIsRef(S) (((S)->Flags & SF_REFERENCED) != 0)
|
|
|
|
|
#endif
|
2003-11-06 11:22:31 +00:00
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE int SymIsImport (const SymEntry* S)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Return true if the given symbol is marked as import */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
{
|
|
|
|
|
/* Check the import flag */
|
|
|
|
|
return (S->Flags & SF_IMPORT) != 0;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define SymIsImport(S) (((S)->Flags & SF_IMPORT) != 0)
|
|
|
|
|
#endif
|
2003-11-06 11:22:31 +00:00
|
|
|
|
|
2003-11-11 13:57:30 +00:00
|
|
|
|
int SymIsConst (SymEntry* Sym, long* Val);
|
|
|
|
|
/* Return true if the given symbol has a constant value. If Val is not NULL
|
|
|
|
|
* and the symbol has a constant value, store it's value there.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE int SymHasExpr (const SymEntry* S)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Return true if the given symbol has an associated expression */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
{
|
|
|
|
|
/* Check the expression */
|
|
|
|
|
return ((S->Flags & (SF_DEFINED|SF_IMPORT)) == SF_DEFINED);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define SymHasExpr(S) (((S)->Flags & (SF_DEFINED|SF_IMPORT)) != SF_DEFINED)
|
|
|
|
|
#endif
|
2003-11-06 11:22:31 +00:00
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE void SymMarkUser (SymEntry* S)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Set a user mark on the specified symbol */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
{
|
|
|
|
|
/* Set the bit */
|
|
|
|
|
S->Flags |= SF_USER;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define SymMarkUser(S) ((S)->Flags |= SF_USER)
|
|
|
|
|
#endif
|
2003-11-06 11:22:31 +00:00
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE void SymUnmarkUser (SymEntry* S)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Remove a user mark from the specified symbol */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
{
|
|
|
|
|
/* Reset the bit */
|
|
|
|
|
S->Flags &= ~SF_USER;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define SymUnmarkUser(S) ((S)->Flags &= ~SF_USER)
|
|
|
|
|
#endif
|
2003-11-06 11:22:31 +00:00
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE int SymHasUserMark (SymEntry* S)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Return the state of the user mark for the specified symbol */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
{
|
|
|
|
|
/* Check the bit */
|
|
|
|
|
return (S->Flags & SF_USER) != 0;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define SymHasUserMark(S) (((S)->Flags & SF_USER) != 0)
|
|
|
|
|
#endif
|
2003-11-06 11:22:31 +00:00
|
|
|
|
|
|
|
|
|
struct ExprNode* GetSymExpr (SymEntry* Sym);
|
|
|
|
|
/* Get the expression for a non-const symbol */
|
|
|
|
|
|
2003-11-11 13:57:30 +00:00
|
|
|
|
const struct ExprNode* SymResolve (const SymEntry* Sym);
|
|
|
|
|
/* Helper function for DumpExpr. Resolves a symbol into an expression or return
|
|
|
|
|
* NULL. Do not call in other contexts!
|
|
|
|
|
*/
|
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE const char* GetSymName (const SymEntry* S)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Return the name of the symbol */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
{
|
|
|
|
|
return GetString (S->Name);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define GetSymName(S) GetString ((S)->Name)
|
|
|
|
|
#endif
|
2003-11-06 11:22:31 +00:00
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE unsigned char GetSymAddrSize (const SymEntry* S)
|
2003-11-11 22:16:47 +00:00
|
|
|
|
/* Return the address size of the symbol. Beware: This function will just
|
|
|
|
|
* return the AddrSize member, it will not look at the expression!
|
|
|
|
|
*/
|
2003-11-29 07:53:26 +00:00
|
|
|
|
{
|
|
|
|
|
return S->AddrSize;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define GetSymAddrSize(S) ((S)->AddrSize)
|
|
|
|
|
#endif
|
2003-11-11 22:16:47 +00:00
|
|
|
|
|
2003-11-13 22:03:24 +00:00
|
|
|
|
long GetSymVal (SymEntry* Sym);
|
|
|
|
|
/* Return the value of a symbol assuming it's constant. FAIL will be called
|
|
|
|
|
* in case the symbol is undefined or not constant.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-11-11 22:16:47 +00:00
|
|
|
|
unsigned GetSymIndex (const SymEntry* Sym);
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Return the symbol index for the given symbol */
|
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE const FilePos* GetSymPos (const SymEntry* S)
|
2003-11-06 11:22:31 +00:00
|
|
|
|
/* Return the position of first occurence in the source for the given symbol */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
{
|
|
|
|
|
return &S->Pos;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define GetSymPos(S) (&(S)->Pos)
|
|
|
|
|
#endif
|
2003-11-06 11:22:31 +00:00
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* End of symentry.h */
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|