Mercurial > hg-old > index.cgi
annotate src/pseudo.c @ 99:3dcb12a6f4ff
Fixed problem handling sections with options on pass 2
author | lost |
---|---|
date | Sat, 17 Jan 2009 07:28:45 +0000 |
parents | f3497072ac44 |
children | 26c058fa0bc1 |
rev | line source |
---|---|
0 | 1 /* |
4
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
2 pseudo.c |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
3 Copyright © 2009 William Astle |
4
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
4 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
5 This file is part of LWASM. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
6 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
7 LWASM is free software: you can redistribute it and/or modify it under the |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
8 terms of the GNU General Public License as published by the Free Software |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
9 Foundation, either version 3 of the License, or (at your option) any later |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
10 version. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
11 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
12 This program is distributed in the hope that it will be useful, but WITHOUT |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
15 more details. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
16 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
17 You should have received a copy of the GNU General Public License along with |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
18 this program. If not, see <http://www.gnu.org/licenses/>. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
19 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
20 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
21 This file implements the various pseudo operations. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
22 */ |
0 | 23 |
24 #include <stdlib.h> | |
50 | 25 #include <string.h> |
0 | 26 #include "lwasm.h" |
27 #include "instab.h" | |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
28 #include "expr.h" |
52 | 29 #include "util.h" |
0 | 30 |
52 | 31 extern int lwasm_read_file(asmstate_t *as, const char *filename); |
0 | 32 |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
33 OPFUNC(pseudo_org) |
0 | 34 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
35 int v, r; |
52 | 36 |
74 | 37 if (as -> csect) |
38 { | |
39 register_error(as, l, 1, "ORG not allowed within sections"); | |
40 return; | |
41 } | |
42 | |
52 | 43 if (as -> passnum != 1) |
44 { | |
45 // org is not needed to be processed on pass 2 | |
46 // this will prevent phasing errors for forward references that | |
47 // resolve on the second pass | |
48 // we saved the org address in l -> codeaddr on pass 1 | |
49 as -> addr = l -> codeaddr; | |
50 return; | |
51 } | |
0 | 52 |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
53 if (l -> sym) |
0 | 54 { |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
55 register_error(as, l, 1, "No symbol allowed with ORG"); |
0 | 56 } |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
57 |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
58 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
59 if (r != 0) |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
60 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
61 l -> codeaddr = v; |
49
21ae0fab469b
Added needed infra for useful listing of EQU and ORG type statements
lost
parents:
47
diff
changeset
|
62 l -> addrset = 1; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
63 as -> addr = v; |
0 | 64 } |
65 | |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
66 /* |
52 | 67 The operand for include is a string optionally enclosed in " |
68 */ | |
69 OPFUNC(pseudo_include) | |
0 | 70 { |
71 int v1; | |
52 | 72 char *fn; |
57 | 73 |
52 | 74 // only include files on pass 1 |
75 // but make sure local include context is right | |
76 // for the next line... | |
0 | 77 if (as -> passnum != 1) |
52 | 78 { |
57 | 79 as -> context = lwasm_next_context(as); |
0 | 80 return; |
52 | 81 } |
82 | |
83 while (**p && isspace(**p)) | |
84 (*p)++; | |
85 | |
86 if (!**p) | |
0 | 87 { |
52 | 88 register_error(as, l, 1, "Bad file name"); |
0 | 89 return; |
90 } | |
52 | 91 |
92 if (**p == '"') | |
93 { | |
94 // search for ending " | |
95 (*p)++; | |
96 for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++) | |
97 /* do nothing */ ; | |
98 if (*((*p)+v1) != '"') | |
99 { | |
100 register_error(as, l, 1, "Bad file name"); | |
101 return; | |
102 } | |
103 } | |
104 else | |
0 | 105 { |
52 | 106 // search for a space type character |
107 for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++) | |
108 ; | |
0 | 109 } |
52 | 110 |
111 fn = lwasm_alloc(v1 + 1); | |
112 memcpy(fn, *p, v1); | |
113 fn[v1] = '\0'; | |
114 | |
115 // end local label context on include | |
57 | 116 as -> context = lwasm_next_context(as); |
52 | 117 if (lwasm_read_file(as, fn) < 0) |
118 { | |
119 register_error(as, l, 1, "File include error (%s)", fn); | |
120 } | |
121 lwasm_free(fn); | |
0 | 122 } |
123 | |
50 | 124 OPFUNC(pseudo_rmb) |
0 | 125 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
126 int r, v; |
0 | 127 |
95 | 128 if (as -> passnum == 2) |
0 | 129 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
130 as -> addr += l -> nocodelen; |
0 | 131 return; |
132 } | |
94
83ba34ed11b3
Fixed problem with constant expressions evaluating to 0 when they shouldn't
lost
parents:
90
diff
changeset
|
133 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, -1); |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
134 if (r != 0) |
0 | 135 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
136 l -> nocodelen = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
137 as -> addr += v; |
0 | 138 } |
53 | 139 |
140 OPFUNC(pseudo_rmd) | |
0 | 141 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
142 int r, v; |
0 | 143 |
95 | 144 if (as -> passnum == 2) |
0 | 145 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
146 as -> addr += l -> nocodelen; |
0 | 147 return; |
148 } | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
149 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
150 if (r != 0) |
0 | 151 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
152 v *= 2; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
153 l -> nocodelen = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
154 as -> addr += v; |
0 | 155 } |
156 | |
53 | 157 OPFUNC(pseudo_rmq) |
0 | 158 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
159 int r, v; |
0 | 160 |
95 | 161 if (as -> passnum == 2) |
0 | 162 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
163 as -> addr += l -> nocodelen; |
0 | 164 return; |
165 } | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
166 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
167 if (r != 0) |
0 | 168 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
169 v *= 4; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
170 l -> nocodelen = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
171 as -> addr += v; |
0 | 172 } |
173 | |
53 | 174 OPFUNC(pseudo_zmb) |
0 | 175 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
176 int r, v; |
0 | 177 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
178 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
179 if (r != 0) |
0 | 180 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
181 while (v--) |
53 | 182 lwasm_emit(as, l, 0); |
0 | 183 } |
184 | |
53 | 185 OPFUNC(pseudo_zmd) |
0 | 186 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
187 int r, v; |
0 | 188 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
189 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
190 if (r != 0) |
0 | 191 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
192 v *= 2; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
193 while (v--) |
53 | 194 lwasm_emit(as, l, 0); |
0 | 195 } |
196 | |
53 | 197 OPFUNC(pseudo_zmq) |
198 { | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
199 int r, v; |
53 | 200 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
201 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
202 if (r != 0) |
53 | 203 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
204 v *= 4; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
205 while (v--) |
53 | 206 lwasm_emit(as, l, 0); |
207 } | |
208 | |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
209 OPFUNC(pseudo_end) |
0 | 210 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
211 int r, v; |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
212 lwasm_expr_stack_t *s; |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
213 |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
214 |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
215 as -> endseen = 1; |
0 | 216 |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
217 // address only matters for DECB output |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
218 if (as -> outformat != OUTPUT_DECB) |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
219 return; |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
220 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
221 r = lwasm_expr_result2(as, l, p, 0, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
222 if (r != 0) |
0 | 223 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
224 register_error(as, l, 2, "Bad operand"); |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
225 } |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
226 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
227 v = v & 0xffff; |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
228 if (as -> passnum == 2) |
0 | 229 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
230 as -> execaddr = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
231 l -> symaddr = v; |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
232 l -> addrset = 2; |
0 | 233 } |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
234 } |
0 | 235 |
56 | 236 |
237 OPFUNC(pseudo_align) | |
0 | 238 { |
239 int cn; | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
240 int r, v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
241 |
56 | 242 if (as -> passnum == 2) |
0 | 243 { |
56 | 244 while (as -> addr < l -> symaddr) |
245 lwasm_emit(as, l, 0); | |
246 return; | |
247 } | |
248 | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
249 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
250 if (r != 0) |
56 | 251 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
252 l -> symaddr = as -> addr; |
0 | 253 return; |
254 } | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
255 |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
256 if (v < 1) |
56 | 257 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
258 register_error(as, l, 1, "Illegal alignment %d", v); |
56 | 259 return; |
0 | 260 } |
56 | 261 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
262 cn = l -> codeaddr % v; |
56 | 263 if (cn) |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
264 cn = v - cn; |
56 | 265 |
266 while (cn--) | |
267 { | |
268 lwasm_emit(as, l, 0); | |
269 } | |
270 l -> symaddr = as -> addr; | |
0 | 271 } |
56 | 272 |
50 | 273 OPFUNC(pseudo_equ) |
0 | 274 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
275 int r, v; |
52 | 276 |
50 | 277 if (l -> sym == NULL) |
0 | 278 { |
50 | 279 register_error(as, l, 1, "No symbol specified"); |
0 | 280 return; |
281 } | |
50 | 282 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
283 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
284 if (r < 0) |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
285 v = 0; |
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:
57
diff
changeset
|
286 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
287 l -> symaddr = v & 0xFFFF; |
50 | 288 l -> addrset = 2; |
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:
57
diff
changeset
|
289 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
290 // note: we need to do this because the symbol might have resolved |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
291 // to a constant! |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
292 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE); |
0 | 293 } |
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:
57
diff
changeset
|
294 |
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:
57
diff
changeset
|
295 OPFUNC(pseudo_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:
57
diff
changeset
|
296 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
297 int r, v; |
64 | 298 |
299 // set MUST run on both passes as the symbol value changes! | |
300 | |
301 if (l -> sym == NULL) | |
302 { | |
303 register_error(as, l, 1, "No symbol specified"); | |
304 return; | |
305 } | |
306 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
307 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
308 if (r < 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
309 v = 0; |
64 | 310 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
311 l -> symaddr = v & 0xFFFF; |
64 | 312 l -> addrset = 2; |
313 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
314 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_SET); |
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:
57
diff
changeset
|
315 } |
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:
57
diff
changeset
|
316 |
65
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
317 OPFUNC(pseudo_setdp) |
0 | 318 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
319 int r, v; |
0 | 320 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
321 if (as -> outformat == OUTPUT_OBJ) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
322 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
323 register_error(as, l, 1, "SETDP not permitted with OBJ target"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
324 return; |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
325 } |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
326 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
327 // setdp is needed on both passes; must resolve to a constant on pass 1 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
328 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
329 if (r != 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
330 return; |
65
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
331 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
332 if (v < -127 || v > 255) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
333 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
334 register_error(as, l, 1, "Byte overflow"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
335 return; |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
336 } |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
337 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
338 l -> symaddr = v & 0xFF; |
65
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
339 l -> addrset = 2; |
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
340 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
341 as -> dpval = v & 0xFF; |
0 | 342 } |
343 | |
56 | 344 OPFUNC(pseudo_fcc) |
345 { | |
0 | 346 int delim = 0; |
347 | |
56 | 348 delim = **p; |
0 | 349 if (!delim) |
350 { | |
56 | 351 register_error(as, l, 1, "Bad operand"); |
352 return; | |
0 | 353 } |
56 | 354 *p += 1; |
355 while (**p && **p != delim) | |
0 | 356 { |
56 | 357 lwasm_emit(as, l, **p); |
358 (*p)++; | |
0 | 359 } |
56 | 360 if (**p) |
361 (*p)++; | |
0 | 362 } |
363 | |
56 | 364 |
365 OPFUNC(pseudo_fcs) | |
0 | 366 { |
367 int delim = 0; | |
56 | 368 |
369 delim = **p; | |
0 | 370 if (!delim) |
371 { | |
56 | 372 register_error(as, l, 1, "Bad operand"); |
373 return; | |
0 | 374 } |
56 | 375 *p += 1; |
376 while (**p && **p != delim) | |
0 | 377 { |
56 | 378 if (!*((*p) + 1) || *((*p) + 1) == delim) |
379 lwasm_emit(as, l, **p | 0x80); | |
380 else | |
381 lwasm_emit(as, l, **p); | |
382 (*p)++; | |
0 | 383 } |
56 | 384 if (**p) |
385 (*p)++; | |
0 | 386 } |
387 | |
56 | 388 OPFUNC(pseudo_fcn) |
0 | 389 { |
390 int delim = 0; | |
391 | |
56 | 392 delim = **p; |
0 | 393 if (!delim) |
394 { | |
56 | 395 register_error(as, l, 1, "Bad operand"); |
396 return; | |
0 | 397 } |
56 | 398 *p += 1; |
399 while (**p && **p != delim) | |
0 | 400 { |
56 | 401 lwasm_emit(as, l, **p); |
402 (*p)++; | |
0 | 403 } |
56 | 404 if (**p) |
405 (*p)++; | |
406 lwasm_emit(as, l, 0); | |
0 | 407 } |
56 | 408 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
409 // FIXME: handle external, etc., references in a useful manner |
56 | 410 OPFUNC(pseudo_fcb) |
0 | 411 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
412 int r, v; |
0 | 413 |
414 fcb_again: | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
415 r = lwasm_expr_result2(as, l, p, 0, &v, -1); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
416 if (r < 0) |
56 | 417 return; |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
418 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
419 if (r > 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
420 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
421 register_error(as, l, 2, "Illegal external or inter-segment reference"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
422 v = 0; |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
423 } |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
424 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
425 if (v < -127 || v > 255) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
426 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
427 register_error(as, l, 1, "Byte overflow"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
428 } |
56 | 429 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
430 lwasm_emit(as, l, v); |
56 | 431 if (**p == ',') |
0 | 432 { |
56 | 433 (*p)++; |
0 | 434 goto fcb_again; |
435 } | |
436 } | |
437 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
438 // FIXME: handle external references in an intelligent way |
56 | 439 OPFUNC(pseudo_fdb) |
0 | 440 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
441 int r, v; |
0 | 442 |
443 fdb_again: | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
444 r = lwasm_expr_result2(as, l, p, 0, &v, -1); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
445 if (r < 0) |
56 | 446 return; |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
447 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
448 if (r > 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
449 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
450 register_error(as, l, 2, "Illegal external or inter-segment reference"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
451 v = 0; |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
452 } |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
453 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
454 lwasm_emit(as, l, v >> 8); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
455 lwasm_emit(as, l, v & 0xff); |
56 | 456 if (**p == ',') |
0 | 457 { |
56 | 458 (*p)++; |
0 | 459 goto fdb_again; |
460 } | |
461 } | |
462 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
463 // FIXME: handle external references in a sensible way |
56 | 464 OPFUNC(pseudo_fqb) |
0 | 465 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
466 int r, v; |
56 | 467 |
0 | 468 fqb_again: |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
469 r = lwasm_expr_result2(as, l, p, 0, &v, -1); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
470 if (r < 0) |
56 | 471 return; |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
472 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
473 if (r > 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
474 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
475 register_error(as, l, 2, "Illegal external or inter-segment reference"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
476 v = 0; |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
477 } |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
478 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
479 lwasm_emit(as, l, v >> 24); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
480 lwasm_emit(as, l, v >> 16); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
481 lwasm_emit(as, l, v >> 8); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
482 lwasm_emit(as, l, v & 0xff); |
56 | 483 if (**p == ',') |
0 | 484 { |
56 | 485 (*p)++; |
0 | 486 goto fqb_again; |
487 } | |
488 } | |
489 | |
490 // don't need to do anything if we are executing one of these | |
57 | 491 OPFUNC(pseudo_endc) |
0 | 492 { |
57 | 493 if (as -> skipcond && !(as -> skipmacro)) |
494 { | |
495 as -> skipcount -= 1; | |
496 if (as -> skipcount <= 0) | |
497 { | |
498 as -> skipcond = 0; | |
499 } | |
500 } | |
0 | 501 return; |
502 } | |
503 | |
504 // if "else" executes, we must be going into an "ignore" state | |
57 | 505 OPFUNC(pseudo_else) |
0 | 506 { |
57 | 507 if (as -> skipmacro) |
508 return; | |
509 | |
510 if (as -> skipcond) | |
511 { | |
512 if (as -> skipcount == 1) | |
513 { | |
514 as -> skipcount = 0; | |
515 as -> skipcond = 0; | |
516 } | |
517 return; | |
518 } | |
519 | |
0 | 520 as -> skipcond = 1; |
521 as -> skipcount = 1; | |
522 } | |
523 | |
57 | 524 OPFUNC(pseudo_ifne) |
0 | 525 { |
526 int v1; | |
527 int rval; | |
57 | 528 |
529 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 530 { |
57 | 531 as -> skipcount++; |
532 return; | |
533 } | |
534 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
535 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
536 if (rval != 0) |
57 | 537 return; |
538 if (!v1) | |
539 { | |
540 as -> skipcond = 1; | |
541 as -> skipcount = 1; | |
0 | 542 } |
543 } | |
57 | 544 |
545 OPFUNC(pseudo_ifeq) | |
0 | 546 { |
547 int v1; | |
548 int rval; | |
57 | 549 |
550 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 551 { |
57 | 552 as -> skipcount++; |
553 return; | |
0 | 554 } |
57 | 555 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
556 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
557 if (rval != 0) |
57 | 558 return; |
559 if (v1) | |
0 | 560 { |
57 | 561 as -> skipcond = 1; |
562 as -> skipcount = 1; | |
0 | 563 } |
564 } | |
57 | 565 |
566 OPFUNC(pseudo_iflt) | |
0 | 567 { |
568 int v1; | |
569 int rval; | |
57 | 570 |
571 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 572 { |
57 | 573 as -> skipcount++; |
574 return; | |
0 | 575 } |
57 | 576 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
577 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
578 if (rval != 0) |
57 | 579 return; |
580 if (v1 >= 0) | |
0 | 581 { |
57 | 582 as -> skipcond = 1; |
583 as -> skipcount = 1; | |
0 | 584 } |
585 } | |
57 | 586 |
587 OPFUNC(pseudo_ifle) | |
0 | 588 { |
589 int v1; | |
590 int rval; | |
57 | 591 |
592 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 593 { |
57 | 594 as -> skipcount++; |
595 return; | |
0 | 596 } |
57 | 597 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
598 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
599 if (rval != 0) |
57 | 600 return; |
601 if (v1 > 0) | |
0 | 602 { |
57 | 603 as -> skipcond = 1; |
604 as -> skipcount = 1; | |
0 | 605 } |
606 } | |
57 | 607 |
608 OPFUNC(pseudo_ifgt) | |
0 | 609 { |
610 int v1; | |
611 int rval; | |
57 | 612 |
613 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 614 { |
57 | 615 as -> skipcount++; |
616 return; | |
0 | 617 } |
57 | 618 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
619 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
620 if (rval != 0) |
57 | 621 return; |
622 if (v1 <= 0) | |
0 | 623 { |
57 | 624 as -> skipcond = 1; |
625 as -> skipcount = 1; | |
0 | 626 } |
627 } | |
57 | 628 |
629 OPFUNC(pseudo_ifge) | |
0 | 630 { |
631 int v1; | |
632 int rval; | |
57 | 633 |
634 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 635 { |
57 | 636 as -> skipcount++; |
637 return; | |
0 | 638 } |
57 | 639 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
640 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
641 if (rval != 0) |
57 | 642 return; |
643 if (v1 < 0) | |
0 | 644 { |
57 | 645 as -> skipcond = 1; |
646 as -> skipcount = 1; | |
0 | 647 } |
648 } | |
649 | |
56 | 650 OPFUNC(pseudo_error) |
0 | 651 { |
56 | 652 register_error(as, l, 1, "User error: %s", *p); |
0 | 653 } |
56 | 654 |
74 | 655 |
656 OPFUNC(pseudo_section) | |
657 { | |
658 sectiontab_t *s; | |
659 char *p2; | |
660 char *sn; | |
661 char *opts; | |
662 | |
99 | 663 |
74 | 664 if (as -> outformat != OUTPUT_OBJ) |
665 { | |
666 register_error(as, l, 1, "Sections only supported for obj target"); | |
667 return; | |
668 } | |
669 | |
670 if (as -> csect) | |
671 { | |
672 as -> csect -> offset = as -> addr; | |
673 as -> csect = NULL; | |
674 } | |
675 | |
676 if (!**p) | |
677 { | |
678 register_error(as, l, 1, "Need section name"); | |
679 return; | |
680 } | |
681 | |
682 for (p2 = *p; *p2 && !isspace(*p2); p2++) | |
683 /* do nothing */ ; | |
684 | |
685 sn = lwasm_alloc(p2 - *p + 1); | |
686 memcpy(sn, *p, p2 - *p); | |
687 sn[p2 - *p] = '\0'; | |
688 | |
689 *p = p2; | |
690 | |
691 opts = strchr(sn, ','); | |
692 if (opts) | |
693 { | |
694 *opts++ = '\0'; | |
695 } | |
696 | |
697 // have we seen the section name already? | |
698 for (s = as -> sections; s; s = s -> next) | |
699 { | |
700 if (!strcmp(s -> name, sn)) | |
701 break; | |
702 } | |
703 | |
99 | 704 if (s && as -> passnum == 1) |
74 | 705 { |
706 lwasm_free(sn); | |
707 if (opts) | |
708 { | |
709 register_error(as, l, 1, "Section options can only be specified the first time"); | |
710 return; | |
711 } | |
712 } | |
713 else if (!s) | |
714 { | |
715 s = lwasm_alloc(sizeof(sectiontab_t)); | |
716 s -> name = sn; | |
717 s -> offset = 0; | |
718 s -> flags = 0; | |
85 | 719 s -> obytes = NULL; |
720 s -> oblen = 0; | |
721 s -> obsize = 0; | |
86 | 722 s -> rl = NULL; |
90 | 723 s -> exports = NULL; |
74 | 724 // parse options; only one "bss" |
725 if (opts && as -> passnum == 1) | |
726 { | |
727 if (!strcasecmp(opts, "bss")) | |
728 { | |
729 s -> flags = SECTION_BSS; | |
730 } | |
731 else | |
732 { | |
733 register_error(as, l, 1, "Unrecognized section option '%s'", opts); | |
734 lwasm_free(s -> name); | |
735 lwasm_free(s); | |
736 return; | |
737 } | |
738 } | |
739 | |
740 s -> next = as -> sections; | |
741 as -> sections = s; | |
742 } | |
743 as -> addr = s -> offset; | |
744 as -> csect = s; | |
745 as -> context = lwasm_next_context(as); | |
746 } | |
747 | |
748 OPFUNC(pseudo_endsection) | |
749 { | |
750 if (as -> outformat != OUTPUT_OBJ) | |
751 { | |
752 register_error(as, l, 1, "Sections only supported for obj target"); | |
753 return; | |
754 } | |
755 | |
756 if (!(as -> csect)) | |
757 { | |
758 register_error(as, l, 1, "ENDSECTION when not in a section"); | |
759 return; | |
760 } | |
761 | |
762 as -> csect -> offset = as -> addr; | |
763 as -> addr = 0; | |
764 as -> csect = 0; | |
765 as -> context = lwasm_next_context(as); | |
766 } | |
82 | 767 |
768 OPFUNC(pseudo_extern) | |
769 { | |
770 if (as -> passnum != 1) | |
771 return; | |
772 | |
773 if (as -> outformat != OUTPUT_OBJ) | |
774 { | |
775 register_error(as, l, 1, "External references only supported for obj target"); | |
776 return; | |
777 } | |
778 | |
779 if (as -> csect) | |
780 { | |
781 register_error(as, l, 1, "Cannot declare external symbols within a section"); | |
782 return; | |
783 } | |
784 | |
785 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN); | |
786 } | |
90 | 787 |
788 OPFUNC(pseudo_export) | |
789 { | |
790 lwasm_symbol_ent_t *se; | |
791 export_list_t *ex; | |
792 | |
793 if (as -> outformat != OUTPUT_OBJ) | |
794 { | |
795 register_error(as, l, 1, "Symbol exports only supported for obj target"); | |
796 return; | |
797 } | |
798 | |
799 if (as -> passnum == 1) | |
800 return; | |
801 | |
802 // the symbol better be defined at this point (pass 2) | |
803 // local symbols cannot be exported nor can "global" symbols | |
804 se = lwasm_find_symbol(as, l -> sym, -1); | |
805 if (!se) | |
806 { | |
807 register_error(as, l, 2, "Exported symbols must be fully defined within a section"); | |
808 return; | |
809 } | |
810 if (se -> sect == NULL) | |
811 { | |
812 register_error(as, l, 2, "Only non-local symbols within a section can be exported"); | |
813 return; | |
814 } | |
815 | |
816 if (se -> flags & SYMBOL_SET) | |
817 { | |
818 register_error(as, l, 2, "You cannot export symbols defined with SET"); | |
819 return; | |
820 } | |
821 | |
822 // if the symbol is not already a simple value, re-evaluate it | |
823 // and see if it becomes simple | |
824 | |
825 | |
826 if (se -> flags & SYMBOL_COMPLEX) | |
827 { | |
828 register_error(as, l, 2, "Exported symbols must be fully resolved on pass 2"); | |
829 return; | |
830 } | |
831 | |
832 // search for existing export | |
833 for (ex = se -> sect -> exports; ex; ex = ex -> next) | |
834 if (!strcmp(l -> sym, ex -> sym)) | |
835 break; | |
836 if (ex) | |
837 { | |
838 register_error(as, l, 2, "Symbol %s already exported", l -> sym); | |
839 return; | |
840 } | |
841 | |
842 // add an external reference | |
843 ex = lwasm_alloc(sizeof(export_list_t)); | |
844 ex -> next = se -> sect -> exports; | |
845 se -> sect -> exports = ex; | |
846 ex -> offset = se -> value; | |
847 ex -> sym = lwasm_strdup(se -> sym); | |
848 } |