1 /*****************************************************************************/
5 /* Symbol table for the ca65 macroassembler */
9 /* (C) 1998-2012, 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 /*****************************************************************************/
52 /*****************************************************************************/
54 /*****************************************************************************/
58 /* Arguments for SymFind... */
60 SYM_FIND_EXISTING = 0x00,
62 SYM_CHECK_ONLY = 0x02,
65 /* Symbol table flags */
66 #define ST_NONE 0x00 /* No flags */
67 #define ST_DEFINED 0x01 /* Scope has been defined */
68 #define ST_CLOSED 0x02 /* Scope is closed */
71 typedef struct SymTable SymTable;
73 SymTable* Next; /* Pointer to next table in list */
74 SymTable* Left; /* Pointer to smaller entry */
75 SymTable* Right; /* Pointer to greater entry */
76 SymTable* Parent; /* Link to enclosing scope if any */
77 SymTable* Childs; /* Pointer to child scopes */
78 SymEntry* Label; /* Scope label */
79 Collection Spans; /* Spans for this scope */
80 unsigned Id; /* Scope id */
81 unsigned short Flags; /* Symbol table flags */
82 unsigned char AddrSize; /* Address size */
83 unsigned char Type; /* Type of the scope */
84 unsigned Level; /* Lexical level */
85 unsigned TableSlots; /* Number of hash table slots */
86 unsigned TableEntries; /* Number of entries in the table */
87 unsigned Name; /* Name of the scope */
88 SymEntry* Table[1]; /* Dynamic allocation */
92 extern SymTable* CurrentScope; /* Pointer to current symbol table */
93 extern SymTable* RootScope; /* Root symbol table */
97 /*****************************************************************************/
99 /*****************************************************************************/
103 void SymEnterLevel (const StrBuf* ScopeName, unsigned char Type,
104 unsigned char AddrSize, SymEntry* OwnerSym);
105 /* Enter a new lexical level */
107 void SymLeaveLevel (void);
108 /* Leave the current lexical level */
110 SymTable* SymFindScope (SymTable* Parent, const StrBuf* Name, SymFindAction Action);
111 /* Find a scope in the given enclosing scope */
113 SymTable* SymFindAnyScope (SymTable* Parent, const StrBuf* Name);
114 /* Find a scope in the given or any of its parent scopes. The function will
115 ** never create a new symbol, since this can only be done in one specific
119 SymEntry* SymFindLocal (SymEntry* Parent, const StrBuf* Name, SymFindAction Action);
120 /* Find a cheap local symbol. If Action contains SYM_ALLOC_NEW and the entry is
121 ** not found, create a new one. Return the entry found, or the new entry
122 ** created, or - in case Action is SYM_FIND_EXISTING - return 0.
125 SymEntry* SymFind (SymTable* Scope, const StrBuf* Name, SymFindAction Action);
126 /* Find a new symbol table entry in the given table. If Action contains
127 ** SYM_ALLOC_NEW and the entry is not found, create a new one. Return the
128 ** entry found, or the new entry created, or - in case Action is
129 ** SYM_FIND_EXISTING - return 0.
132 SymEntry* SymFindAny (SymTable* Scope, const StrBuf* Name);
133 /* Find a symbol in the given or any of its parent scopes. The function will
134 ** never create a new symbol, since this can only be done in one specific
138 #if defined(HAVE_INLINE)
139 INLINE unsigned char GetSymTabType (const SymTable* S)
140 /* Return the type of the given symbol table */
145 # define GetSymTabType(S) ((S)->Type)
148 #if defined(HAVE_INLINE)
149 INLINE int SymTabIsClosed (const SymTable* S)
150 /* Return true if the symbol table has been closed */
152 return (S->Flags & ST_CLOSED) != 0;
155 # define SymTabIsClosed(S) (((S)->Flags & ST_CLOSED) != 0)
158 void SymCheck (void);
159 /* Run through all symbols and check for anomalies and errors */
161 void SymDump (FILE* F);
162 /* Dump the symbol table */
164 void WriteImports (void);
165 /* Write the imports list to the object file */
167 void WriteExports (void);
168 /* Write the exports list to the object file */
170 void WriteDbgSyms (void);
171 /* Write a list of all symbols to the object file */
173 void WriteScopes (void);
174 /* Write the scope table to the object file */
178 /* End of symtab.h */