1 /*****************************************************************************/
5 /* Symbol table entries for the cc65 C compiler */
9 /* (C) 2000-2013, 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 /*****************************************************************************/
64 /*****************************************************************************/
66 /*****************************************************************************/
70 /* Storage classes and flags */
71 #define SC_AUTO 0x0001U /* Auto variable */
72 #define SC_REGISTER 0x0002U /* Register variable */
73 #define SC_STATIC 0x0004U /* Static */
74 #define SC_EXTERN 0x0008U /* Extern linkage */
76 #define SC_ENUM 0x0030U /* An enum */
77 #define SC_CONST 0x0020U /* A numeric constant with a type */
78 #define SC_LABEL 0x0040U /* A goto label */
79 #define SC_PARAM 0x0080U /* A function parameter */
80 #define SC_FUNC 0x0100U /* A function */
82 #define SC_DEFTYPE 0x0200U /* Parameter has default type (=int, old style) */
83 #define SC_STORAGE 0x0400U /* Symbol with associated storage */
84 #define SC_DEFAULT 0x0800U /* Flag: default storage class was used */
86 #define SC_DEF 0x1000U /* Symbol is defined */
87 #define SC_REF 0x2000U /* Symbol is referenced */
89 #define SC_TYPE 0x4000U /* This is a type, struct, typedef, etc. */
90 #define SC_STRUCT 0x4001U /* Struct */
91 #define SC_UNION 0x4002U /* Union */
92 #define SC_STRUCTFIELD 0x4003U /* Struct or union field */
93 #define SC_BITFIELD 0x4004U /* A bit-field inside a struct or union */
94 #define SC_TYPEDEF 0x4005U /* A typedef */
95 #define SC_TYPEMASK 0x400FU /* Mask for above types */
97 #define SC_ZEROPAGE 0x8000U /* Symbol marked as zeropage */
99 #define SC_HAVEATTR 0x10000U /* Symbol has attributes */
103 /* Symbol table entry */
104 typedef struct SymEntry SymEntry;
106 SymEntry* NextHash; /* Next entry in hash list */
107 SymEntry* PrevSym; /* Previous symbol in dl list */
108 SymEntry* NextSym; /* Next symbol double linked list */
109 SymEntry* Link; /* General purpose single linked list */
110 struct SymTable* Owner; /* Symbol table the symbol is in */
111 unsigned Flags; /* Symbol flags */
112 Type* Type; /* Symbol type */
113 Collection* Attr; /* Attribute list if any */
114 char* AsmName; /* Assembler name if any */
116 /* Data that differs for the different symbol types */
119 /* Offset for locals or struct members */
122 /* Label name for static symbols */
125 /* Register bank offset and offset of the saved copy on stack for
126 ** register variables.
133 /* Value for constants (including enums) */
136 /* Data for structs/unions */
138 struct SymTable* SymTab; /* Member symbol table */
139 unsigned Size; /* Size of the union/struct */
142 /* Data for bit fields */
144 unsigned Offs; /* Byte offset into struct */
145 unsigned BitOffs; /* Bit offset into storage unit */
146 unsigned BitWidth; /* Width in bits */
149 /* Data for functions */
151 struct FuncDesc* Func; /* Function descriptor */
152 struct Segments* Seg; /* Segments for this function */
153 struct LiteralPool* LitPool; /* Literal pool for this function */
156 /* Segment name for tentantive global definitions */
159 char Name[1]; /* Name, dynamically allocated */
164 /*****************************************************************************/
166 /*****************************************************************************/
170 SymEntry* NewSymEntry (const char* Name, unsigned Flags);
171 /* Create a new symbol table with the given name */
173 void FreeSymEntry (SymEntry* E);
174 /* Free a symbol entry */
176 void DumpSymEntry (FILE* F, const SymEntry* E);
177 /* Dump the given symbol table entry to the file in readable form */
179 #if defined(HAVE_INLINE)
180 INLINE int SymIsBitField (const SymEntry* Sym)
181 /* Return true if the given entry is a bit-field entry */
183 return ((Sym->Flags & SC_BITFIELD) == SC_BITFIELD);
186 # define SymIsBitField(Sym) (((Sym)->Flags & SC_BITFIELD) == SC_BITFIELD)
189 #if defined(HAVE_INLINE)
190 INLINE int SymIsTypeDef (const SymEntry* Sym)
191 /* Return true if the given entry is a typedef entry */
193 return ((Sym->Flags & SC_TYPEDEF) == SC_TYPEDEF);
196 # define SymIsTypeDef(Sym) (((Sym)->Flags & SC_TYPEDEF) == SC_TYPEDEF)
199 #if defined(HAVE_INLINE)
200 INLINE int SymIsDef (const SymEntry* Sym)
201 /* Return true if the given entry is defined */
203 return ((Sym->Flags & SC_DEF) == SC_DEF);
206 # define SymIsDef(Sym) (((Sym)->Flags & SC_DEF) == SC_DEF)
209 #if defined(HAVE_INLINE)
210 INLINE int SymIsRef (const SymEntry* Sym)
211 /* Return true if the given entry is referenced */
213 return ((Sym->Flags & SC_REF) == SC_REF);
216 # define SymIsRef(Sym) (((Sym)->Flags & SC_REF) == SC_REF)
219 #if defined(HAVE_INLINE)
220 INLINE int SymIsRegVar (const SymEntry* Sym)
221 /* Return true if the given entry is a register variable */
222 /* ### HACK! Fix the ugly type flags! */
224 return ((Sym->Flags & (SC_REGISTER|SC_TYPE)) == SC_REGISTER);
227 # define SymIsRegVar(Sym) (((Sym)->Flags & (SC_REGISTER|SC_TYPE)) == SC_REGISTER)
230 int SymIsOutputFunc (const SymEntry* Sym);
231 /* Return true if this is a function that must be output */
233 #if defined(HAVE_INLINE)
234 INLINE const char* SymGetAsmName (const SymEntry* Sym)
235 /* Return the assembler label name for the symbol (beware: may be NULL!) */
240 # define SymGetAsmName(Sym) ((Sym)->AsmName)
243 const DeclAttr* SymGetAttr (const SymEntry* Sym, DeclAttrType AttrType);
244 /* Return an attribute for this symbol or NULL if the attribute does not exist */
246 #if defined(HAVE_INLINE)
247 INLINE int SymHasAttr (const SymEntry* Sym, DeclAttrType A)
248 /* Return true if the symbol has the given attribute */
250 return (SymGetAttr (Sym, A) != 0);
253 # define SymHasAttr(Sym, A) (SymGetAttr (Sym, A) != 0)
256 void SymUseAttr (SymEntry* Sym, struct Declaration* D);
257 /* Use the attributes from the declaration for this symbol */
259 void SymSetAsmName (SymEntry* Sym);
260 /* Set the assembler name for an external symbol from the name of the symbol */
262 void CvtRegVarToAuto (SymEntry* Sym);
263 /* Convert a register variable to an auto variable */
265 void ChangeSymType (SymEntry* Entry, Type* T);
266 /* Change the type of the given symbol */
268 void ChangeAsmName (SymEntry* Entry, const char* NewAsmName);
269 /* Change the assembler name of the symbol */
271 int HasAnonName (const SymEntry* Entry);
272 /* Return true if the symbol entry has an anonymous name */
276 /* End of symentry.h */