]> git.sur5r.net Git - cc65/blob - src/cc65/symentry.h
Re-added register variables.
[cc65] / src / cc65 / symentry.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                symentry.h                                 */
4 /*                                                                           */
5 /*               Symbol table entries for the cc65 C compiler                */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000-2002 Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef SYMENTRY_H
37 #define SYMENTRY_H
38
39
40
41 #include <stdio.h>
42
43 /* common */
44 #include "inline.h"
45
46 /* cc65 */
47 #include "datatype.h"
48
49
50
51 /*****************************************************************************/
52 /*                                  Forwards                                 */
53 /*****************************************************************************/
54
55
56
57 struct Segments;
58
59
60
61 /*****************************************************************************/
62 /*                              struct SymEntry                              */
63 /*****************************************************************************/
64
65
66
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
72
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 */
78
79 #define SC_STORAGE      0x0400U /* Symbol with associated storage */
80 #define SC_DEFAULT      0x0800U /* Flag: default storage class was used */
81
82 #define SC_DEF          0x1000U /* Symbol is defined */
83 #define SC_REF          0x2000U /* Symbol is referenced */
84
85 #define SC_TYPE         0x4000U /* This is a type, struct, typedef, etc. */
86 #define SC_STRUCT       0x4001U /* Struct or union */
87 #define SC_STRUCTFIELD  0x4002U /* Struct or union field */
88 #define SC_TYPEDEF      0x4003U /* A typedef */
89
90 #define SC_ZEROPAGE     0x8000U /* Symbol marked as zeropage */
91
92
93
94 /* Symbol table entry */
95 typedef struct SymEntry SymEntry;
96 struct SymEntry {
97     SymEntry*                   NextHash; /* Next entry in hash list */
98     SymEntry*                   PrevSym;  /* Previous symbol in dl list */
99     SymEntry*                   NextSym;  /* Next symbol double linked list */
100     SymEntry*                   Link;     /* General purpose single linked list */
101     struct SymTable*            Owner;    /* Symbol table the symbol is in */
102     unsigned                    Flags;    /* Symbol flags */
103     type*                       Type;     /* Symbol type */
104     char*                       AsmName;  /* Assembler name if any */
105
106     /* Data that differs for the different symbol types */
107     union {
108
109         /* Offset for locals or struct members */
110         int                     Offs;
111
112         /* Label name for static symbols */
113         unsigned                Label;
114
115         /* Register bank offset and offset of the saved copy on stack for
116          * register variables.
117          */
118         struct {
119             int                 RegOffs;
120             int                 SaveOffs;
121         } R;
122
123         /* Value for constants (including enums) */
124         long                    ConstVal;
125
126         /* Data for structs/unions */
127         struct {
128             struct SymTable*    SymTab;   /* Member symbol table */
129             unsigned            Size;     /* Size of the union/struct */
130         } S;
131
132         /* Data for functions */
133         struct {
134             struct FuncDesc*    Func;     /* Function descriptor */
135             struct Segments*    Seg;      /* Segments for this function */
136         } F;
137
138     } V;
139     char                       Name[1]; /* Name, dynamically allocated */
140 };
141
142
143
144 /*****************************************************************************/
145 /*                                   Code                                    */
146 /*****************************************************************************/
147
148
149
150 SymEntry* NewSymEntry (const char* Name, unsigned Flags);
151 /* Create a new symbol table with the given name */
152
153 void FreeSymEntry (SymEntry* E);
154 /* Free a symbol entry */
155
156 void DumpSymEntry (FILE* F, const SymEntry* E);
157 /* Dump the given symbol table entry to the file in readable form */
158
159 #if defined(HAVE_INLINE)
160 INLINE int SymIsTypeDef (const SymEntry* Sym)
161 /* Return true if the given entry is a typedef entry */
162 {
163     return ((Sym->Flags & SC_TYPEDEF) == SC_TYPEDEF);
164 }
165 #else
166 #  define SymIsTypeDef(Sym)     (((Sym)->Flags & SC_TYPEDEF) == SC_TYPEDEF)
167 #endif
168
169 #if defined(HAVE_INLINE)
170 INLINE int SymIsDef (const SymEntry* Sym)
171 /* Return true if the given entry is defined */
172 {
173     return ((Sym->Flags & SC_DEF) == SC_DEF);
174 }
175 #else
176 #  define SymIsDef(Sym)     (((Sym)->Flags & SC_DEF) == SC_DEF)
177 #endif
178
179 #if defined(HAVE_INLINE)
180 INLINE int SymIsRef (const SymEntry* Sym)
181 /* Return true if the given entry is referenced */
182 {
183     return ((Sym->Flags & SC_REF) == SC_REF);
184 }
185 #else
186 #  define SymIsRef(Sym)     (((Sym)->Flags & SC_REF) == SC_REF)
187 #endif
188
189 #if defined(HAVE_INLINE)
190 INLINE int SymIsRegVar (const SymEntry* Sym)
191 /* Return true if the given entry is a register variable */
192 {
193     return ((Sym->Flags & SC_REGISTER) == SC_REGISTER);
194 }
195 #else
196 #  define SymIsRegVar(Sym)      (((Sym)->Flags & SC_REGISTER) == SC_REGISTER)
197 #endif
198
199 void CvtRegVarToAuto (SymEntry* Sym);
200 /* Convert a register variable to an auto variable */
201
202 void ChangeSymType (SymEntry* Entry, type* Type);
203 /* Change the type of the given symbol */
204
205 void ChangeAsmName (SymEntry* Entry, const char* NewAsmName);
206 /* Change the assembler name of the symbol */
207
208 int HasAnonName (const SymEntry* Entry);
209 /* Return true if the symbol entry has an anonymous name */
210
211
212
213 /* End of symentry.h */
214 #endif
215
216
217