Mercurial > hg-old > index.cgi
annotate src/pseudo.c @ 103:26c058fa0bc1
Fixed up some issues with pseudo ops and object target
author | lost |
---|---|
date | Fri, 23 Jan 2009 05:48:55 +0000 |
parents | 3dcb12a6f4ff |
children | 2ba8f9ef1417 |
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 } | |
103 | 133 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | 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 } | |
103 | 149 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0); |
78
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 } | |
103 | 166 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0); |
78
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 |
103 | 178 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0); |
78
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 |
103 | 189 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0); |
78
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 |
103 | 201 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0); |
78
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 | |
103 | 249 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0); |
78
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 |
103 | 283 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0); |
78
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 | |
103 | 307 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0); |
79
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 |
103 | 328 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0); |
79
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; |
103 | 442 int extseen = 0; |
443 char *p1; | |
0 | 444 |
445 fdb_again: | |
103 | 446 p1 = *p; |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
447 r = lwasm_expr_result2(as, l, p, 0, &v, -1); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
448 if (r < 0) |
56 | 449 return; |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
450 |
103 | 451 if (r > 0 && extseen == 1) |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
452 { |
103 | 453 register_error(as, l, 2, "Illegal external or inter-segment reference (only 1 per FDB line)"); |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
454 v = 0; |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
455 } |
103 | 456 else if (r > 0) |
457 { | |
458 l -> relocoff = as -> addr - l -> codeaddr; | |
459 *p = p1; | |
460 r = lwasm_expr_result2(as, l, p, 0, &v, 0); | |
461 } | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
462 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
463 lwasm_emit(as, l, v >> 8); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
464 lwasm_emit(as, l, v & 0xff); |
56 | 465 if (**p == ',') |
0 | 466 { |
56 | 467 (*p)++; |
0 | 468 goto fdb_again; |
469 } | |
470 } | |
471 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
472 // FIXME: handle external references in a sensible way |
56 | 473 OPFUNC(pseudo_fqb) |
0 | 474 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
475 int r, v; |
56 | 476 |
0 | 477 fqb_again: |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
478 r = lwasm_expr_result2(as, l, p, 0, &v, -1); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
479 if (r < 0) |
56 | 480 return; |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
481 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
482 if (r > 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
483 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
484 register_error(as, l, 2, "Illegal external or inter-segment reference"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
485 v = 0; |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
486 } |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
487 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
488 lwasm_emit(as, l, v >> 24); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
489 lwasm_emit(as, l, v >> 16); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
490 lwasm_emit(as, l, v >> 8); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
491 lwasm_emit(as, l, v & 0xff); |
56 | 492 if (**p == ',') |
0 | 493 { |
56 | 494 (*p)++; |
0 | 495 goto fqb_again; |
496 } | |
497 } | |
498 | |
499 // don't need to do anything if we are executing one of these | |
57 | 500 OPFUNC(pseudo_endc) |
0 | 501 { |
57 | 502 if (as -> skipcond && !(as -> skipmacro)) |
503 { | |
504 as -> skipcount -= 1; | |
505 if (as -> skipcount <= 0) | |
506 { | |
507 as -> skipcond = 0; | |
508 } | |
509 } | |
0 | 510 return; |
511 } | |
512 | |
513 // if "else" executes, we must be going into an "ignore" state | |
57 | 514 OPFUNC(pseudo_else) |
0 | 515 { |
57 | 516 if (as -> skipmacro) |
517 return; | |
518 | |
519 if (as -> skipcond) | |
520 { | |
521 if (as -> skipcount == 1) | |
522 { | |
523 as -> skipcount = 0; | |
524 as -> skipcond = 0; | |
525 } | |
526 return; | |
527 } | |
528 | |
0 | 529 as -> skipcond = 1; |
530 as -> skipcount = 1; | |
531 } | |
532 | |
57 | 533 OPFUNC(pseudo_ifne) |
0 | 534 { |
535 int v1; | |
536 int rval; | |
57 | 537 |
538 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 539 { |
57 | 540 as -> skipcount++; |
541 return; | |
542 } | |
543 | |
103 | 544 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0); |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
545 if (rval != 0) |
57 | 546 return; |
547 if (!v1) | |
548 { | |
549 as -> skipcond = 1; | |
550 as -> skipcount = 1; | |
0 | 551 } |
552 } | |
57 | 553 |
554 OPFUNC(pseudo_ifeq) | |
0 | 555 { |
556 int v1; | |
557 int rval; | |
57 | 558 |
559 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 560 { |
57 | 561 as -> skipcount++; |
562 return; | |
0 | 563 } |
57 | 564 |
103 | 565 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0); |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
566 if (rval != 0) |
57 | 567 return; |
568 if (v1) | |
0 | 569 { |
57 | 570 as -> skipcond = 1; |
571 as -> skipcount = 1; | |
0 | 572 } |
573 } | |
57 | 574 |
575 OPFUNC(pseudo_iflt) | |
0 | 576 { |
577 int v1; | |
578 int rval; | |
57 | 579 |
580 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 581 { |
57 | 582 as -> skipcount++; |
583 return; | |
0 | 584 } |
57 | 585 |
103 | 586 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0); |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
587 if (rval != 0) |
57 | 588 return; |
589 if (v1 >= 0) | |
0 | 590 { |
57 | 591 as -> skipcond = 1; |
592 as -> skipcount = 1; | |
0 | 593 } |
594 } | |
57 | 595 |
596 OPFUNC(pseudo_ifle) | |
0 | 597 { |
598 int v1; | |
599 int rval; | |
57 | 600 |
601 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 602 { |
57 | 603 as -> skipcount++; |
604 return; | |
0 | 605 } |
57 | 606 |
103 | 607 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0); |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
608 if (rval != 0) |
57 | 609 return; |
610 if (v1 > 0) | |
0 | 611 { |
57 | 612 as -> skipcond = 1; |
613 as -> skipcount = 1; | |
0 | 614 } |
615 } | |
57 | 616 |
617 OPFUNC(pseudo_ifgt) | |
0 | 618 { |
619 int v1; | |
620 int rval; | |
57 | 621 |
622 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 623 { |
57 | 624 as -> skipcount++; |
625 return; | |
0 | 626 } |
57 | 627 |
103 | 628 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0); |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
629 if (rval != 0) |
57 | 630 return; |
631 if (v1 <= 0) | |
0 | 632 { |
57 | 633 as -> skipcond = 1; |
634 as -> skipcount = 1; | |
0 | 635 } |
636 } | |
57 | 637 |
638 OPFUNC(pseudo_ifge) | |
0 | 639 { |
640 int v1; | |
641 int rval; | |
57 | 642 |
643 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 644 { |
57 | 645 as -> skipcount++; |
646 return; | |
0 | 647 } |
57 | 648 |
103 | 649 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0); |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
650 if (rval != 0) |
57 | 651 return; |
652 if (v1 < 0) | |
0 | 653 { |
57 | 654 as -> skipcond = 1; |
655 as -> skipcount = 1; | |
0 | 656 } |
657 } | |
658 | |
56 | 659 OPFUNC(pseudo_error) |
0 | 660 { |
56 | 661 register_error(as, l, 1, "User error: %s", *p); |
0 | 662 } |
56 | 663 |
74 | 664 |
665 OPFUNC(pseudo_section) | |
666 { | |
667 sectiontab_t *s; | |
668 char *p2; | |
669 char *sn; | |
670 char *opts; | |
671 | |
99 | 672 |
74 | 673 if (as -> outformat != OUTPUT_OBJ) |
674 { | |
675 register_error(as, l, 1, "Sections only supported for obj target"); | |
676 return; | |
677 } | |
678 | |
679 if (as -> csect) | |
680 { | |
681 as -> csect -> offset = as -> addr; | |
682 as -> csect = NULL; | |
683 } | |
684 | |
685 if (!**p) | |
686 { | |
687 register_error(as, l, 1, "Need section name"); | |
688 return; | |
689 } | |
690 | |
691 for (p2 = *p; *p2 && !isspace(*p2); p2++) | |
692 /* do nothing */ ; | |
693 | |
694 sn = lwasm_alloc(p2 - *p + 1); | |
695 memcpy(sn, *p, p2 - *p); | |
696 sn[p2 - *p] = '\0'; | |
697 | |
698 *p = p2; | |
699 | |
700 opts = strchr(sn, ','); | |
701 if (opts) | |
702 { | |
703 *opts++ = '\0'; | |
704 } | |
705 | |
706 // have we seen the section name already? | |
707 for (s = as -> sections; s; s = s -> next) | |
708 { | |
709 if (!strcmp(s -> name, sn)) | |
710 break; | |
711 } | |
712 | |
99 | 713 if (s && as -> passnum == 1) |
74 | 714 { |
715 lwasm_free(sn); | |
716 if (opts) | |
717 { | |
718 register_error(as, l, 1, "Section options can only be specified the first time"); | |
719 return; | |
720 } | |
721 } | |
722 else if (!s) | |
723 { | |
724 s = lwasm_alloc(sizeof(sectiontab_t)); | |
725 s -> name = sn; | |
726 s -> offset = 0; | |
727 s -> flags = 0; | |
85 | 728 s -> obytes = NULL; |
729 s -> oblen = 0; | |
730 s -> obsize = 0; | |
86 | 731 s -> rl = NULL; |
90 | 732 s -> exports = NULL; |
74 | 733 // parse options; only one "bss" |
734 if (opts && as -> passnum == 1) | |
735 { | |
736 if (!strcasecmp(opts, "bss")) | |
737 { | |
738 s -> flags = SECTION_BSS; | |
739 } | |
740 else | |
741 { | |
742 register_error(as, l, 1, "Unrecognized section option '%s'", opts); | |
743 lwasm_free(s -> name); | |
744 lwasm_free(s); | |
745 return; | |
746 } | |
747 } | |
748 | |
749 s -> next = as -> sections; | |
750 as -> sections = s; | |
751 } | |
752 as -> addr = s -> offset; | |
753 as -> csect = s; | |
754 as -> context = lwasm_next_context(as); | |
755 } | |
756 | |
757 OPFUNC(pseudo_endsection) | |
758 { | |
759 if (as -> outformat != OUTPUT_OBJ) | |
760 { | |
761 register_error(as, l, 1, "Sections only supported for obj target"); | |
762 return; | |
763 } | |
764 | |
765 if (!(as -> csect)) | |
766 { | |
767 register_error(as, l, 1, "ENDSECTION when not in a section"); | |
768 return; | |
769 } | |
770 | |
771 as -> csect -> offset = as -> addr; | |
772 as -> addr = 0; | |
773 as -> csect = 0; | |
774 as -> context = lwasm_next_context(as); | |
775 } | |
82 | 776 |
777 OPFUNC(pseudo_extern) | |
778 { | |
779 if (as -> passnum != 1) | |
780 return; | |
781 | |
782 if (as -> outformat != OUTPUT_OBJ) | |
783 { | |
784 register_error(as, l, 1, "External references only supported for obj target"); | |
785 return; | |
786 } | |
787 | |
788 if (as -> csect) | |
789 { | |
790 register_error(as, l, 1, "Cannot declare external symbols within a section"); | |
791 return; | |
792 } | |
793 | |
794 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN); | |
795 } | |
90 | 796 |
797 OPFUNC(pseudo_export) | |
798 { | |
799 lwasm_symbol_ent_t *se; | |
800 export_list_t *ex; | |
801 | |
802 if (as -> outformat != OUTPUT_OBJ) | |
803 { | |
804 register_error(as, l, 1, "Symbol exports only supported for obj target"); | |
805 return; | |
806 } | |
807 | |
808 if (as -> passnum == 1) | |
809 return; | |
810 | |
811 // the symbol better be defined at this point (pass 2) | |
812 // local symbols cannot be exported nor can "global" symbols | |
813 se = lwasm_find_symbol(as, l -> sym, -1); | |
814 if (!se) | |
815 { | |
816 register_error(as, l, 2, "Exported symbols must be fully defined within a section"); | |
817 return; | |
818 } | |
819 if (se -> sect == NULL) | |
820 { | |
821 register_error(as, l, 2, "Only non-local symbols within a section can be exported"); | |
822 return; | |
823 } | |
824 | |
825 if (se -> flags & SYMBOL_SET) | |
826 { | |
827 register_error(as, l, 2, "You cannot export symbols defined with SET"); | |
828 return; | |
829 } | |
830 | |
831 // if the symbol is not already a simple value, re-evaluate it | |
832 // and see if it becomes simple | |
833 | |
834 | |
835 if (se -> flags & SYMBOL_COMPLEX) | |
836 { | |
837 register_error(as, l, 2, "Exported symbols must be fully resolved on pass 2"); | |
838 return; | |
839 } | |
840 | |
841 // search for existing export | |
842 for (ex = se -> sect -> exports; ex; ex = ex -> next) | |
843 if (!strcmp(l -> sym, ex -> sym)) | |
844 break; | |
845 if (ex) | |
846 { | |
847 register_error(as, l, 2, "Symbol %s already exported", l -> sym); | |
848 return; | |
849 } | |
850 | |
851 // add an external reference | |
852 ex = lwasm_alloc(sizeof(export_list_t)); | |
853 ex -> next = se -> sect -> exports; | |
854 se -> sect -> exports = ex; | |
855 ex -> offset = se -> value; | |
856 ex -> sym = lwasm_strdup(se -> sym); | |
857 } |