Mercurial > hg-old > index.cgi
annotate src/pseudo.c @ 96:7fbccdd1defb
Added doc subdirectory to distribution
author | lost |
---|---|
date | Sat, 17 Jan 2009 07:09:02 +0000 |
parents | f3497072ac44 |
children | 3dcb12a6f4ff |
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); |
95 | 134 fprintf(stderr, "RMB: v=%d, addr=%d\n", v, as -> addr); |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
135 if (r != 0) |
0 | 136 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
137 l -> nocodelen = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
138 as -> addr += v; |
0 | 139 } |
53 | 140 |
141 OPFUNC(pseudo_rmd) | |
0 | 142 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
143 int r, v; |
0 | 144 |
95 | 145 if (as -> passnum == 2) |
0 | 146 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
147 as -> addr += l -> nocodelen; |
0 | 148 return; |
149 } | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
150 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
151 if (r != 0) |
0 | 152 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
153 v *= 2; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
154 l -> nocodelen = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
155 as -> addr += v; |
0 | 156 } |
157 | |
53 | 158 OPFUNC(pseudo_rmq) |
0 | 159 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
160 int r, v; |
0 | 161 |
95 | 162 if (as -> passnum == 2) |
0 | 163 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
164 as -> addr += l -> nocodelen; |
0 | 165 return; |
166 } | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
167 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
168 if (r != 0) |
0 | 169 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
170 v *= 4; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
171 l -> nocodelen = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
172 as -> addr += v; |
0 | 173 } |
174 | |
53 | 175 OPFUNC(pseudo_zmb) |
0 | 176 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
177 int r, v; |
0 | 178 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
179 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
180 if (r != 0) |
0 | 181 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
182 while (v--) |
53 | 183 lwasm_emit(as, l, 0); |
0 | 184 } |
185 | |
53 | 186 OPFUNC(pseudo_zmd) |
0 | 187 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
188 int r, v; |
0 | 189 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
190 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
191 if (r != 0) |
0 | 192 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
193 v *= 2; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
194 while (v--) |
53 | 195 lwasm_emit(as, l, 0); |
0 | 196 } |
197 | |
53 | 198 OPFUNC(pseudo_zmq) |
199 { | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
200 int r, v; |
53 | 201 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
202 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
203 if (r != 0) |
53 | 204 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
205 v *= 4; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
206 while (v--) |
53 | 207 lwasm_emit(as, l, 0); |
208 } | |
209 | |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
210 OPFUNC(pseudo_end) |
0 | 211 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
212 int r, v; |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
213 lwasm_expr_stack_t *s; |
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 |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
216 as -> endseen = 1; |
0 | 217 |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
218 // address only matters for DECB output |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
219 if (as -> outformat != OUTPUT_DECB) |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
220 return; |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
221 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
222 r = lwasm_expr_result2(as, l, p, 0, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
223 if (r != 0) |
0 | 224 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
225 register_error(as, l, 2, "Bad operand"); |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
226 } |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
227 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
228 v = v & 0xffff; |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
229 if (as -> passnum == 2) |
0 | 230 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
231 as -> execaddr = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
232 l -> symaddr = v; |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
233 l -> addrset = 2; |
0 | 234 } |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
235 } |
0 | 236 |
56 | 237 |
238 OPFUNC(pseudo_align) | |
0 | 239 { |
240 int cn; | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
241 int r, v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
242 |
56 | 243 if (as -> passnum == 2) |
0 | 244 { |
56 | 245 while (as -> addr < l -> symaddr) |
246 lwasm_emit(as, l, 0); | |
247 return; | |
248 } | |
249 | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
250 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
251 if (r != 0) |
56 | 252 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
253 l -> symaddr = as -> addr; |
0 | 254 return; |
255 } | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
256 |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
257 if (v < 1) |
56 | 258 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
259 register_error(as, l, 1, "Illegal alignment %d", v); |
56 | 260 return; |
0 | 261 } |
56 | 262 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
263 cn = l -> codeaddr % v; |
56 | 264 if (cn) |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
265 cn = v - cn; |
56 | 266 |
267 while (cn--) | |
268 { | |
269 lwasm_emit(as, l, 0); | |
270 } | |
271 l -> symaddr = as -> addr; | |
0 | 272 } |
56 | 273 |
50 | 274 OPFUNC(pseudo_equ) |
0 | 275 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
276 int r, v; |
52 | 277 |
50 | 278 if (l -> sym == NULL) |
0 | 279 { |
50 | 280 register_error(as, l, 1, "No symbol specified"); |
0 | 281 return; |
282 } | |
50 | 283 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
284 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
285 if (r < 0) |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
286 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
|
287 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
288 l -> symaddr = v & 0xFFFF; |
50 | 289 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
|
290 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
291 // 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
|
292 // to a constant! |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
293 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE); |
0 | 294 } |
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
|
295 |
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 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
|
297 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
298 int r, v; |
64 | 299 |
300 // set MUST run on both passes as the symbol value changes! | |
301 | |
302 if (l -> sym == NULL) | |
303 { | |
304 register_error(as, l, 1, "No symbol specified"); | |
305 return; | |
306 } | |
307 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
308 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
309 if (r < 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
310 v = 0; |
64 | 311 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
312 l -> symaddr = v & 0xFFFF; |
64 | 313 l -> addrset = 2; |
314 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
315 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
|
316 } |
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
|
317 |
65
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
318 OPFUNC(pseudo_setdp) |
0 | 319 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
320 int r, v; |
0 | 321 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
322 if (as -> outformat == OUTPUT_OBJ) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
323 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
324 register_error(as, l, 1, "SETDP not permitted with OBJ target"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
325 return; |
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 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
328 // 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
|
329 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
330 if (r != 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
331 return; |
65
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
332 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
333 if (v < -127 || v > 255) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
334 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
335 register_error(as, l, 1, "Byte overflow"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
336 return; |
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 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
339 l -> symaddr = v & 0xFF; |
65
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
340 l -> addrset = 2; |
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
341 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
342 as -> dpval = v & 0xFF; |
0 | 343 } |
344 | |
56 | 345 OPFUNC(pseudo_fcc) |
346 { | |
0 | 347 int delim = 0; |
348 | |
56 | 349 delim = **p; |
0 | 350 if (!delim) |
351 { | |
56 | 352 register_error(as, l, 1, "Bad operand"); |
353 return; | |
0 | 354 } |
56 | 355 *p += 1; |
356 while (**p && **p != delim) | |
0 | 357 { |
56 | 358 lwasm_emit(as, l, **p); |
359 (*p)++; | |
0 | 360 } |
56 | 361 if (**p) |
362 (*p)++; | |
0 | 363 } |
364 | |
56 | 365 |
366 OPFUNC(pseudo_fcs) | |
0 | 367 { |
368 int delim = 0; | |
56 | 369 |
370 delim = **p; | |
0 | 371 if (!delim) |
372 { | |
56 | 373 register_error(as, l, 1, "Bad operand"); |
374 return; | |
0 | 375 } |
56 | 376 *p += 1; |
377 while (**p && **p != delim) | |
0 | 378 { |
56 | 379 if (!*((*p) + 1) || *((*p) + 1) == delim) |
380 lwasm_emit(as, l, **p | 0x80); | |
381 else | |
382 lwasm_emit(as, l, **p); | |
383 (*p)++; | |
0 | 384 } |
56 | 385 if (**p) |
386 (*p)++; | |
0 | 387 } |
388 | |
56 | 389 OPFUNC(pseudo_fcn) |
0 | 390 { |
391 int delim = 0; | |
392 | |
56 | 393 delim = **p; |
0 | 394 if (!delim) |
395 { | |
56 | 396 register_error(as, l, 1, "Bad operand"); |
397 return; | |
0 | 398 } |
56 | 399 *p += 1; |
400 while (**p && **p != delim) | |
0 | 401 { |
56 | 402 lwasm_emit(as, l, **p); |
403 (*p)++; | |
0 | 404 } |
56 | 405 if (**p) |
406 (*p)++; | |
407 lwasm_emit(as, l, 0); | |
0 | 408 } |
56 | 409 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
410 // FIXME: handle external, etc., references in a useful manner |
56 | 411 OPFUNC(pseudo_fcb) |
0 | 412 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
413 int r, v; |
0 | 414 |
415 fcb_again: | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
416 r = lwasm_expr_result2(as, l, p, 0, &v, -1); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
417 if (r < 0) |
56 | 418 return; |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
419 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
420 if (r > 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
421 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
422 register_error(as, l, 2, "Illegal external or inter-segment reference"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
423 v = 0; |
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 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
426 if (v < -127 || v > 255) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
427 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
428 register_error(as, l, 1, "Byte overflow"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
429 } |
56 | 430 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
431 lwasm_emit(as, l, v); |
56 | 432 if (**p == ',') |
0 | 433 { |
56 | 434 (*p)++; |
0 | 435 goto fcb_again; |
436 } | |
437 } | |
438 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
439 // FIXME: handle external references in an intelligent way |
56 | 440 OPFUNC(pseudo_fdb) |
0 | 441 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
442 int r, v; |
0 | 443 |
444 fdb_again: | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
445 r = lwasm_expr_result2(as, l, p, 0, &v, -1); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
446 if (r < 0) |
56 | 447 return; |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
448 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
449 if (r > 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
450 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
451 register_error(as, l, 2, "Illegal external or inter-segment reference"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
452 v = 0; |
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 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
455 lwasm_emit(as, l, v >> 8); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
456 lwasm_emit(as, l, v & 0xff); |
56 | 457 if (**p == ',') |
0 | 458 { |
56 | 459 (*p)++; |
0 | 460 goto fdb_again; |
461 } | |
462 } | |
463 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
464 // FIXME: handle external references in a sensible way |
56 | 465 OPFUNC(pseudo_fqb) |
0 | 466 { |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
467 int r, v; |
56 | 468 |
0 | 469 fqb_again: |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
470 r = lwasm_expr_result2(as, l, p, 0, &v, -1); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
471 if (r < 0) |
56 | 472 return; |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
473 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
474 if (r > 0) |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
475 { |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
476 register_error(as, l, 2, "Illegal external or inter-segment reference"); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
477 v = 0; |
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 |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
480 lwasm_emit(as, l, v >> 24); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
481 lwasm_emit(as, l, v >> 16); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
482 lwasm_emit(as, l, v >> 8); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
483 lwasm_emit(as, l, v & 0xff); |
56 | 484 if (**p == ',') |
0 | 485 { |
56 | 486 (*p)++; |
0 | 487 goto fqb_again; |
488 } | |
489 } | |
490 | |
491 // don't need to do anything if we are executing one of these | |
57 | 492 OPFUNC(pseudo_endc) |
0 | 493 { |
57 | 494 if (as -> skipcond && !(as -> skipmacro)) |
495 { | |
496 as -> skipcount -= 1; | |
497 if (as -> skipcount <= 0) | |
498 { | |
499 as -> skipcond = 0; | |
500 } | |
501 } | |
0 | 502 return; |
503 } | |
504 | |
505 // if "else" executes, we must be going into an "ignore" state | |
57 | 506 OPFUNC(pseudo_else) |
0 | 507 { |
57 | 508 if (as -> skipmacro) |
509 return; | |
510 | |
511 if (as -> skipcond) | |
512 { | |
513 if (as -> skipcount == 1) | |
514 { | |
515 as -> skipcount = 0; | |
516 as -> skipcond = 0; | |
517 } | |
518 return; | |
519 } | |
520 | |
0 | 521 as -> skipcond = 1; |
522 as -> skipcount = 1; | |
523 } | |
524 | |
57 | 525 OPFUNC(pseudo_ifne) |
0 | 526 { |
527 int v1; | |
528 int rval; | |
57 | 529 |
530 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 531 { |
57 | 532 as -> skipcount++; |
533 return; | |
534 } | |
535 | |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
536 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
537 if (rval != 0) |
57 | 538 return; |
539 if (!v1) | |
540 { | |
541 as -> skipcond = 1; | |
542 as -> skipcount = 1; | |
0 | 543 } |
544 } | |
57 | 545 |
546 OPFUNC(pseudo_ifeq) | |
0 | 547 { |
548 int v1; | |
549 int rval; | |
57 | 550 |
551 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 552 { |
57 | 553 as -> skipcount++; |
554 return; | |
0 | 555 } |
57 | 556 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
557 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
558 if (rval != 0) |
57 | 559 return; |
560 if (v1) | |
0 | 561 { |
57 | 562 as -> skipcond = 1; |
563 as -> skipcount = 1; | |
0 | 564 } |
565 } | |
57 | 566 |
567 OPFUNC(pseudo_iflt) | |
0 | 568 { |
569 int v1; | |
570 int rval; | |
57 | 571 |
572 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 573 { |
57 | 574 as -> skipcount++; |
575 return; | |
0 | 576 } |
57 | 577 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
578 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
579 if (rval != 0) |
57 | 580 return; |
581 if (v1 >= 0) | |
0 | 582 { |
57 | 583 as -> skipcond = 1; |
584 as -> skipcount = 1; | |
0 | 585 } |
586 } | |
57 | 587 |
588 OPFUNC(pseudo_ifle) | |
0 | 589 { |
590 int v1; | |
591 int rval; | |
57 | 592 |
593 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 594 { |
57 | 595 as -> skipcount++; |
596 return; | |
0 | 597 } |
57 | 598 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
599 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
600 if (rval != 0) |
57 | 601 return; |
602 if (v1 > 0) | |
0 | 603 { |
57 | 604 as -> skipcond = 1; |
605 as -> skipcount = 1; | |
0 | 606 } |
607 } | |
57 | 608 |
609 OPFUNC(pseudo_ifgt) | |
0 | 610 { |
611 int v1; | |
612 int rval; | |
57 | 613 |
614 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 615 { |
57 | 616 as -> skipcount++; |
617 return; | |
0 | 618 } |
57 | 619 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
620 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
621 if (rval != 0) |
57 | 622 return; |
623 if (v1 <= 0) | |
0 | 624 { |
57 | 625 as -> skipcond = 1; |
626 as -> skipcount = 1; | |
0 | 627 } |
628 } | |
57 | 629 |
630 OPFUNC(pseudo_ifge) | |
0 | 631 { |
632 int v1; | |
633 int rval; | |
57 | 634 |
635 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 636 { |
57 | 637 as -> skipcount++; |
638 return; | |
0 | 639 } |
57 | 640 |
79
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
641 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); |
d0ce3f5f6797
Checkpointing deployment of non-constant expression handling
lost
parents:
78
diff
changeset
|
642 if (rval != 0) |
57 | 643 return; |
644 if (v1 < 0) | |
0 | 645 { |
57 | 646 as -> skipcond = 1; |
647 as -> skipcount = 1; | |
0 | 648 } |
649 } | |
650 | |
56 | 651 OPFUNC(pseudo_error) |
0 | 652 { |
56 | 653 register_error(as, l, 1, "User error: %s", *p); |
0 | 654 } |
56 | 655 |
74 | 656 |
657 OPFUNC(pseudo_section) | |
658 { | |
659 sectiontab_t *s; | |
660 char *p2; | |
661 char *sn; | |
662 char *opts; | |
663 | |
664 | |
665 if (as -> outformat != OUTPUT_OBJ) | |
666 { | |
667 register_error(as, l, 1, "Sections only supported for obj target"); | |
668 return; | |
669 } | |
670 | |
671 if (as -> csect) | |
672 { | |
673 as -> csect -> offset = as -> addr; | |
674 as -> csect = NULL; | |
675 } | |
676 | |
677 if (!**p) | |
678 { | |
679 register_error(as, l, 1, "Need section name"); | |
680 return; | |
681 } | |
682 | |
683 for (p2 = *p; *p2 && !isspace(*p2); p2++) | |
684 /* do nothing */ ; | |
685 | |
686 sn = lwasm_alloc(p2 - *p + 1); | |
687 memcpy(sn, *p, p2 - *p); | |
688 sn[p2 - *p] = '\0'; | |
689 | |
690 *p = p2; | |
691 | |
692 opts = strchr(sn, ','); | |
693 if (opts) | |
694 { | |
695 *opts++ = '\0'; | |
696 } | |
697 | |
698 // have we seen the section name already? | |
699 for (s = as -> sections; s; s = s -> next) | |
700 { | |
701 if (!strcmp(s -> name, sn)) | |
702 break; | |
703 } | |
704 | |
705 if (s) | |
706 { | |
707 lwasm_free(sn); | |
708 if (opts) | |
709 { | |
710 register_error(as, l, 1, "Section options can only be specified the first time"); | |
711 return; | |
712 } | |
713 } | |
714 else if (!s) | |
715 { | |
716 s = lwasm_alloc(sizeof(sectiontab_t)); | |
717 s -> name = sn; | |
718 s -> offset = 0; | |
719 s -> flags = 0; | |
85 | 720 s -> obytes = NULL; |
721 s -> oblen = 0; | |
722 s -> obsize = 0; | |
86 | 723 s -> rl = NULL; |
90 | 724 s -> exports = NULL; |
74 | 725 // parse options; only one "bss" |
726 if (opts && as -> passnum == 1) | |
727 { | |
728 if (!strcasecmp(opts, "bss")) | |
729 { | |
730 s -> flags = SECTION_BSS; | |
731 } | |
732 else | |
733 { | |
734 register_error(as, l, 1, "Unrecognized section option '%s'", opts); | |
735 lwasm_free(s -> name); | |
736 lwasm_free(s); | |
737 return; | |
738 } | |
739 } | |
740 | |
741 s -> next = as -> sections; | |
742 as -> sections = s; | |
743 } | |
744 as -> addr = s -> offset; | |
745 as -> csect = s; | |
746 as -> context = lwasm_next_context(as); | |
747 } | |
748 | |
749 OPFUNC(pseudo_endsection) | |
750 { | |
751 if (as -> outformat != OUTPUT_OBJ) | |
752 { | |
753 register_error(as, l, 1, "Sections only supported for obj target"); | |
754 return; | |
755 } | |
756 | |
757 if (!(as -> csect)) | |
758 { | |
759 register_error(as, l, 1, "ENDSECTION when not in a section"); | |
760 return; | |
761 } | |
762 | |
763 as -> csect -> offset = as -> addr; | |
764 as -> addr = 0; | |
765 as -> csect = 0; | |
766 as -> context = lwasm_next_context(as); | |
767 } | |
82 | 768 |
769 OPFUNC(pseudo_extern) | |
770 { | |
771 if (as -> passnum != 1) | |
772 return; | |
773 | |
774 if (as -> outformat != OUTPUT_OBJ) | |
775 { | |
776 register_error(as, l, 1, "External references only supported for obj target"); | |
777 return; | |
778 } | |
779 | |
780 if (as -> csect) | |
781 { | |
782 register_error(as, l, 1, "Cannot declare external symbols within a section"); | |
783 return; | |
784 } | |
785 | |
786 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN); | |
787 } | |
90 | 788 |
789 OPFUNC(pseudo_export) | |
790 { | |
791 lwasm_symbol_ent_t *se; | |
792 export_list_t *ex; | |
793 | |
794 if (as -> outformat != OUTPUT_OBJ) | |
795 { | |
796 register_error(as, l, 1, "Symbol exports only supported for obj target"); | |
797 return; | |
798 } | |
799 | |
800 if (as -> passnum == 1) | |
801 return; | |
802 | |
803 // the symbol better be defined at this point (pass 2) | |
804 // local symbols cannot be exported nor can "global" symbols | |
805 se = lwasm_find_symbol(as, l -> sym, -1); | |
806 if (!se) | |
807 { | |
808 register_error(as, l, 2, "Exported symbols must be fully defined within a section"); | |
809 return; | |
810 } | |
811 if (se -> sect == NULL) | |
812 { | |
813 register_error(as, l, 2, "Only non-local symbols within a section can be exported"); | |
814 return; | |
815 } | |
816 | |
817 if (se -> flags & SYMBOL_SET) | |
818 { | |
819 register_error(as, l, 2, "You cannot export symbols defined with SET"); | |
820 return; | |
821 } | |
822 | |
823 // if the symbol is not already a simple value, re-evaluate it | |
824 // and see if it becomes simple | |
825 | |
826 | |
827 if (se -> flags & SYMBOL_COMPLEX) | |
828 { | |
829 register_error(as, l, 2, "Exported symbols must be fully resolved on pass 2"); | |
830 return; | |
831 } | |
832 | |
833 // search for existing export | |
834 for (ex = se -> sect -> exports; ex; ex = ex -> next) | |
835 if (!strcmp(l -> sym, ex -> sym)) | |
836 break; | |
837 if (ex) | |
838 { | |
839 register_error(as, l, 2, "Symbol %s already exported", l -> sym); | |
840 return; | |
841 } | |
842 | |
843 // add an external reference | |
844 ex = lwasm_alloc(sizeof(export_list_t)); | |
845 ex -> next = se -> sect -> exports; | |
846 se -> sect -> exports = ex; | |
847 ex -> offset = se -> value; | |
848 ex -> sym = lwasm_strdup(se -> sym); | |
849 } |