1 /*****************************************************************************/
5 /* Symbol table entries for the cc65 C compiler */
9 /* (C) 2000-2008 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 /*****************************************************************************/
51 /*****************************************************************************/
53 /*****************************************************************************/
61 /*****************************************************************************/
63 /*****************************************************************************/
67 /* Storage classes and flags */
68 #define SC_AUTO 0x0001U
69 #define SC_REGISTER 0x0002U /* Register variable, is in static storage */
70 #define SC_STATIC 0x0004U
71 #define SC_EXTERN 0x0008U
73 #define SC_ENUM 0x0030U /* An enum (numeric constant) */
74 #define SC_CONST 0x0020U /* A numeric constant with a type */
75 #define SC_LABEL 0x0040U /* A goto label */
76 #define SC_PARAM 0x0080U /* This is a function parameter */
77 #define SC_FUNC 0x0100U /* Function entry */
79 #define SC_DEFTYPE 0x0200U /* Parameter has default type (=int, old style) */
80 #define SC_STORAGE 0x0400U /* Symbol with associated storage */
81 #define SC_DEFAULT 0x0800U /* Flag: default storage class was used */
83 #define SC_DEF 0x1000U /* Symbol is defined */
84 #define SC_REF 0x2000U /* Symbol is referenced */
86 #define SC_TYPE 0x4000U /* This is a type, struct, typedef, etc. */
87 #define SC_STRUCT 0x4001U /* Struct or union */
88 #define SC_STRUCTFIELD 0x4002U /* Struct or union field */
89 #define SC_TYPEDEF 0x4003U /* A typedef */
91 #define SC_ZEROPAGE 0x8000U /* Symbol marked as zeropage */
95 /* Symbol table entry */
96 typedef struct SymEntry SymEntry;
98 SymEntry* NextHash; /* Next entry in hash list */
99 SymEntry* PrevSym; /* Previous symbol in dl list */
100 SymEntry* NextSym; /* Next symbol double linked list */
101 SymEntry* Link; /* General purpose single linked list */
102 struct SymTable* Owner; /* Symbol table the symbol is in */
103 unsigned Flags; /* Symbol flags */
104 Type* Type; /* Symbol type */
105 char* AsmName; /* Assembler name if any */
107 /* Data that differs for the different symbol types */
110 /* Offset for locals or struct members */
113 /* Label name for static symbols */
116 /* Register bank offset and offset of the saved copy on stack for
117 * register variables.
124 /* Value for constants (including enums) */
127 /* Data for structs/unions */
129 struct SymTable* SymTab; /* Member symbol table */
130 unsigned Size; /* Size of the union/struct */
133 /* Data for functions */
135 struct FuncDesc* Func; /* Function descriptor */
136 struct Segments* Seg; /* Segments for this function */
140 char Name[1]; /* Name, dynamically allocated */
145 /*****************************************************************************/
147 /*****************************************************************************/
151 SymEntry* NewSymEntry (const char* Name, unsigned Flags);
152 /* Create a new symbol table with the given name */
154 void FreeSymEntry (SymEntry* E);
155 /* Free a symbol entry */
157 void DumpSymEntry (FILE* F, const SymEntry* E);
158 /* Dump the given symbol table entry to the file in readable form */
160 #if defined(HAVE_INLINE)
161 INLINE int SymIsTypeDef (const SymEntry* Sym)
162 /* Return true if the given entry is a typedef entry */
164 return ((Sym->Flags & SC_TYPEDEF) == SC_TYPEDEF);
167 # define SymIsTypeDef(Sym) (((Sym)->Flags & SC_TYPEDEF) == SC_TYPEDEF)
170 #if defined(HAVE_INLINE)
171 INLINE int SymIsDef (const SymEntry* Sym)
172 /* Return true if the given entry is defined */
174 return ((Sym->Flags & SC_DEF) == SC_DEF);
177 # define SymIsDef(Sym) (((Sym)->Flags & SC_DEF) == SC_DEF)
180 #if defined(HAVE_INLINE)
181 INLINE int SymIsRef (const SymEntry* Sym)
182 /* Return true if the given entry is referenced */
184 return ((Sym->Flags & SC_REF) == SC_REF);
187 # define SymIsRef(Sym) (((Sym)->Flags & SC_REF) == SC_REF)
190 #if defined(HAVE_INLINE)
191 INLINE int SymIsRegVar (const SymEntry* Sym)
192 /* Return true if the given entry is a register variable */
193 /* ### HACK! Fix the ugly type flags! */
195 return ((Sym->Flags & (SC_REGISTER|SC_TYPE)) == SC_REGISTER);
198 # define SymIsRegVar(Sym) (((Sym)->Flags & (SC_REGISTER|SC_TYPE)) == SC_REGISTER)
201 #if defined(HAVE_INLINE)
202 INLINE const char* SymGetAsmName (const SymEntry* Sym)
203 /* Return the assembler label name for the symbol (beware: may be NULL!) */
208 # define SymGetAsmName(Sym) ((Sym)->AsmName)
211 void CvtRegVarToAuto (SymEntry* Sym);
212 /* Convert a register variable to an auto variable */
214 void ChangeSymType (SymEntry* Entry, Type* T);
215 /* Change the type of the given symbol */
217 void ChangeAsmName (SymEntry* Entry, const char* NewAsmName);
218 /* Change the assembler name of the symbol */
220 int HasAnonName (const SymEntry* Entry);
221 /* Return true if the symbol entry has an anonymous name */
225 /* End of symentry.h */