Mercurial > hg-old > index.cgi
annotate lwasm/symbol.c @ 426:652eee8f0c82
Fixed lw_expr_destroy() to not crash on NULL
author | lost@l-w.ca |
---|---|
date | Sun, 19 Sep 2010 10:40:37 -0600 |
parents | cac204676434 |
children |
rev | line source |
---|---|
342 | 1 /* |
2 symbol.c | |
3 | |
4 Copyright © 2010 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 #include <config.h> | |
23 | |
390
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
24 #include <stdio.h> |
342 | 25 #include <stdlib.h> |
26 #include <string.h> | |
27 | |
28 #include <lw_alloc.h> | |
29 #include <lw_expr.h> | |
370 | 30 #include <lw_string.h> |
342 | 31 |
32 #include "lwasm.h" | |
33 | |
406 | 34 struct symtabe *symbol_findprev(asmstate_t *as, struct symtabe *se) |
35 { | |
36 struct symtabe *se1, *se2; | |
37 int i; | |
38 | |
39 for (se2 = NULL, se1 = as -> symtab.head; se1; se1 = se1 -> next) | |
40 { | |
41 debug_message(as, 200, "Sorting; looking at symbol %s (%p) for %s", se1 -> symbol, se1, se -> symbol); | |
42 /* compare se with se1 */ | |
43 i = strcasecmp(se -> symbol, se1 -> symbol); | |
44 | |
45 /* if the symbol sorts before se1, we just need to return */ | |
46 if (i < 0) | |
47 return se2; | |
48 | |
49 if (i == 0) | |
50 { | |
51 /* symbol name matches; compare other things */ | |
52 | |
53 /*if next version is greater than this one, return */ | |
54 if (se -> version > se1 -> version) | |
55 return se2; | |
56 /* if next context is great than this one, return */ | |
57 if (se -> context > se1 -> context) | |
58 return se2; | |
59 | |
60 /* if section name is greater, return */ | |
61 /* if se has no section but se1 does, we go first */ | |
62 if (se -> section == NULL && se1 -> section != NULL) | |
63 return se2; | |
64 if (se -> section != NULL && se -> section != NULL) | |
65 { | |
66 /* compare section names and if se < se1, return */ | |
67 i = strcasecmp(se -> section -> name, se1 -> section -> name); | |
68 if (i < 0) | |
69 return se2; | |
70 } | |
71 } | |
72 | |
73 se2 = se1; | |
74 } | |
75 return se2; | |
76 } | |
77 | |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
78 struct symtabe *register_symbol(asmstate_t *as, line_t *cl, char *sym, lw_expr_t val, int flags) |
342 | 79 { |
80 struct symtabe *se; | |
406 | 81 struct symtabe *sprev; |
342 | 82 int islocal = 0; |
83 int context = -1; | |
84 int version = -1; | |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
85 char *cp; |
342 | 86 |
406 | 87 debug_message(as, 200, "Register symbol %s (%02X), %s", sym, flags, lw_expr_print(val)); |
88 | |
389
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
89 if (!(flags & symbol_flag_nocheck)) |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
90 { |
411
cac204676434
Allow symbols to start with digits if they contain $, ?, or @; numbered locals
lost@l-w.ca
parents:
406
diff
changeset
|
91 if (!sym || !*sym) |
cac204676434
Allow symbols to start with digits if they contain $, ?, or @; numbered locals
lost@l-w.ca
parents:
406
diff
changeset
|
92 { |
cac204676434
Allow symbols to start with digits if they contain $, ?, or @; numbered locals
lost@l-w.ca
parents:
406
diff
changeset
|
93 lwasm_register_error(as, cl, "Bad symbol (%s)", sym); |
cac204676434
Allow symbols to start with digits if they contain $, ?, or @; numbered locals
lost@l-w.ca
parents:
406
diff
changeset
|
94 return NULL; |
cac204676434
Allow symbols to start with digits if they contain $, ?, or @; numbered locals
lost@l-w.ca
parents:
406
diff
changeset
|
95 } |
cac204676434
Allow symbols to start with digits if they contain $, ?, or @; numbered locals
lost@l-w.ca
parents:
406
diff
changeset
|
96 if (*sym < 0x80 && (!strchr(SSYMCHARS, *sym) && !strchr(sym + 1, '$') && !strchr(sym + 1, '@') && !strchr(sym + 1, '?'))) |
389
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
97 { |
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
98 lwasm_register_error(as, cl, "Bad symbol (%s)", sym); |
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
99 return NULL; |
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
100 } |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
101 |
389
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
102 if ((*sym == '$' || *sym == '@') && (sym[1] >= '0' && sym[1] <= '9')) |
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
103 { |
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
104 lwasm_register_error(as, cl, "Bad symbol (%s)", sym); |
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
105 return NULL; |
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
106 } |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
107 } |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
108 |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
109 for (cp = sym; *cp; cp++) |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
110 { |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
111 if (*cp == '@' || *cp == '?') |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
112 islocal = 1; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
346
diff
changeset
|
113 if (*cp == '$' && !(CURPRAGMA(cl, PRAGMA_DOLLARNOTLOCAL))) |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
114 islocal = 1; |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
115 |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
116 // bad symbol |
389
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
117 if (!(flags & symbol_flag_nocheck) && *cp < 0x80 && !strchr(SYMCHARS, *cp)) |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
118 { |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
119 lwasm_register_error(as, cl, "Bad symbol (%s)", sym); |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
120 return NULL; |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
121 } |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
122 } |
342 | 123 |
124 if (islocal) | |
363
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
125 context = cl -> context; |
342 | 126 |
127 // first, look up symbol to see if it is already defined | |
128 for (se = as -> symtab.head; se; se = se -> next) | |
129 { | |
406 | 130 debug_message(as, 300, "Symbol add lookup: %p, %p", se, se -> next); |
342 | 131 if (!strcmp(sym, se -> symbol)) |
132 { | |
133 if (se -> context != context) | |
134 continue; | |
135 if ((flags & symbol_flag_set) && (se -> flags & symbol_flag_set)) | |
136 { | |
137 if (version < se -> version) | |
138 version = se -> version; | |
139 continue; | |
140 } | |
141 break; | |
142 } | |
143 } | |
389
fbb7bfed8076
Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents:
374
diff
changeset
|
144 |
342 | 145 if (se) |
146 { | |
147 // multiply defined symbol | |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
342
diff
changeset
|
148 lwasm_register_error(as, cl, "Multiply defined symbol (%s)", sym); |
342 | 149 return NULL; |
150 } | |
151 | |
152 if (flags & symbol_flag_set) | |
153 { | |
154 version++; | |
155 } | |
156 | |
363
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
157 // symplify the symbol expression - replaces "SET" symbols with |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
158 // symbol table entries |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
159 lwasm_reduce_expr(as, val); |
406 | 160 |
342 | 161 se = lw_alloc(sizeof(struct symtabe)); |
162 se -> context = context; | |
163 se -> version = version; | |
164 se -> flags = flags; | |
165 se -> value = lw_expr_copy(val); | |
370 | 166 se -> symbol = lw_strdup(sym); |
374 | 167 se -> section = cl -> csect; |
406 | 168 sprev = symbol_findprev(as, se); |
169 if (!sprev) | |
170 { | |
171 debug_message(as, 200, "Adding symbol at head of symbol table"); | |
172 se -> next = as -> symtab.head; | |
173 as -> symtab.head = se; | |
174 } | |
175 else | |
176 { | |
177 debug_message(as, 200, "Adding symbol in middle of symbol table"); | |
178 se -> next = sprev -> next; | |
179 sprev -> next = se; | |
180 } | |
342 | 181 return se; |
182 } | |
183 | |
363
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
184 // for "SET" symbols, always returns the LAST definition of the |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
185 // symbol. This works because the lwasm_reduce_expr() call in |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
186 // register_symbol will ensure there are no lingering "var" references |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
187 // to the set symbol anywhere in the symbol table; they will all be |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
188 // converted to direct references |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
189 // NOTE: this means that for a forward reference to a SET symbol, |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
190 // the LAST definition will be the one used. |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
191 // This arrangement also ensures that any reference to the symbol |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
192 // itself inside a "set" definition will refer to the previous version |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
193 // of the symbol. |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
194 struct symtabe * lookup_symbol(asmstate_t *as, line_t *cl, char *sym) |
342 | 195 { |
363
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
196 int local = 0; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
197 struct symtabe *s, *s2; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
198 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
199 // check if this is a local symbol |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
200 if (strchr(sym, '@') || strchr(sym, '?')) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
201 local = 1; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
202 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
203 if (cl && !CURPRAGMA(cl, PRAGMA_DOLLARNOTLOCAL) && strchr(sym, '$')) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
204 local = 1; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
205 if (!cl && !(as -> pragmas & PRAGMA_DOLLARNOTLOCAL) && strchr(sym, '$')) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
206 local = 1; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
207 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
208 // cannot look up local symbol in global context!!!!! |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
209 if (!cl && local) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
210 return NULL; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
211 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
212 for (s = as -> symtab.head, s2 = NULL; s; s = s -> next) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
213 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
214 if (!strcmp(sym, s -> symbol)) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
215 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
216 if (local && s -> context != cl -> context) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
217 continue; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
218 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
219 if (s -> flags & symbol_flag_set) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
220 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
221 // look for highest version of symbol |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
222 if (s -> version > s2 -> version) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
223 s2 = s; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
224 continue; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
225 } |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
226 break; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
227 } |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
228 } |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
229 if (!s && s2) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
230 s = s2; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
231 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
360
diff
changeset
|
232 return s; |
342 | 233 } |
390
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
234 |
405 | 235 struct listinfo |
236 { | |
237 sectiontab_t *sect; | |
238 asmstate_t *as; | |
239 int complex; | |
240 }; | |
241 | |
242 int list_symbols_test(lw_expr_t e, void *p) | |
243 { | |
244 struct listinfo *li = p; | |
245 | |
246 if (li -> complex) | |
247 return 0; | |
248 | |
249 if (lw_expr_istype(e, lw_expr_type_special)) | |
250 { | |
251 if (lw_expr_specint(e) == lwasm_expr_secbase) | |
252 { | |
253 if (li -> sect) | |
254 { | |
255 li -> complex = 1; | |
256 } | |
257 else | |
258 { | |
259 li -> sect = lw_expr_specptr(e); | |
260 } | |
261 } | |
262 } | |
263 return 0; | |
264 } | |
265 | |
390
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
266 void list_symbols(asmstate_t *as, FILE *of) |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
267 { |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
268 struct symtabe *s; |
405 | 269 lw_expr_t te; |
270 struct listinfo li; | |
271 | |
272 li.as = as; | |
273 | |
390
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
274 fprintf(of, "\nSymbol Table:\n"); |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
275 |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
276 for (s = as -> symtab.head; s; s = s -> next) |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
277 { |
405 | 278 lwasm_reduce_expr(as, s -> value); |
390
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
279 fputc('[', of); |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
280 if (s -> flags & symbol_flag_set) |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
281 fputc('S', of); |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
282 else |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
283 fputc(' ', of); |
405 | 284 if (as -> output_format == OUTPUT_OBJ) |
285 { | |
286 if (lw_expr_istype(s -> value, lw_expr_type_int)) | |
287 fputc('c', of); | |
288 else | |
289 fputc('s', of); | |
290 } | |
291 if (s -> context < 0) | |
390
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
292 fputc('G', of); |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
293 else |
405 | 294 fputc('L', of); |
295 | |
390
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
296 fputc(']', of); |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
297 fputc(' ', of); |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
298 fprintf(of, "%-32s ", s -> symbol); |
405 | 299 |
300 te = lw_expr_copy(s -> value); | |
301 li.complex = 0; | |
302 li.sect = NULL; | |
303 lw_expr_testterms(te, list_symbols_test, &li); | |
304 if (li.sect) | |
305 { | |
306 as -> exportcheck = 1; | |
307 as -> csect = li.sect; | |
308 lwasm_reduce_expr(as, te); | |
309 as -> exportcheck = 0; | |
310 } | |
311 | |
312 if (lw_expr_istype(te, lw_expr_type_int)) | |
313 { | |
314 fprintf(of, "%04X", lw_expr_intval(te)); | |
315 if (li.sect) | |
316 { | |
317 fprintf(of, " (%s)", li.sect -> name); | |
318 } | |
319 fprintf(of, "\n"); | |
320 } | |
390
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
321 else |
405 | 322 { |
323 fprintf(of, "<<incomplete>>\n"); | |
324 // fprintf(of, "%s\n", lw_expr_print(s -> value)); | |
325 } | |
326 lw_expr_destroy(te); | |
390
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
327 } |
027d7fbcdcfc
Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents:
389
diff
changeset
|
328 } |