Mercurial > hg-old > index.cgi
annotate src/pseudo.c @ 112:a567dbb3f1d4
command line options
author | lost |
---|---|
date | Sat, 17 Jan 2009 16:55:53 +0000 |
parents | 2ba8f9ef1417 |
children |
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 |
104 | 554 OPFUNC(pseudo_ifdef) |
555 { | |
556 lwasm_symbol_ent_t *se; | |
557 char *sym; | |
558 char *p2; | |
559 | |
560 if (as -> skipcond && !(as -> skipmacro)) | |
561 { | |
562 as -> skipcount++; | |
563 return; | |
564 } | |
565 | |
566 if (as -> passnum != 1) | |
567 { | |
568 if (!(l -> fsize)) | |
569 { | |
570 as -> skipcond = 1; | |
571 as -> skipcount = 1; | |
572 } | |
573 return; | |
574 } | |
575 | |
576 if (!**p) | |
577 { | |
578 register_error(as, l, 1, "Need symbol name"); | |
579 return; | |
580 } | |
581 | |
582 for (p2 = *p; *p2 && !isspace(*p2); p2++) | |
583 /* do nothing */ ; | |
584 | |
585 sym = lwasm_alloc(p2 - *p + 1); | |
586 memcpy(sym, *p, p2 - *p); | |
587 sym[p2 - *p] = '\0'; | |
588 | |
589 *p = p2; | |
590 | |
591 se = lwasm_find_symbol(as, sym, l -> context); | |
592 if (!se) | |
593 se = lwasm_find_symbol(as, sym, -1); | |
594 | |
595 lwasm_free(sym); | |
596 | |
597 if (!se) | |
598 { | |
599 as -> skipcond = 1; | |
600 as -> skipcount = 1; | |
601 l -> fsize = 0; | |
602 } | |
603 else | |
604 { | |
605 l -> fsize = 1; | |
606 } | |
607 } | |
608 | |
609 OPFUNC(pseudo_ifndef) | |
610 { | |
611 lwasm_symbol_ent_t *se; | |
612 char *sym; | |
613 char *p2; | |
614 | |
615 if (as -> skipcond && !(as -> skipmacro)) | |
616 { | |
617 as -> skipcount++; | |
618 return; | |
619 } | |
620 | |
621 if (as -> passnum != 1) | |
622 { | |
623 if (l -> fsize) | |
624 { | |
625 as -> skipcond = 1; | |
626 as -> skipcount = 1; | |
627 } | |
628 return; | |
629 } | |
630 | |
631 if (!**p) | |
632 { | |
633 register_error(as, l, 1, "Need symbol name"); | |
634 return; | |
635 } | |
636 | |
637 for (p2 = *p; *p2 && !isspace(*p2); p2++) | |
638 /* do nothing */ ; | |
639 | |
640 sym = lwasm_alloc(p2 - *p + 1); | |
641 memcpy(sym, *p, p2 - *p); | |
642 sym[p2 - *p] = '\0'; | |
643 | |
644 *p = p2; | |
645 | |
646 se = lwasm_find_symbol(as, sym, l -> context); | |
647 if (!se) | |
648 se = lwasm_find_symbol(as, sym, -1); | |
649 | |
650 lwasm_free(sym); | |
651 | |
652 if (se) | |
653 { | |
654 as -> skipcond = 1; | |
655 as -> skipcount = 1; | |
656 l -> fsize = 0; | |
657 } | |
658 else | |
659 { | |
660 l -> fsize = 1; | |
661 } | |
662 } | |
663 | |
57 | 664 OPFUNC(pseudo_ifeq) |
0 | 665 { |
666 int v1; | |
667 int rval; | |
57 | 668 |
669 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 670 { |
57 | 671 as -> skipcount++; |
672 return; | |
0 | 673 } |
57 | 674 |
103 | 675 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
|
676 if (rval != 0) |
57 | 677 return; |
678 if (v1) | |
0 | 679 { |
57 | 680 as -> skipcond = 1; |
681 as -> skipcount = 1; | |
0 | 682 } |
683 } | |
57 | 684 |
685 OPFUNC(pseudo_iflt) | |
0 | 686 { |
687 int v1; | |
688 int rval; | |
57 | 689 |
690 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 691 { |
57 | 692 as -> skipcount++; |
693 return; | |
0 | 694 } |
57 | 695 |
103 | 696 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
|
697 if (rval != 0) |
57 | 698 return; |
699 if (v1 >= 0) | |
0 | 700 { |
57 | 701 as -> skipcond = 1; |
702 as -> skipcount = 1; | |
0 | 703 } |
704 } | |
57 | 705 |
706 OPFUNC(pseudo_ifle) | |
0 | 707 { |
708 int v1; | |
709 int rval; | |
57 | 710 |
711 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 712 { |
57 | 713 as -> skipcount++; |
714 return; | |
0 | 715 } |
57 | 716 |
103 | 717 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
|
718 if (rval != 0) |
57 | 719 return; |
720 if (v1 > 0) | |
0 | 721 { |
57 | 722 as -> skipcond = 1; |
723 as -> skipcount = 1; | |
0 | 724 } |
725 } | |
57 | 726 |
727 OPFUNC(pseudo_ifgt) | |
0 | 728 { |
729 int v1; | |
730 int rval; | |
57 | 731 |
732 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 733 { |
57 | 734 as -> skipcount++; |
735 return; | |
0 | 736 } |
57 | 737 |
103 | 738 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
|
739 if (rval != 0) |
57 | 740 return; |
741 if (v1 <= 0) | |
0 | 742 { |
57 | 743 as -> skipcond = 1; |
744 as -> skipcount = 1; | |
0 | 745 } |
746 } | |
57 | 747 |
748 OPFUNC(pseudo_ifge) | |
0 | 749 { |
750 int v1; | |
751 int rval; | |
57 | 752 |
753 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 754 { |
57 | 755 as -> skipcount++; |
756 return; | |
0 | 757 } |
57 | 758 |
103 | 759 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
|
760 if (rval != 0) |
57 | 761 return; |
762 if (v1 < 0) | |
0 | 763 { |
57 | 764 as -> skipcond = 1; |
765 as -> skipcount = 1; | |
0 | 766 } |
767 } | |
768 | |
56 | 769 OPFUNC(pseudo_error) |
0 | 770 { |
56 | 771 register_error(as, l, 1, "User error: %s", *p); |
0 | 772 } |
56 | 773 |
74 | 774 |
775 OPFUNC(pseudo_section) | |
776 { | |
777 sectiontab_t *s; | |
778 char *p2; | |
779 char *sn; | |
780 char *opts; | |
781 | |
99 | 782 |
74 | 783 if (as -> outformat != OUTPUT_OBJ) |
784 { | |
785 register_error(as, l, 1, "Sections only supported for obj target"); | |
786 return; | |
787 } | |
788 | |
789 if (as -> csect) | |
790 { | |
791 as -> csect -> offset = as -> addr; | |
792 as -> csect = NULL; | |
793 } | |
794 | |
795 if (!**p) | |
796 { | |
797 register_error(as, l, 1, "Need section name"); | |
798 return; | |
799 } | |
800 | |
801 for (p2 = *p; *p2 && !isspace(*p2); p2++) | |
802 /* do nothing */ ; | |
803 | |
804 sn = lwasm_alloc(p2 - *p + 1); | |
805 memcpy(sn, *p, p2 - *p); | |
806 sn[p2 - *p] = '\0'; | |
807 | |
808 *p = p2; | |
809 | |
810 opts = strchr(sn, ','); | |
811 if (opts) | |
812 { | |
813 *opts++ = '\0'; | |
814 } | |
815 | |
816 // have we seen the section name already? | |
817 for (s = as -> sections; s; s = s -> next) | |
818 { | |
819 if (!strcmp(s -> name, sn)) | |
820 break; | |
821 } | |
822 | |
99 | 823 if (s && as -> passnum == 1) |
74 | 824 { |
825 lwasm_free(sn); | |
826 if (opts) | |
827 { | |
828 register_error(as, l, 1, "Section options can only be specified the first time"); | |
829 return; | |
830 } | |
831 } | |
832 else if (!s) | |
833 { | |
834 s = lwasm_alloc(sizeof(sectiontab_t)); | |
835 s -> name = sn; | |
836 s -> offset = 0; | |
837 s -> flags = 0; | |
85 | 838 s -> obytes = NULL; |
839 s -> oblen = 0; | |
840 s -> obsize = 0; | |
86 | 841 s -> rl = NULL; |
90 | 842 s -> exports = NULL; |
74 | 843 // parse options; only one "bss" |
844 if (opts && as -> passnum == 1) | |
845 { | |
846 if (!strcasecmp(opts, "bss")) | |
847 { | |
848 s -> flags = SECTION_BSS; | |
849 } | |
850 else | |
851 { | |
852 register_error(as, l, 1, "Unrecognized section option '%s'", opts); | |
853 lwasm_free(s -> name); | |
854 lwasm_free(s); | |
855 return; | |
856 } | |
857 } | |
858 | |
859 s -> next = as -> sections; | |
860 as -> sections = s; | |
861 } | |
862 as -> addr = s -> offset; | |
863 as -> csect = s; | |
864 as -> context = lwasm_next_context(as); | |
865 } | |
866 | |
867 OPFUNC(pseudo_endsection) | |
868 { | |
869 if (as -> outformat != OUTPUT_OBJ) | |
870 { | |
871 register_error(as, l, 1, "Sections only supported for obj target"); | |
872 return; | |
873 } | |
874 | |
875 if (!(as -> csect)) | |
876 { | |
877 register_error(as, l, 1, "ENDSECTION when not in a section"); | |
878 return; | |
879 } | |
880 | |
881 as -> csect -> offset = as -> addr; | |
882 as -> addr = 0; | |
883 as -> csect = 0; | |
884 as -> context = lwasm_next_context(as); | |
885 } | |
82 | 886 |
887 OPFUNC(pseudo_extern) | |
888 { | |
889 if (as -> passnum != 1) | |
890 return; | |
891 | |
892 if (as -> outformat != OUTPUT_OBJ) | |
893 { | |
894 register_error(as, l, 1, "External references only supported for obj target"); | |
895 return; | |
896 } | |
897 | |
898 if (as -> csect) | |
899 { | |
900 register_error(as, l, 1, "Cannot declare external symbols within a section"); | |
901 return; | |
902 } | |
903 | |
904 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN); | |
905 } | |
90 | 906 |
907 OPFUNC(pseudo_export) | |
908 { | |
909 lwasm_symbol_ent_t *se; | |
910 export_list_t *ex; | |
911 | |
912 if (as -> outformat != OUTPUT_OBJ) | |
913 { | |
914 register_error(as, l, 1, "Symbol exports only supported for obj target"); | |
915 return; | |
916 } | |
917 | |
918 if (as -> passnum == 1) | |
919 return; | |
920 | |
921 // the symbol better be defined at this point (pass 2) | |
922 // local symbols cannot be exported nor can "global" symbols | |
923 se = lwasm_find_symbol(as, l -> sym, -1); | |
924 if (!se) | |
925 { | |
926 register_error(as, l, 2, "Exported symbols must be fully defined within a section"); | |
927 return; | |
928 } | |
929 if (se -> sect == NULL) | |
930 { | |
931 register_error(as, l, 2, "Only non-local symbols within a section can be exported"); | |
932 return; | |
933 } | |
934 | |
935 if (se -> flags & SYMBOL_SET) | |
936 { | |
937 register_error(as, l, 2, "You cannot export symbols defined with SET"); | |
938 return; | |
939 } | |
940 | |
941 // if the symbol is not already a simple value, re-evaluate it | |
942 // and see if it becomes simple | |
943 | |
944 | |
945 if (se -> flags & SYMBOL_COMPLEX) | |
946 { | |
947 register_error(as, l, 2, "Exported symbols must be fully resolved on pass 2"); | |
948 return; | |
949 } | |
950 | |
951 // search for existing export | |
952 for (ex = se -> sect -> exports; ex; ex = ex -> next) | |
953 if (!strcmp(l -> sym, ex -> sym)) | |
954 break; | |
955 if (ex) | |
956 { | |
957 register_error(as, l, 2, "Symbol %s already exported", l -> sym); | |
958 return; | |
959 } | |
960 | |
961 // add an external reference | |
962 ex = lwasm_alloc(sizeof(export_list_t)); | |
963 ex -> next = se -> sect -> exports; | |
964 se -> sect -> exports = ex; | |
965 ex -> offset = se -> value; | |
966 ex -> sym = lwasm_strdup(se -> sym); | |
967 } |