annotate lwasm/symbol.c @ 232:1009f302ac11

Documented the "Flags" term for object files
author lost
date Fri, 12 Jun 2009 04:17:22 +0000
parents bae1e3ecdce1
children a58f49a77441
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__
212
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 193
diff changeset
26 #include <config.h>
37
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 */
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 75
diff changeset
38
a338d496350e Checkpointing conversion to allow object target
lost
parents: 75
diff changeset
39 /*
a338d496350e Checkpointing conversion to allow object target
lost
parents: 75
diff changeset
40 NOTE: complex symbols always take their value from slot 0 on the expression placeholders
a338d496350e Checkpointing conversion to allow object target
lost
parents: 75
diff changeset
41 for a line!
a338d496350e Checkpointing conversion to allow object target
lost
parents: 75
diff changeset
42 */
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
43 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
44 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
45 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
46 char *p;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
47
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
48 int scontext = -1;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
49
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
50 // 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
51 if (flags & SYMBOL_COMPLEX)
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
52 {
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 75
diff changeset
53 if (l -> exprs[0] == NULL)
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
54 {
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 75
diff changeset
55 val = l -> exprvals[0];
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
56 flags &= ~SYMBOL_COMPLEX;
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
57 }
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
58 }
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
59
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
60 // 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
61 // 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
62 // [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
63 // 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
64 // symbols must start with [a-zA-Z._]
193
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
65 if (!strchr(sym, '$'))
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
66 {
193
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
67 if (!strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._@?", *sym))
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
68 {
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
69 register_error(as, l, 1, "Bad symbol: %s", sym);
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
70 return -1;
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
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
193
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
73 if (*sym == '@' && isdigit(sym[1]))
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
74 {
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
75 register_error(as, l, 1, "Bad symbol: %s", sym);
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
76 return -1;
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
77 }
40
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
78 }
d2cee0c335e7 adjusted symbol rules to accept symbols starting with @ but not @<digit>
lost
parents: 37
diff changeset
79
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
80 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
81 {
52
b9856da2674a Added file inclusion
lost
parents: 40
diff changeset
82 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
83 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
84 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
85 return -1;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
86 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
87 // flag local symbols while we're at it...
193
716879fc6790 Allow $ to be a local symbol and allow symbols with $ to start with a digit
lost
parents: 190
diff changeset
88 if (*p == '?' || *p == '@' || *p == '$')
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
89 scontext = as -> context;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
90 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
91
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
92 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
93
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
94 // 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
95 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
96 if (se)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
97 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
98 if (flags & SYMBOL_FORCE && as -> passnum != 2)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
99 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
100 register_error(as, l, 1, "Multiply defined symbol: %s", sym);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
101 return -1;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
102 }
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
103 if (!(flags & SYMBOL_SET) || (flags & SYMBOL_SET && !(se -> flags & SYMBOL_SET)))
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
104 {
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
105 register_error(as, l, 1, "Mulitply defined symbol: %s", sym);
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
106 return -1;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
107 }
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
108 }
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
109 if (se)
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
110 {
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
111 se -> value = val;
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
112 if (flags & SYMBOL_COMPLEX)
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
113 {
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 75
diff changeset
114 se -> expr = l -> exprs[0];
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
115 }
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
116 else
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
117 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
118 se -> expr = NULL;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
119 }
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
120 return;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
121 }
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
122
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
123 // 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
124 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
125 if (as -> symhead)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
126 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
127 se -> prev = NULL;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
128 se -> next = as -> symhead;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
129 as -> symhead -> prev = se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
130 as -> symhead = se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
131 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
132 else
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 se -> next = NULL;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
135 se -> prev = NULL;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
136 as -> symhead = se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
137 as -> symtail = se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
138 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
139 se -> value = val;
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
140 if (flags & SYMBOL_COMPLEX)
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 75
diff changeset
141 se -> expr = l -> exprs[0];
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
142 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
143 se -> context = scontext;
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
144
190
563adfccb645 Added 'sym=expr' opcode handling
lost
parents: 151
diff changeset
145 if (!(flags & SYMBOL_EXTERN) && ((flags & SYMBOL_COMPLEX) || !(flags & SYMBOL_GLOBAL)))
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
146 se -> sect = as -> csect;
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
147 else
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
148 se -> sect = NULL;
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
149
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
150 se -> expr = NULL;
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
151 se -> flags = flags;
82
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
152 se -> externalname = NULL;
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
153
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
154 return 0;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
155 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
156
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
157 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
158 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
159 lwasm_symbol_ent_t *se;
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
160 static int st = 0;
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
161
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
162 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
163 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
164 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
165 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
166 return se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
167 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
168 }
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
169 if (as -> passnum == 2 && st == 0 && scontext == -1 && as -> outformat == OUTPUT_OBJ && as -> pragmas & PRAGMA_UNDEFEXTERN)
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
170 {
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
171 // we want undefined symbols to be considered external
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
172 // we didn't find it on a lookup so register it as external
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
173 // but we only do so when looking up in global context
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
174 st = 1;
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
175 if (lwasm_register_symbol(as, NULL, sym, 0, SYMBOL_EXTERN))
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
176 {
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
177 st = 0;
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
178 return NULL;
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
179 }
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
180 st = 0;
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
181
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
182 // find the newly registered symbol and return it
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
183 for (se = as -> symhead; se; se = se -> next)
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
184 {
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
185 if (scontext == se -> context && !strcmp(sym, se -> sym))
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
186 {
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
187 return se;
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
188 }
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
189 }
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
190 }
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 92
diff changeset
191
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
192 return NULL;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
193 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
194
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
195 // 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
196 // 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
197 // 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
198 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
199 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
200 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
201
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
202 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
203 if (!se)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
204 return -1;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
205
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
206 se -> value = val;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
207 return 0;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
diff changeset
208 }
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
209
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
210 void lwasm_list_symbols(asmstate_t *as, FILE *lf)
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
211 {
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
212 lwasm_symbol_ent_t *se;
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
213
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
214 for (se = as -> symhead; se; se = se -> next)
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
215 {
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
216 if (se -> expr)
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
217 {
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
218 fprintf(lf, "<incompl>");
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
219 }
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
220 else if (se -> value > 0xffff || se -> value < -0x8000)
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
221 {
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
222 fprintf(lf, "%08X ", se -> value);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
223 }
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
224 else
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
225 {
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
226 fprintf(lf, " %04X ", se -> value);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
227 }
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
228 if (se -> context < 0)
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
229 fputc('G', lf);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
230 else
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
231 fputc('L', lf);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
232
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
233 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
234 fputc('S', lf);
92
ea2cfebef5d0 Make external symbols remain unresolved in expressions and also flag them in the symbol list
lost
parents: 82
diff changeset
235 else if (se -> flags & SYMBOL_EXTERN)
ea2cfebef5d0 Make external symbols remain unresolved in expressions and also flag them in the symbol list
lost
parents: 82
diff changeset
236 fputc('E', lf);
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
237 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
238 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
239
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
240 fprintf(lf, " %s", se -> sym);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
241
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
242 if (se -> context >= 0)
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
243 fprintf(lf, " (%d)", se -> context);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
244
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
245 if (se -> sect)
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
246 {
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
247 fprintf(lf, " [%s]", se -> sect -> name);
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
248 }
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 64
diff changeset
249
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
250 fputc('\n', lf);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
251 }
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 52
diff changeset
252 }