move operator-to-string conversion to unit.c
[xorcyst.git] / symtab.h
blob61e1d84ac17d986890219154eec4717caac999e8
1 /*
2 * $Id: symtab.h,v 1.8 2007/08/12 18:59:10 khansen Exp $
3 * $Log: symtab.h,v $
4 * Revision 1.8 2007/08/12 18:59:10 khansen
5 * ability to generate pure 6502 binary
7 * Revision 1.7 2007/08/09 20:34:09 khansen
8 * progress
10 * Revision 1.6 2007/07/22 13:35:20 khansen
11 * convert tabs to whitespaces
13 * Revision 1.5 2005/01/05 02:27:23 kenth
14 * ordered_field_list has pointer to symtab_entry instead of id
16 * Revision 1.4 2004/12/19 20:47:04 kenth
17 * xorcyst 1.4.0
19 * Revision 1.3 2004/12/16 13:21:47 kenth
20 * added RECORD_SYMBOL
22 * Revision 1.2 2004/12/06 04:54:00 kenth
23 * xorcyst 1.1.0
25 * Revision 1.1 2004/06/30 07:56:45 kenth
26 * Initial revision
30 /**
31 * (C) 2004 Kent Hansen
33 * The XORcyst is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
38 * The XORcyst is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
43 * You should have received a copy of the GNU General Public License
44 * along with The XORcyst; if not, write to the Free Software
45 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48 #ifndef SYMTAB_H
49 #define SYMTAB_H
51 #include "astnode.h"
53 /**
54 * The possible types of symbol.
56 enum tag_symbol_type {
57 LABEL_SYMBOL=0, /* A label */
58 CONSTANT_SYMBOL, /* A constant */
59 MACRO_SYMBOL, /* A macro */
60 STRUC_SYMBOL, /* A structure */
61 UNION_SYMBOL, /* A union */
62 RECORD_SYMBOL, /* A record */
63 ENUM_SYMBOL, /* An enumeration */
64 VAR_SYMBOL, /* A variable */
65 PROC_SYMBOL, /* A procedure */
66 ANY_SYMBOL
69 typedef enum tag_symbol_type symbol_type;
71 typedef struct tag_label_attribs label_attribs;
73 /* Possible bits for entry.flags */
74 #define PUBLIC_FLAG 0x01 /* Symbol is public (exported) */
75 #define EXTRN_FLAG 0x02 /* Symbol is external */
76 #define DATA_FLAG 0x04 /* Symbol is in dataseg */
77 #define VOLATILE_FLAG 0x08 /* Symbol is volatile */
78 #define ZEROPAGE_FLAG 0x10 /* Symbol should be mapped to ZP */
79 #define ALIGN_FLAG 0x20 /* Symbol has alignment constraint */
80 #define ADDR_FLAG 0x40 /* Symbol has hardcoded address */
81 #define ERROR_UNDEFINED_FLAG 0x80
82 /**
83 * Must keep a definition-ordered list of struct or union's fields.
85 struct tag_ordered_field_list {
86 struct tag_symtab_entry *entry;
87 struct tag_ordered_field_list *next;
90 typedef struct tag_ordered_field_list ordered_field_list;
92 /**
93 * Structure that describes a struct or union.
95 struct tag_struc_attribs {
96 astnode *size; /* total size of the struct or union */
97 ordered_field_list *fields;
100 typedef struct tag_struc_attribs struc_attribs;
102 struct tag_field_attribs {
103 astnode *offset; /* offset from start of structure, in bytes */
104 astnode *size; /* size of field, in bytes */
107 typedef struct tag_field_attribs field_attribs;
110 * Structure that describes a symbol table entry.
112 struct tag_symtab_entry {
113 symbol_type type;
114 char *id;
115 astnode *def; /* Pointer to something that describes this entry more */
116 int flags;
117 int tag;
118 int ref_count;
119 int align; /* 2^align = boundary */
120 int address;
121 struct tag_symtab *symtab; /* Child symbols (STRUC|UNION|ENUM_SYMBOL) */
122 union {
123 field_attribs field; /* type == VAR_SYMBOL */
124 struc_attribs struc; /* type == UNION|STRUC_SYMBOL */
126 struct tag_symtab_entry *left;
127 struct tag_symtab_entry *right;
128 struct tag_symtab_entry *parent;
131 typedef struct tag_symtab_entry symtab_entry;
134 * Structure that describes a symbol table.
136 struct tag_symtab {
137 struct tag_symtab *parent;
138 symtab_entry *root;
141 typedef struct tag_symtab symtab;
144 * Structure that describes a list of identifiers.
146 struct tag_symbol_ident_list {
147 char **idents;
148 int size;
151 typedef struct tag_symbol_ident_list symbol_ident_list;
153 /* Function prototypes */
154 symtab *symtab_create();
155 void symtab_push(symtab *);
156 symtab *symtab_pop();
157 symtab *symtab_tos();
158 symtab *symtab_parent();
159 symtab_entry *symtab_enter(const char *, symbol_type, astnode *, int);
160 symtab_entry *symtab_lookup(const char *);
161 symtab_entry *symtab_lookup_recursive(const char *);
162 symtab_entry *symtab_global_lookup(const char *);
163 int symtab_size();
164 int symtab_type_count(symbol_type);
165 void symtab_finalize(symtab *);
166 void symtab_remove(const char *);
167 void symtab_remove_by_type(symbol_type);
168 int symtab_list(symbol_ident_list *);
169 int symtab_list_type(symbol_type, symbol_ident_list *);
170 void symtab_list_finalize(symbol_ident_list *);
171 void symtab_print();
173 #endif /* !SYMTAB_H */