annotate src/symbol.c @ 75:92eb93bffa28

Rejigged symbol system to be able to handle non-constant references
author lost
date Thu, 08 Jan 2009 01:32:49 +0000
parents aaddd47219b4
children a338d496350e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
1 /*
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
2 symbol.c
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
4
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
5 This file is part of LWASM.
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
6
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
10 version.
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
11
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
15 more details.
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
16
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
19 */
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
20
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
21 /*
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
22 for handling the symbol table
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
23 */
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
24
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
25 #define __symbol_c_seen__
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
26
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
27 #include <string.h>
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
28
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
29 #include "lwasm.h"
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
30 #include "util.h"
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
31 #include "expr.h"
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
32
40
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
33 /*
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
34 Note that this function may accept symbols that the expression evaluator doesn't
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
35 recognize because the expression evaluator must avoid all ambiguity in order
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
36 to achieve predictable results. The checks here are simply a fuzz check.
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
37 */
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
38 int lwasm_register_symbol(asmstate_t *as, lwasm_line_t *l, char *sym, int val, int flags)
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
39 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
40 lwasm_symbol_ent_t *se, *se2;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
41 char *p;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
42
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
43 int scontext = -1;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
44
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
45 // if the symbol is constant, fall back to simple registration!
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
46 if (flags & SYMBOL_COMPLEX)
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
47 {
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
48 if (lwasm_expr_is_constant(l -> expr))
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
49 {
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
50 val = lwasm_expr_get_value(l -> expr);
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
51 flags &= ~SYMBOL_COMPLEX;
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
52 }
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
53 }
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
54
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
55 // first check if the symbol is valid
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
56 // the following characters are allowed in a symbol:
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
57 // [a-zA-Z0-9._$?@] and any byte value larger than 0x7F
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
58 // although symbols should be restricted to the 7 bit range
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
59 // symbols must start with [a-zA-Z._]
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
60 if (!strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._@?", *sym))
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
61 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
62 register_error(as, l, 1, "Bad symbol: %s", sym);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
63 return -1;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
64 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
65
40
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
66 if (*sym == '@' && isdigit(sym[1]))
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
67 {
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
68 register_error(as, l, 1, "Bad symbol: %s", sym);
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
69 return -1;
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
70 }
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
71
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
72 for (p = sym; *p; p++)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
73 {
52
b9856da2674a Added file inclusion
lost
parents: 40
diff changeset
74 if (!strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._$?@0123456789", *sym))
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
75 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
76 register_error(as, l, 1, "Bad symbol: %s", sym);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
77 return -1;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
78 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
79 // flag local symbols while we're at it...
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
80 if (*p == '?' || *p == '@')
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
81 scontext = as -> context;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
82 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
83
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
84 debug_message(3, "lwasm_register_symbol(): registering '%s' (%d) at %04X; flags=%d", sym, scontext, val, flags);
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
85
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
86 // now look it for to see if it is a duplicate
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
87 se = lwasm_find_symbol(as, sym, scontext);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
88 if (se)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
89 {
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
90 if (!(flags & SYMBOL_SET) || (flags & SYMBOL_SET && !(se -> flags & SYMBOL_SET)))
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
91 {
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
92 register_error(as, l, 1, "Mulitply defined symbol: %s", sym);
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
93 return -1;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
94 }
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
95 }
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
96 if (se)
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
97 {
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
98 se -> value = val;
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
99 if (flags & SYMBOL_COMPLEX)
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
100 {
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
101 se -> expr = l -> expr;
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
102 }
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
103 return;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
104 }
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
105
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
106 // if not a duplicate, register it with the value
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
107 se = lwasm_alloc(sizeof(lwasm_symbol_ent_t));
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
108 if (as -> symhead)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
109 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
110 se -> prev = NULL;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
111 se -> next = as -> symhead;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
112 as -> symhead -> prev = se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
113 as -> symhead = se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
114 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
115 else
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
116 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
117 se -> next = NULL;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
118 se -> prev = NULL;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
119 as -> symhead = se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
120 as -> symtail = se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
121 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
122 se -> value = val;
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
123 if (flags & SYMBOL_COMPLEX)
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
124 se -> expr = l -> expr;
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
125 se -> sym = lwasm_strdup(sym);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
126 se -> context = scontext;
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
127 se -> sect = as -> csect;
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
128 se -> expr = NULL;
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
129 se -> flags = flags;
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
130
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
131 return 0;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
132 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
133
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
134 lwasm_symbol_ent_t *lwasm_find_symbol(asmstate_t *as, char *sym, int scontext)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
135 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
136 lwasm_symbol_ent_t *se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
137
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
138 for (se = as -> symhead; se; se = se -> next)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
139 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
140 if (scontext == se -> context && !strcmp(sym, se -> sym))
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
141 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
142 return se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
143 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
144 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
145 return NULL;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
146 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
147
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
148 // reset the value of a symbol - should not be used normally
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
149 // it is intended for use by such operations as EQU
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
150 // returns -1 if the symbol is not registered
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
151 int lwasm_set_symbol(asmstate_t *as, char *sym, int scontext, int val)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
152 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
153 lwasm_symbol_ent_t *se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
154
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
155 se = lwasm_find_symbol(as, sym, scontext);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
156 if (!se)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
157 return -1;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
158
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
159 se -> value = val;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
160 return 0;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
161 }
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
162
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
163 void lwasm_list_symbols(asmstate_t *as, FILE *lf)
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
164 {
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
165 lwasm_symbol_ent_t *se;
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
166
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
167 for (se = as -> symhead; se; se = se -> next)
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
168 {
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
169 if (se -> expr)
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
170 {
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
171 fprintf(lf, "<incompl>");
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
172 }
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
173 else if (se -> value > 0xffff || se -> value < -0x8000)
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
174 {
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
175 fprintf(lf, "%08X ", se -> value);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
176 }
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
177 else
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
178 {
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
179 fprintf(lf, " %04X ", se -> value);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
180 }
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
181 if (se -> context < 0)
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
182 fputc('G', lf);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
183 else
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
184 fputc('L', lf);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
185
63
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 58
diff changeset
186 if (se -> flags & SYMBOL_SET)
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 58
diff changeset
187 fputc('S', lf);
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 58
diff changeset
188 else
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 58
diff changeset
189 fputc(' ', lf);
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 58
diff changeset
190
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
191 fprintf(lf, " %s", se -> sym);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
192
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
193 if (se -> context >= 0)
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
194 fprintf(lf, " (%d)", se -> context);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
195
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
196 if (se -> sect)
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
197 {
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
198 fprintf(lf, " [%s]", se -> sect -> name);
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
199 }
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
200
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
201 fputc('\n', lf);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
202 }
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
203 }