9 date 2007.08.12.18.59.10; author khansen; state Exp;
14 date 2007.08.09.20.34.09; author khansen; state Exp;
19 date 2007.07.22.13.35.20; author khansen; state Exp;
24 date 2005.01.05.02.27.23; author kenth; state Exp;
29 date 2004.12.19.20.47.04; author kenth; state Exp;
34 date 2004.12.16.13.21.47; author kenth; state Exp;
39 date 2004.12.06.04.54.00; author kenth; state Exp;
44 date 2004.06.30.07.56.45; author kenth; state Exp;
55 @ability to generate pure 6502 binary
59 * $Id: symtab.h,v 1.7 2007/08/09 20:34:09 khansen Exp khansen $
61 * Revision 1.7 2007/08/09 20:34:09 khansen
64 * Revision 1.6 2007/07/22 13:35:20 khansen
65 * convert tabs to whitespaces
67 * Revision 1.5 2005/01/05 02:27:23 kenth
68 * ordered_field_list has pointer to symtab_entry instead of id
70 * Revision 1.4 2004/12/19 20:47:04 kenth
73 * Revision 1.3 2004/12/16 13:21:47 kenth
76 * Revision 1.2 2004/12/06 04:54:00 kenth
79 * Revision 1.1 2004/06/30 07:56:45 kenth
85 * (C) 2004 Kent Hansen
87 * The XORcyst is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
89 * the Free Software Foundation; either version 2 of the License, or
90 * (at your option) any later version.
92 * The XORcyst is distributed in the hope that it will be useful,
93 * but WITHOUT ANY WARRANTY; without even the implied warranty of
94 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95 * GNU General Public License for more details.
97 * You should have received a copy of the GNU General Public License
98 * along with The XORcyst; if not, write to the Free Software
99 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
108 * The possible types of symbol.
110 enum tag_symbol_type {
111 LABEL_SYMBOL=0, /* A label */
112 CONSTANT_SYMBOL, /* A constant */
113 MACRO_SYMBOL, /* A macro */
114 STRUC_SYMBOL, /* A structure */
115 UNION_SYMBOL, /* A union */
116 RECORD_SYMBOL, /* A record */
117 ENUM_SYMBOL, /* An enumeration */
118 VAR_SYMBOL, /* A variable */
119 PROC_SYMBOL, /* A procedure */
123 typedef enum tag_symbol_type symbol_type;
125 typedef struct tag_label_attribs label_attribs;
127 /* Possible bits for entry.flags */
128 #define PUBLIC_FLAG 0x01 /* Symbol is public (exported) */
129 #define EXTRN_FLAG 0x02 /* Symbol is external */
130 #define DATA_FLAG 0x04 /* Symbol is in dataseg */
131 #define VOLATILE_FLAG 0x08 /* Symbol is volatile */
132 #define ZEROPAGE_FLAG 0x10 /* Symbol should be mapped to ZP */
133 #define ALIGN_FLAG 0x20 /* Symbol has alignment constraint */
134 #define ADDR_FLAG 0x40 /* Symbol has hardcoded address */
135 #define ERROR_UNDEFINED_FLAG 0x80
137 * Must keep a definition-ordered list of struct or union's fields.
139 struct tag_ordered_field_list {
140 struct tag_symtab_entry *entry;
141 struct tag_ordered_field_list *next;
144 typedef struct tag_ordered_field_list ordered_field_list;
147 * Structure that describes a struct or union.
149 struct tag_struc_attribs {
150 astnode *size; /* total size of the struct or union */
151 ordered_field_list *fields;
154 typedef struct tag_struc_attribs struc_attribs;
156 struct tag_field_attribs {
157 astnode *offset; /* offset from start of structure, in bytes */
158 astnode *size; /* size of field, in bytes */
161 typedef struct tag_field_attribs field_attribs;
164 * Structure that describes a symbol table entry.
166 struct tag_symtab_entry {
169 astnode *def; /* Pointer to something that describes this entry more */
173 int align; /* 2^align = boundary */
175 struct tag_symtab *symtab; /* Child symbols (STRUC|UNION|ENUM_SYMBOL) */
177 field_attribs field; /* type == VAR_SYMBOL */
178 struc_attribs struc; /* type == UNION|STRUC_SYMBOL */
180 struct tag_symtab_entry *left;
181 struct tag_symtab_entry *right;
182 struct tag_symtab_entry *parent;
185 typedef struct tag_symtab_entry symtab_entry;
188 * Structure that describes a symbol table.
191 struct tag_symtab *parent;
195 typedef struct tag_symtab symtab;
198 * Structure that describes a list of identifiers.
200 struct tag_symbol_ident_list {
205 typedef struct tag_symbol_ident_list symbol_ident_list;
207 /* Function prototypes */
208 symtab *symtab_create();
209 void symtab_push(symtab *);
210 symtab *symtab_pop();
211 symtab *symtab_tos();
212 symtab *symtab_parent();
213 symtab_entry *symtab_enter(const char *, symbol_type, astnode *, int);
214 symtab_entry *symtab_lookup(const char *);
215 symtab_entry *symtab_lookup_recursive(const char *);
216 symtab_entry *symtab_global_lookup(const char *);
218 int symtab_type_count(symbol_type);
219 void symtab_finalize(symtab *);
220 void symtab_remove(const char *);
221 void symtab_remove_by_type(symbol_type);
222 int symtab_list(symbol_ident_list *);
223 int symtab_list_type(symbol_type, symbol_ident_list *);
224 void symtab_list_finalize(symbol_ident_list *);
227 #endif /* !SYMTAB_H */
238 * $Id: symtab.h,v 1.6 2007/07/22 13:35:20 khansen Exp khansen $
248 @convert tabs to whitespaces
253 * $Id: symtab.h,v 1.5 2005/01/05 02:27:23 kenth Exp khansen $
261 @ordered_field_list has pointer to symtab_entry instead of id
266 * $Id: symtab.h,v 1.4 2004/12/19 20:47:04 kenth Exp kenth $
270 LABEL_SYMBOL=0, /* A label */
271 CONSTANT_SYMBOL, /* A constant */
272 MACRO_SYMBOL, /* A macro */
273 STRUC_SYMBOL, /* A structure */
274 UNION_SYMBOL, /* A union */
275 RECORD_SYMBOL, /* A record */
276 ENUM_SYMBOL, /* An enumeration */
277 VAR_SYMBOL, /* A variable */
278 PROC_SYMBOL, /* A procedure */
282 #define PUBLIC_FLAG 0x01 /* Symbol is public (exported) */
283 #define EXTRN_FLAG 0x02 /* Symbol is external */
284 #define DATA_FLAG 0x04 /* Symbol is in dataseg */
285 #define VOLATILE_FLAG 0x08 /* Symbol is volatile */
286 #define ZEROPAGE_FLAG 0x10 /* Symbol should be mapped to ZP */
287 #define ALIGN_FLAG 0x20 /* Symbol has alignment constraint */
288 #define ADDR_FLAG 0x40 /* Symbol has hardcoded address */
291 struct tag_symtab_entry *entry;
292 struct tag_ordered_field_list *next;
295 astnode *size; /* total size of the struct or union */
296 ordered_field_list *fields;
299 astnode *offset; /* offset from start of structure, in bytes */
300 astnode *size; /* size of field, in bytes */
305 astnode *def; /* Pointer to something that describes this entry more */
309 int align; /* 2^align = boundary */
311 struct tag_symtab *symtab; /* Child symbols (STRUC|UNION|ENUM_SYMBOL) */
313 field_attribs field; /* type == VAR_SYMBOL */
314 struc_attribs struc; /* type == UNION|STRUC_SYMBOL */
316 struct tag_symtab_entry *left;
317 struct tag_symtab_entry *right;
318 struct tag_symtab_entry *parent;
321 struct tag_symtab *parent;
329 #endif /* !SYMTAB_H */
340 * $Id: symtab.h,v 1.3 2004/12/16 13:21:47 kenth Exp kenth $
355 * $Id: symtab.h,v 1.2 2004/12/06 04:54:00 kenth Exp kenth $
369 * $Id: symtab.h,v 1.1 2004/06/30 07:56:45 kenth Exp $
387 EXTERNAL_SYMBOL, /* An external symbol */
390 #define DEFINED_FLAG 0x02 /* Symbol is defined */
394 void *def; /* Pointer to something that describes this entry more */
398 int ref_count; /* type == LABEL_SYMBOL */
401 symtab_entry *symtab_enter(const char *, symbol_type, void *, int);