1 /*****************************************************************************/
5 /* Symbol table for the ca65 macroassembler */
9 /* (C) 1998-2011, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
53 /*****************************************************************************/
55 /*****************************************************************************/
59 /* Symbol table flags */
60 #define ST_NONE 0x00 /* No flags */
61 #define ST_DEFINED 0x01 /* Scope has been defined */
63 /* Symbol table types */
65 ST_GLOBAL, /* Root level */
67 ST_SCOPE, /* .SCOPE */
68 ST_SCOPE_HAS_DATA = ST_SCOPE, /* Last scope that contains data */
69 ST_STRUCT, /* .STRUCT/.UNION */
75 typedef struct SymTable SymTable;
77 SymTable* Next; /* Pointer to next table in list */
78 SymTable* Left; /* Pointer to smaller entry */
79 SymTable* Right; /* Pointer to greater entry */
80 SymTable* Parent; /* Link to enclosing scope if any */
81 SymTable* Childs; /* Pointer to child scopes */
82 SymEntry* OwnerSym; /* Symbol that "owns" the scope */
83 Collection SegRanges; /* Segment ranges for this scope */
84 unsigned Id; /* Scope id */
85 unsigned short Flags; /* Symbol table flags */
86 unsigned char AddrSize; /* Address size */
87 unsigned char Type; /* Type of the scope */
88 unsigned Level; /* Lexical level */
89 unsigned TableSlots; /* Number of hash table slots */
90 unsigned TableEntries; /* Number of entries in the table */
91 unsigned Name; /* Name of the scope */
92 SymEntry* Table[1]; /* Dynamic allocation */
96 extern SymTable* CurrentScope; /* Pointer to current symbol table */
97 extern SymTable* RootScope; /* Root symbol table */
101 /*****************************************************************************/
103 /*****************************************************************************/
107 void SymEnterLevel (const StrBuf* ScopeName, unsigned char Type,
108 unsigned char AddrSize, SymEntry* OwnerSym);
109 /* Enter a new lexical level */
111 void SymLeaveLevel (void);
112 /* Leave the current lexical level */
114 SymTable* SymFindScope (SymTable* Parent, const StrBuf* Name, int AllocNew);
115 /* Find a scope in the given enclosing scope */
117 SymTable* SymFindAnyScope (SymTable* Parent, const StrBuf* Name);
118 /* Find a scope in the given or any of its parent scopes. The function will
119 * never create a new symbol, since this can only be done in one specific
123 SymEntry* SymFindLocal (SymEntry* Parent, const StrBuf* StrBuf, int AllocNew);
124 /* Find a cheap local symbol. If AllocNew is given and the entry is not
125 * found, create a new one. Return the entry found, or the new entry created,
126 * or - in case AllocNew is zero - return 0.
129 SymEntry* SymFind (SymTable* Scope, const StrBuf* Name, int AllocNew);
130 /* Find a new symbol table entry in the given table. If AllocNew is given and
131 * the entry is not found, create a new one. Return the entry found, or the
132 * new entry created, or - in case AllocNew is zero - return 0.
135 SymEntry* SymFindAny (SymTable* Scope, const StrBuf* Name);
136 /* Find a symbol in the given or any of its parent scopes. The function will
137 * never create a new symbol, since this can only be done in one specific
141 #if defined(HAVE_INLINE)
142 INLINE unsigned char GetSymTabType (const SymTable* S)
143 /* Return the type of the given symbol table */
148 # define GetSymTabType(S) ((S)->Type)
151 unsigned char GetCurrentSymTabType ();
152 /* Return the type of the current symbol table */
154 void SymCheck (void);
155 /* Run through all symbols and check for anomalies and errors */
157 void SymDump (FILE* F);
158 /* Dump the symbol table */
160 void WriteImports (void);
161 /* Write the imports list to the object file */
163 void WriteExports (void);
164 /* Write the exports list to the object file */
166 void WriteDbgSyms (void);
167 /* Write a list of all symbols to the object file */
169 void WriteScopes (void);
170 /* Write the scope table to the object file */
174 /* End of symtab.h */