Mercurial > hg-old > index.cgi
comparison src/pseudo.c @ 78:121bf4a588ea
Checkpointing deployment of non-constant expression handling
author | lost |
---|---|
date | Sat, 10 Jan 2009 05:00:42 +0000 |
parents | c8c772ef5df9 |
children | d0ce3f5f6797 |
comparison
equal
deleted
inserted
replaced
77:a338d496350e | 78:121bf4a588ea |
---|---|
30 | 30 |
31 extern int lwasm_read_file(asmstate_t *as, const char *filename); | 31 extern int lwasm_read_file(asmstate_t *as, const char *filename); |
32 | 32 |
33 OPFUNC(pseudo_org) | 33 OPFUNC(pseudo_org) |
34 { | 34 { |
35 int rval; | 35 int v, r; |
36 lwasm_expr_stack_t *s; | |
37 | 36 |
38 if (as -> csect) | 37 if (as -> csect) |
39 { | 38 { |
40 register_error(as, l, 1, "ORG not allowed within sections"); | 39 register_error(as, l, 1, "ORG not allowed within sections"); |
41 return; | 40 return; |
53 | 52 |
54 if (l -> sym) | 53 if (l -> sym) |
55 { | 54 { |
56 register_error(as, l, 1, "No symbol allowed with ORG"); | 55 register_error(as, l, 1, "No symbol allowed with ORG"); |
57 } | 56 } |
58 s = lwasm_evaluate_expr(as, l, *p, NULL); | 57 |
59 if (!s) | 58 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
60 { | 59 if (r != 0) |
61 register_error(as, l, 1, "Bad expression"); | 60 return; |
62 return; | 61 l -> codeaddr = v; |
63 } | |
64 if (!lwasm_expr_is_constant(s)) | |
65 { | |
66 register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); | |
67 lwasm_expr_stack_free(s); | |
68 return; | |
69 } | |
70 rval = lwasm_expr_get_value(s) & 0xffff; | |
71 lwasm_expr_stack_free(s); | |
72 l -> codeaddr = rval; | |
73 l -> addrset = 1; | 62 l -> addrset = 1; |
74 as -> addr = rval; | 63 as -> addr = v; |
75 } | 64 } |
76 | 65 |
77 /* | 66 /* |
78 The operand for include is a string optionally enclosed in " | 67 The operand for include is a string optionally enclosed in " |
79 */ | 68 */ |
132 lwasm_free(fn); | 121 lwasm_free(fn); |
133 } | 122 } |
134 | 123 |
135 OPFUNC(pseudo_rmb) | 124 OPFUNC(pseudo_rmb) |
136 { | 125 { |
137 int rval; | 126 int r, v; |
138 lwasm_expr_stack_t *s; | 127 |
139 | 128 if (as -> passnum == 1) |
140 s = lwasm_evaluate_expr(as, l, *p, NULL); | 129 { |
141 if (!s) | 130 as -> addr += l -> nocodelen; |
142 { | 131 return; |
143 register_error(as, l, 1, "Bad expression"); | 132 } |
144 return; | 133 |
145 } | 134 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
146 if (!lwasm_expr_is_constant(s)) | 135 if (r != 0) |
147 { | 136 return; |
148 register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); | 137 l -> nocodelen = v; |
149 lwasm_expr_stack_free(s); | 138 as -> addr += v; |
150 return; | |
151 } | |
152 rval = lwasm_expr_get_value(s); | |
153 lwasm_expr_stack_free(s); | |
154 l -> nocodelen = rval; | |
155 as -> addr += rval; | |
156 } | 139 } |
157 | 140 |
158 OPFUNC(pseudo_rmd) | 141 OPFUNC(pseudo_rmd) |
159 { | 142 { |
160 int rval; | 143 int r, v; |
161 lwasm_expr_stack_t *s; | 144 |
162 | 145 if (as -> passnum == 1) |
163 s = lwasm_evaluate_expr(as, l, *p, NULL); | 146 { |
164 if (!s) | 147 as -> addr += l -> nocodelen; |
165 { | 148 return; |
166 register_error(as, l, 1, "Bad expression"); | 149 } |
167 return; | 150 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
168 } | 151 if (r != 0) |
169 if (!lwasm_expr_is_constant(s)) | 152 return; |
170 { | 153 v *= 2; |
171 register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); | 154 l -> nocodelen = v; |
172 lwasm_expr_stack_free(s); | 155 as -> addr += v; |
173 return; | |
174 } | |
175 rval = lwasm_expr_get_value(s) * 2; | |
176 lwasm_expr_stack_free(s); | |
177 l -> nocodelen = rval; | |
178 as -> addr += rval; | |
179 } | 156 } |
180 | 157 |
181 OPFUNC(pseudo_rmq) | 158 OPFUNC(pseudo_rmq) |
182 { | 159 { |
183 int rval; | 160 int r, v; |
184 lwasm_expr_stack_t *s; | 161 |
185 | 162 if (as -> passnum == 1) |
186 s = lwasm_evaluate_expr(as, l, *p, NULL); | 163 { |
187 if (!s) | 164 as -> addr += l -> nocodelen; |
188 { | 165 return; |
189 register_error(as, l, 1, "Bad expression"); | 166 } |
190 return; | 167 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
191 } | 168 if (r != 0) |
192 if (!lwasm_expr_is_constant(s)) | 169 return; |
193 { | 170 v *= 4; |
194 register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); | 171 l -> nocodelen = v; |
195 lwasm_expr_stack_free(s); | 172 as -> addr += v; |
196 return; | |
197 } | |
198 rval = lwasm_expr_get_value(s) * 4; | |
199 lwasm_expr_stack_free(s); | |
200 l -> nocodelen = rval; | |
201 as -> addr += rval; | |
202 } | 173 } |
203 | 174 |
204 OPFUNC(pseudo_zmb) | 175 OPFUNC(pseudo_zmb) |
205 { | 176 { |
206 int rval; | 177 int r, v; |
207 lwasm_expr_stack_t *s; | 178 |
208 | 179 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
209 s = lwasm_evaluate_expr(as, l, *p, NULL); | 180 if (r != 0) |
210 if (!s) | 181 return; |
211 { | 182 while (v--) |
212 register_error(as, l, 1, "Bad expression"); | |
213 return; | |
214 } | |
215 if (!lwasm_expr_is_constant(s)) | |
216 { | |
217 register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); | |
218 lwasm_expr_stack_free(s); | |
219 return; | |
220 } | |
221 rval = lwasm_expr_get_value(s); | |
222 lwasm_expr_stack_free(s); | |
223 while (rval-- > 0) | |
224 { | |
225 lwasm_emit(as, l, 0); | 183 lwasm_emit(as, l, 0); |
226 } | |
227 } | 184 } |
228 | 185 |
229 OPFUNC(pseudo_zmd) | 186 OPFUNC(pseudo_zmd) |
230 { | 187 { |
231 int rval; | 188 int r, v; |
232 lwasm_expr_stack_t *s; | 189 |
233 | 190 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
234 s = lwasm_evaluate_expr(as, l, *p, NULL); | 191 if (r != 0) |
235 if (!s) | 192 return; |
236 { | 193 v *= 2; |
237 register_error(as, l, 1, "Bad expression"); | 194 while (v--) |
238 return; | |
239 } | |
240 if (!lwasm_expr_is_constant(s)) | |
241 { | |
242 register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); | |
243 lwasm_expr_stack_free(s); | |
244 return; | |
245 } | |
246 rval = lwasm_expr_get_value(s); | |
247 lwasm_expr_stack_free(s); | |
248 while (rval-- > 0) | |
249 { | |
250 lwasm_emit(as, l, 0); | 195 lwasm_emit(as, l, 0); |
196 } | |
197 | |
198 OPFUNC(pseudo_zmq) | |
199 { | |
200 int r, v; | |
201 | |
202 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); | |
203 if (r != 0) | |
204 return; | |
205 v *= 4; | |
206 while (v--) | |
251 lwasm_emit(as, l, 0); | 207 lwasm_emit(as, l, 0); |
252 } | |
253 } | |
254 | |
255 OPFUNC(pseudo_zmq) | |
256 { | |
257 int rval; | |
258 lwasm_expr_stack_t *s; | |
259 | |
260 s = lwasm_evaluate_expr(as, l, *p, NULL); | |
261 if (!s) | |
262 { | |
263 register_error(as, l, 1, "Bad expression"); | |
264 return; | |
265 } | |
266 if (!lwasm_expr_is_constant(s)) | |
267 { | |
268 register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); | |
269 lwasm_expr_stack_free(s); | |
270 return; | |
271 } | |
272 rval = lwasm_expr_get_value(s); | |
273 lwasm_expr_stack_free(s); | |
274 while (rval-- > 0) | |
275 { | |
276 lwasm_emit(as, l, 0); | |
277 lwasm_emit(as, l, 0); | |
278 lwasm_emit(as, l, 0); | |
279 lwasm_emit(as, l, 0); | |
280 } | |
281 } | 208 } |
282 | 209 |
283 OPFUNC(pseudo_end) | 210 OPFUNC(pseudo_end) |
284 { | 211 { |
285 int rval; | 212 int r, v; |
286 lwasm_expr_stack_t *s; | 213 lwasm_expr_stack_t *s; |
287 | 214 |
288 | 215 |
289 as -> endseen = 1; | 216 as -> endseen = 1; |
290 | 217 |
291 // address only matters for DECB output | 218 // address only matters for DECB output |
292 if (as -> outformat != OUTPUT_DECB) | 219 if (as -> outformat != OUTPUT_DECB) |
293 return; | 220 return; |
294 | 221 |
295 s = lwasm_evaluate_expr(as, l, *p, NULL); | 222 r = lwasm_expr_result2(as, l, p, 0, &v, 0); |
296 if (!s) | 223 if (r != 0) |
297 { | 224 { |
298 register_error(as, l, 1, "Bad expression"); | 225 register_error(as, l, 2, "Bad operand"); |
299 return; | 226 } |
300 } | 227 |
301 if (!lwasm_expr_is_constant(s)) | 228 v = v & 0xffff; |
302 { | |
303 register_error(as, l, 2, "Incomplete reference"); | |
304 } | |
305 rval = lwasm_expr_get_value(s); | |
306 lwasm_expr_stack_free(s); | |
307 | |
308 rval = rval & 0xffff; | |
309 if (as -> passnum == 2) | 229 if (as -> passnum == 2) |
310 { | 230 { |
311 as -> execaddr = rval; | 231 as -> execaddr = v; |
312 l -> symaddr = rval; | 232 l -> symaddr = v; |
313 l -> addrset = 2; | 233 l -> addrset = 2; |
314 } | 234 } |
315 } | 235 } |
316 | 236 |
317 | 237 |
318 OPFUNC(pseudo_align) | 238 OPFUNC(pseudo_align) |
319 { | 239 { |
320 int rval; | |
321 lwasm_expr_stack_t *s; | |
322 int cn; | 240 int cn; |
323 | 241 int r, v; |
242 | |
324 if (as -> passnum == 2) | 243 if (as -> passnum == 2) |
325 { | 244 { |
326 while (as -> addr < l -> symaddr) | 245 while (as -> addr < l -> symaddr) |
327 lwasm_emit(as, l, 0); | 246 lwasm_emit(as, l, 0); |
328 return; | 247 return; |
329 } | 248 } |
330 | 249 |
331 s = lwasm_evaluate_expr(as, l, *p, NULL); | 250 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
332 if (!s) | 251 if (r != 0) |
333 { | 252 { |
334 register_error(as, l, 1, "Bad expression"); | 253 l -> symaddr = as -> addr; |
335 return; | 254 return; |
336 } | 255 } |
337 if (!lwasm_expr_is_constant(s)) | 256 |
338 { | 257 if (v < 1) |
339 register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); | 258 { |
340 } | 259 register_error(as, l, 1, "Illegal alignment %d", v); |
341 rval = lwasm_expr_get_value(s); | 260 return; |
342 lwasm_expr_stack_free(s); | 261 } |
343 | 262 |
344 if (rval < 1) | 263 cn = l -> codeaddr % v; |
345 { | |
346 register_error(as, l, 1, "Illegal alignment %d", rval); | |
347 return; | |
348 } | |
349 | |
350 cn = l -> codeaddr % rval; | |
351 if (cn) | 264 if (cn) |
352 cn = rval - cn; | 265 cn = v - cn; |
353 | 266 |
354 while (cn--) | 267 while (cn--) |
355 { | 268 { |
356 lwasm_emit(as, l, 0); | 269 lwasm_emit(as, l, 0); |
357 } | 270 } |
358 l -> symaddr = as -> addr; | 271 l -> symaddr = as -> addr; |
359 } | 272 } |
360 | 273 |
361 OPFUNC(pseudo_equ) | 274 OPFUNC(pseudo_equ) |
362 { | 275 { |
363 int rval; | 276 int r, v; |
364 | |
365 // equ is not needed to be processed on pass 2 | |
366 if (as -> passnum != 1) | |
367 return; | |
368 | 277 |
369 if (l -> sym == NULL) | 278 if (l -> sym == NULL) |
370 { | 279 { |
371 register_error(as, l, 1, "No symbol specified"); | 280 register_error(as, l, 1, "No symbol specified"); |
372 return; | 281 return; |
373 } | 282 } |
374 | 283 |
375 if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &rval) < 0) | 284 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
376 rval = 0; | 285 if (r < 0) |
377 | 286 v = 0; |
378 l -> symaddr = rval & 0xFFFF; | 287 |
288 l -> symaddr = v & 0xFFFF; | |
379 l -> addrset = 2; | 289 l -> addrset = 2; |
380 | 290 |
381 lwasm_register_symbol(as, l, l -> sym, rval, SYMBOL_NORM); | 291 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE); |
382 } | 292 } |
383 | 293 |
384 OPFUNC(pseudo_set) | 294 OPFUNC(pseudo_set) |
385 { | 295 { |
386 int rval; | 296 int rval; |