Mercurial > hg-old > index.cgi
annotate lwasm/pseudo.c @ 354:60568b123281
Added os9 opcodes and ERROR
author | lost@starbug |
---|---|
date | Tue, 30 Mar 2010 23:10:01 -0600 |
parents | 4dba8c7e242c |
children | 7166254491ed |
rev | line source |
---|---|
347 | 1 /* |
2 pseudo.c | |
3 Copyright © 2010 William Astle | |
4 | |
5 This file is part of LWASM. | |
6 | |
7 LWASM is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 */ | |
21 | |
22 #include <config.h> | |
23 | |
24 #include "lwasm.h" | |
25 #include "instab.h" | |
26 | |
349 | 27 #include "lw_string.h" |
28 | |
347 | 29 // for "end" |
30 PARSEFUNC(pseudo_parse_end) | |
31 { | |
32 lw_expr_t addr; | |
33 | |
34 as -> endseen = 1; | |
35 | |
36 if (as -> output_format != OUTPUT_DECB) | |
37 { | |
38 skip_operand(p); | |
39 return; | |
40 } | |
41 | |
42 addr = lwasm_parse_expr(as, p); | |
43 if (!addr) | |
44 { | |
45 lwasm_register_error(as, l, "Bad expression"); | |
46 addr = lw_expr_build(lw_expr_type_int, 0); | |
47 } | |
48 lwasm_save_expr(l, 0, addr); | |
49 } | |
50 | |
348
11a95c6414b4
Added third func to instab to split resolve and emit logic
lost@starbug
parents:
347
diff
changeset
|
51 EMITFUNC(pseudo_emit_end) |
347 | 52 { |
53 lw_expr_t addr; | |
54 | |
55 addr = lwasm_fetch_expr(l, 0); | |
56 | |
57 if (addr) | |
58 { | |
59 if (!lw_expr_istype(addr, lw_expr_type_int)) | |
60 lwasm_register_error(as, l, "Exec address not constant!"); | |
61 else | |
62 as -> execaddr = lw_expr_intval(addr); | |
63 } | |
64 as -> endseen = 1; | |
65 } | |
66 | |
67 PARSEFUNC(pseudo_parse_fcb) | |
68 { | |
69 int i = 0; | |
70 lw_expr_t e; | |
71 | |
72 for (;;) | |
73 { | |
74 e = lwasm_parse_expr(as, p); | |
75 if (!e) | |
76 { | |
77 lwasm_register_error(as, l, "Bad expression (#%s)", i); | |
78 break; | |
79 } | |
80 lwasm_save_expr(l, i, e); | |
81 i++; | |
82 } | |
83 | |
84 l -> len = i; | |
85 } | |
86 | |
348
11a95c6414b4
Added third func to instab to split resolve and emit logic
lost@starbug
parents:
347
diff
changeset
|
87 EMITFUNC(pseudo_emit_fcb) |
347 | 88 { |
89 int i; | |
90 lw_expr_t e; | |
91 int v; | |
92 | |
93 for (i = 0; i < l -> len; i++) | |
94 { | |
95 e = lwasm_fetch_expr(l, i); | |
96 lwasm_emitexpr(l, e, 1); | |
97 } | |
98 } | |
99 | |
100 PARSEFUNC(pseudo_parse_fdb) | |
101 { | |
102 int i = 0; | |
103 lw_expr_t e; | |
104 | |
105 for (;;) | |
106 { | |
107 e = lwasm_parse_expr(as, p); | |
108 if (!e) | |
109 { | |
110 lwasm_register_error(as, l, "Bad expression (#%s)", i); | |
111 break; | |
112 } | |
113 lwasm_save_expr(l, i, e); | |
114 i++; | |
115 } | |
116 | |
117 l -> len = i * 2; | |
118 } | |
119 | |
348
11a95c6414b4
Added third func to instab to split resolve and emit logic
lost@starbug
parents:
347
diff
changeset
|
120 EMITFUNC(pseudo_emit_fdb) |
347 | 121 { |
122 int i; | |
123 lw_expr_t e; | |
124 int v; | |
125 | |
126 for (i = 0; i < (l -> len)/2; i++) | |
127 { | |
128 e = lwasm_fetch_expr(l, i); | |
129 lwasm_emitexpr(l, e, 2); | |
130 } | |
131 } | |
132 | |
133 PARSEFUNC(pseudo_parse_fqb) | |
134 { | |
135 int i = 0; | |
136 lw_expr_t e; | |
137 | |
138 for (;;) | |
139 { | |
140 e = lwasm_parse_expr(as, p); | |
141 if (!e) | |
142 { | |
143 lwasm_register_error(as, l, "Bad expression (#%s)", i); | |
144 break; | |
145 } | |
146 lwasm_save_expr(l, i, e); | |
147 i++; | |
148 } | |
149 | |
150 l -> len = i * 4; | |
151 } | |
152 | |
348
11a95c6414b4
Added third func to instab to split resolve and emit logic
lost@starbug
parents:
347
diff
changeset
|
153 EMITFUNC(pseudo_emit_fqb) |
347 | 154 { |
155 int i; | |
156 lw_expr_t e; | |
157 int v; | |
158 | |
159 for (i = 0; i < (l -> len)/4; i++) | |
160 { | |
161 e = lwasm_fetch_expr(l, i); | |
162 lwasm_emitexpr(l, e, 4); | |
163 } | |
164 } | |
349 | 165 |
166 PARSEFUNC(pseudo_parse_fcc) | |
167 { | |
168 char delim; | |
169 int i; | |
170 | |
171 if (!**p) | |
172 { | |
173 lwasm_register_error(as, l, "Bad operand"); | |
174 return; | |
175 } | |
176 | |
177 delim = **p; | |
178 (*p)++; | |
179 | |
180 for (i = 0; (*p)[i] && (*p)[i] != delim; i++) | |
181 /* do nothing */ ; | |
182 | |
183 if ((*p)[i] != delim) | |
184 { | |
185 lwasm_register_error(as, l, "Bad operand"); | |
186 return; | |
187 } | |
188 | |
189 l -> lstr = lw_strndup(*p, i); | |
190 (*p) += i + 1; | |
191 | |
192 l -> len = i; | |
193 } | |
194 | |
195 EMITFUNC(pseudo_emit_fcc) | |
196 { | |
197 int i; | |
198 | |
199 for (i = 0; i < l -> len; i++) | |
200 lwasm_emit(l, l -> lstr[i]); | |
201 } | |
202 | |
203 PARSEFUNC(pseudo_parse_fcs) | |
204 { | |
205 char delim; | |
206 int i; | |
207 | |
208 if (!**p) | |
209 { | |
210 lwasm_register_error(as, l, "Bad operand"); | |
211 return; | |
212 } | |
213 | |
214 delim = **p; | |
215 (*p)++; | |
216 | |
217 for (i = 0; (*p)[i] && (*p)[i] != delim; i++) | |
218 /* do nothing */ ; | |
219 | |
220 if ((*p)[i] != delim) | |
221 { | |
222 lwasm_register_error(as, l, "Bad operand"); | |
223 return; | |
224 } | |
225 | |
226 l -> lstr = lw_strndup(*p, i); | |
227 (*p) += i + 1; | |
228 | |
229 l -> len = i; | |
230 } | |
231 | |
232 EMITFUNC(pseudo_emit_fcs) | |
233 { | |
234 int i; | |
235 | |
236 for (i = 0; i < l -> len - 1; i++) | |
237 lwasm_emit(l, l -> lstr[i]); | |
238 lwasm_emit(l, l -> lstr[i] | 0x80); | |
239 } | |
240 | |
241 PARSEFUNC(pseudo_parse_fcn) | |
242 { | |
243 char delim; | |
244 int i; | |
245 | |
246 if (!**p) | |
247 { | |
248 lwasm_register_error(as, l, "Bad operand"); | |
249 return; | |
250 } | |
251 | |
252 delim = **p; | |
253 (*p)++; | |
254 | |
255 for (i = 0; (*p)[i] && (*p)[i] != delim; i++) | |
256 /* do nothing */ ; | |
257 | |
258 if ((*p)[i] != delim) | |
259 { | |
260 lwasm_register_error(as, l, "Bad operand"); | |
261 return; | |
262 } | |
263 | |
264 l -> lstr = lw_strndup(*p, i); | |
265 (*p) += i + 1; | |
266 | |
267 l -> len = i; | |
268 } | |
269 | |
270 EMITFUNC(pseudo_emit_fcn) | |
271 { | |
272 int i; | |
273 | |
274 for (i = 0; i < l -> len; i++) | |
275 lwasm_emit(l, l -> lstr[i]); | |
276 lwasm_emit(l, 0); | |
277 } | |
278 | |
279 PARSEFUNC(pseudo_parse_rmb) | |
280 { | |
281 lw_expr_t expr; | |
282 | |
283 expr = lwasm_parse_expr(as, p); | |
284 if (!expr) | |
285 { | |
286 lwasm_register_error(as, l, "Bad expression"); | |
287 } | |
288 | |
289 lwasm_save_expr(l, 0, expr); | |
290 } | |
291 | |
292 RESOLVEFUNC(pseudo_resolve_rmb) | |
293 { | |
294 lw_expr_t expr; | |
295 | |
296 if (l -> len >= 0) | |
297 return; | |
298 | |
299 expr = lwasm_fetch_expr(l, 0); | |
300 | |
301 if (lw_expr_istype(expr, lw_expr_type_int)) | |
302 { | |
303 l -> len = lw_expr_intval(expr); | |
304 } | |
305 } | |
306 | |
307 EMITFUNC(pseudo_emit_rmb) | |
308 { | |
309 if (l -> len < 0) | |
310 lwasm_register_error(as, l, "Expression not constant"); | |
311 } | |
312 | |
313 PARSEFUNC(pseudo_parse_rmd) | |
314 { | |
315 lw_expr_t expr; | |
316 | |
317 expr = lwasm_parse_expr(as, p); | |
318 if (!expr) | |
319 { | |
320 lwasm_register_error(as, l, "Bad expression"); | |
321 } | |
322 | |
323 lwasm_save_expr(l, 0, expr); | |
324 } | |
325 | |
326 RESOLVEFUNC(pseudo_resolve_rmd) | |
327 { | |
328 lw_expr_t expr; | |
329 | |
330 if (l -> len >= 0) | |
331 return; | |
332 | |
333 expr = lwasm_fetch_expr(l, 0); | |
334 | |
335 if (lw_expr_istype(expr, lw_expr_type_int)) | |
336 { | |
337 l -> len = lw_expr_intval(expr) * 2; | |
338 } | |
339 } | |
340 | |
341 EMITFUNC(pseudo_emit_rmd) | |
342 { | |
343 if (l -> len < 0) | |
344 lwasm_register_error(as, l, "Expression not constant"); | |
345 } | |
346 | |
347 | |
348 PARSEFUNC(pseudo_parse_rmq) | |
349 { | |
350 lw_expr_t expr; | |
351 | |
352 expr = lwasm_parse_expr(as, p); | |
353 if (!expr) | |
354 { | |
355 lwasm_register_error(as, l, "Bad expression"); | |
356 } | |
357 | |
358 lwasm_save_expr(l, 0, expr); | |
359 } | |
360 | |
361 RESOLVEFUNC(pseudo_resolve_rmq) | |
362 { | |
363 lw_expr_t expr; | |
364 | |
365 if (l -> len >= 0) | |
366 return; | |
367 | |
368 expr = lwasm_fetch_expr(l, 0); | |
369 | |
370 if (lw_expr_istype(expr, lw_expr_type_int)) | |
371 { | |
372 l -> len = lw_expr_intval(expr) * 4; | |
373 } | |
374 } | |
375 | |
376 EMITFUNC(pseudo_emit_rmq) | |
377 { | |
378 if (l -> len < 0) | |
379 lwasm_register_error(as, l, "Expression not constant"); | |
380 } | |
381 | |
382 | |
383 PARSEFUNC(pseudo_parse_zmq) | |
384 { | |
385 lw_expr_t expr; | |
386 | |
387 expr = lwasm_parse_expr(as, p); | |
388 if (!expr) | |
389 { | |
390 lwasm_register_error(as, l, "Bad expression"); | |
391 } | |
392 | |
393 lwasm_save_expr(l, 0, expr); | |
394 } | |
395 | |
396 RESOLVEFUNC(pseudo_resolve_zmq) | |
397 { | |
398 lw_expr_t expr; | |
399 | |
400 if (l -> len >= 0) | |
401 return; | |
402 | |
403 expr = lwasm_fetch_expr(l, 0); | |
404 | |
405 if (lw_expr_istype(expr, lw_expr_type_int)) | |
406 { | |
407 l -> len = lw_expr_intval(expr) * 4; | |
408 } | |
409 } | |
410 | |
411 EMITFUNC(pseudo_emit_zmq) | |
412 { | |
413 int i; | |
414 | |
415 if (l -> len < 0) | |
416 { | |
417 lwasm_register_error(as, l, "Expression not constant"); | |
418 return; | |
419 } | |
420 | |
421 for (i = 0; i < l -> len; i++) | |
422 lwasm_emit(l, 0); | |
423 } | |
424 | |
425 | |
426 PARSEFUNC(pseudo_parse_zmd) | |
427 { | |
428 lw_expr_t expr; | |
429 | |
430 expr = lwasm_parse_expr(as, p); | |
431 if (!expr) | |
432 { | |
433 lwasm_register_error(as, l, "Bad expression"); | |
434 } | |
435 | |
436 lwasm_save_expr(l, 0, expr); | |
437 } | |
438 | |
439 RESOLVEFUNC(pseudo_resolve_zmd) | |
440 { | |
441 lw_expr_t expr; | |
442 | |
443 if (l -> len >= 0) | |
444 return; | |
445 | |
446 expr = lwasm_fetch_expr(l, 0); | |
447 | |
448 if (lw_expr_istype(expr, lw_expr_type_int)) | |
449 { | |
450 l -> len = lw_expr_intval(expr) * 2; | |
451 } | |
452 } | |
453 | |
454 EMITFUNC(pseudo_emit_zmd) | |
455 { | |
456 int i; | |
457 | |
458 if (l -> len < 0) | |
459 { | |
460 lwasm_register_error(as, l, "Expression not constant"); | |
461 return; | |
462 } | |
463 | |
464 for (i = 0; i < l -> len; i++) | |
465 lwasm_emit(l, 0); | |
466 } | |
467 | |
468 PARSEFUNC(pseudo_parse_zmb) | |
469 { | |
470 lw_expr_t expr; | |
471 | |
472 expr = lwasm_parse_expr(as, p); | |
473 if (!expr) | |
474 { | |
475 lwasm_register_error(as, l, "Bad expression"); | |
476 } | |
477 | |
478 lwasm_save_expr(l, 0, expr); | |
479 } | |
480 | |
481 RESOLVEFUNC(pseudo_resolve_zmb) | |
482 { | |
483 lw_expr_t expr; | |
484 | |
485 if (l -> len >= 0) | |
486 return; | |
487 | |
488 expr = lwasm_fetch_expr(l, 0); | |
489 | |
490 if (lw_expr_istype(expr, lw_expr_type_int)) | |
491 { | |
492 l -> len = lw_expr_intval(expr); | |
493 } | |
494 } | |
495 | |
496 EMITFUNC(pseudo_emit_zmb) | |
497 { | |
498 int i; | |
499 | |
500 if (l -> len < 0) | |
501 { | |
502 lwasm_register_error(as, l, "Expression not constant"); | |
503 return; | |
504 } | |
505 | |
506 for (i = 0; i < l -> len; i++) | |
507 lwasm_emit(l, 0); | |
508 } | |
350 | 509 |
510 PARSEFUNC(pseudo_parse_org) | |
511 { | |
512 lw_expr_t e; | |
513 | |
351 | 514 l -> len = 0; |
515 | |
350 | 516 e = lwasm_parse_expr(as, p); |
517 if (!e) | |
518 { | |
519 lwasm_register_error(as, l, "Bad operand"); | |
520 return; | |
521 } | |
522 | |
523 lw_expr_destroy(l -> addr); | |
524 l -> addr = e; | |
525 l -> len = 0; | |
526 } | |
527 | |
528 PARSEFUNC(pseudo_parse_equ) | |
529 { | |
530 lw_expr_t e; | |
531 | |
351 | 532 l -> len = 0; |
533 | |
350 | 534 if (!(l -> sym)) |
535 { | |
536 lwasm_register_error(as, l, "Missing symbol"); | |
537 return; | |
538 } | |
539 | |
540 e = lwasm_parse_expr(as, p); | |
541 if (!e) | |
542 { | |
543 lwasm_register_error(as, l, "Bad operand"); | |
544 return; | |
545 } | |
546 | |
547 register_symbol(as, l, l -> sym, e, symbol_flag_none); | |
548 l -> symset = 1; | |
549 } | |
351 | 550 |
551 PARSEFUNC(pseudo_parse_set) | |
552 { | |
553 lw_expr_t e; | |
554 | |
555 l -> len = 0; | |
556 | |
557 if (!(l -> sym)) | |
558 { | |
559 lwasm_register_error(as, l, "Missing symbol"); | |
560 return; | |
561 } | |
562 | |
563 e = lwasm_parse_expr(as, p); | |
564 if (!e) | |
565 { | |
566 lwasm_register_error(as, l, "Bad operand"); | |
567 return; | |
568 } | |
569 | |
570 register_symbol(as, l, l -> sym, e, symbol_flag_set); | |
571 l -> symset = 1; | |
572 } | |
573 | |
574 PARSEFUNC(pseudo_parse_setdp) | |
575 { | |
576 lw_expr_t e; | |
577 | |
578 l -> len = 0; | |
579 | |
580 if (as -> output_format == OUTPUT_OBJ) | |
581 { | |
582 lwasm_register_error(as, l, "SETDP not permitted for object target"); | |
583 return; | |
584 } | |
585 | |
586 e = lwasm_parse_expr(as, p); | |
587 if (!e) | |
588 { | |
589 lwasm_register_error(as, l, "Bad operand"); | |
590 return; | |
591 } | |
592 | |
593 if (!lw_expr_istype(e, lw_expr_type_int)) | |
594 { | |
595 lwasm_register_error(as, l, "SETDP must be constant on pass 1"); | |
596 return; | |
597 } | |
598 l -> dpval = lw_expr_intval(e) & 0xff; | |
599 } | |
600 | |
601 PARSEFUNC(pseudo_parse_ifp1) | |
602 { | |
603 l -> len = 0; | |
604 | |
605 if (as -> skipcond && !(as -> skipmacro)) | |
606 { | |
607 as -> skipcount++; | |
608 skip_operand(p); | |
609 return; | |
610 } | |
611 | |
612 lwasm_register_warning(as, l, "IFP1 if is not supported; ignoring"); | |
613 | |
614 } | |
615 | |
616 PARSEFUNC(pseudo_parse_ifp2) | |
617 { | |
618 l -> len = 0; | |
619 | |
620 if (as -> skipcond && !(as -> skipmacro)) | |
621 { | |
622 as -> skipcount++; | |
623 skip_operand(p); | |
624 return; | |
625 } | |
626 | |
627 lwasm_register_warning(as, l, "IFP2 if is not supported; ignoring"); | |
628 } | |
629 | |
630 PARSEFUNC(pseudo_parse_ifeq) | |
631 { | |
632 lw_expr_t e; | |
633 | |
634 l -> len = 0; | |
635 | |
636 if (as -> skipcond && !(as -> skipmacro)) | |
637 { | |
638 as -> skipcount++; | |
639 skip_operand(p); | |
640 return; | |
641 } | |
642 | |
643 e = lwasm_parse_expr(as, p); | |
644 if (!e) | |
645 { | |
646 lwasm_register_error(as, l, "Bad expression"); | |
647 return; | |
648 } | |
649 if (!lw_expr_istype(e, lw_expr_type_int)) | |
650 { | |
651 lwasm_register_error(as, l, "Conditions must be constant on pass 1"); | |
652 return; | |
653 } | |
654 if (lw_expr_intval(e) != 0) | |
655 { | |
656 as -> skipcond = 1; | |
657 as -> skipcount = 1; | |
658 } | |
659 } | |
660 | |
661 PARSEFUNC(pseudo_parse_ifne) | |
662 { | |
663 lw_expr_t e; | |
664 | |
665 l -> len = 0; | |
666 | |
667 if (as -> skipcond && !(as -> skipmacro)) | |
668 { | |
669 as -> skipcount++; | |
670 skip_operand(p); | |
671 return; | |
672 } | |
673 | |
674 e = lwasm_parse_expr(as, p); | |
675 if (!e) | |
676 { | |
677 lwasm_register_error(as, l, "Bad expression"); | |
678 return; | |
679 } | |
680 if (!lw_expr_istype(e, lw_expr_type_int)) | |
681 { | |
682 lwasm_register_error(as, l, "Conditions must be constant on pass 1"); | |
683 return; | |
684 } | |
685 if (lw_expr_intval(e) == 0) | |
686 { | |
687 as -> skipcond = 1; | |
688 as -> skipcount = 1; | |
689 } | |
690 } | |
691 | |
692 | |
693 PARSEFUNC(pseudo_parse_ifgt) | |
694 { | |
695 lw_expr_t e; | |
696 | |
697 l -> len = 0; | |
698 | |
699 if (as -> skipcond && !(as -> skipmacro)) | |
700 { | |
701 as -> skipcount++; | |
702 skip_operand(p); | |
703 return; | |
704 } | |
705 | |
706 e = lwasm_parse_expr(as, p); | |
707 if (!e) | |
708 { | |
709 lwasm_register_error(as, l, "Bad expression"); | |
710 return; | |
711 } | |
712 if (!lw_expr_istype(e, lw_expr_type_int)) | |
713 { | |
714 lwasm_register_error(as, l, "Conditions must be constant on pass 1"); | |
715 return; | |
716 } | |
717 if (lw_expr_intval(e) <= 0) | |
718 { | |
719 as -> skipcond = 1; | |
720 as -> skipcount = 1; | |
721 } | |
722 } | |
723 | |
724 PARSEFUNC(pseudo_parse_ifge) | |
725 { | |
726 lw_expr_t e; | |
727 | |
728 l -> len = 0; | |
729 | |
730 if (as -> skipcond && !(as -> skipmacro)) | |
731 { | |
732 as -> skipcount++; | |
733 skip_operand(p); | |
734 return; | |
735 } | |
736 | |
737 e = lwasm_parse_expr(as, p); | |
738 if (!e) | |
739 { | |
740 lwasm_register_error(as, l, "Bad expression"); | |
741 return; | |
742 } | |
743 if (!lw_expr_istype(e, lw_expr_type_int)) | |
744 { | |
745 lwasm_register_error(as, l, "Conditions must be constant on pass 1"); | |
746 return; | |
747 } | |
748 if (lw_expr_intval(e) < 0) | |
749 { | |
750 as -> skipcond = 1; | |
751 as -> skipcount = 1; | |
752 } | |
753 } | |
754 | |
755 PARSEFUNC(pseudo_parse_iflt) | |
756 { | |
757 lw_expr_t e; | |
758 | |
759 l -> len = 0; | |
760 | |
761 if (as -> skipcond && !(as -> skipmacro)) | |
762 { | |
763 as -> skipcount++; | |
764 skip_operand(p); | |
765 return; | |
766 } | |
767 | |
768 e = lwasm_parse_expr(as, p); | |
769 if (!e) | |
770 { | |
771 lwasm_register_error(as, l, "Bad expression"); | |
772 return; | |
773 } | |
774 if (!lw_expr_istype(e, lw_expr_type_int)) | |
775 { | |
776 lwasm_register_error(as, l, "Conditions must be constant on pass 1"); | |
777 return; | |
778 } | |
779 if (lw_expr_intval(e) >= 0) | |
780 { | |
781 as -> skipcond = 1; | |
782 as -> skipcount = 1; | |
783 } | |
784 } | |
785 | |
786 PARSEFUNC(pseudo_parse_ifle) | |
787 { | |
788 lw_expr_t e; | |
789 | |
790 l -> len = 0; | |
791 | |
792 if (as -> skipcond && !(as -> skipmacro)) | |
793 { | |
794 as -> skipcount++; | |
795 skip_operand(p); | |
796 return; | |
797 } | |
798 | |
799 e = lwasm_parse_expr(as, p); | |
800 if (!e) | |
801 { | |
802 lwasm_register_error(as, l, "Bad expression"); | |
803 return; | |
804 } | |
805 if (!lw_expr_istype(e, lw_expr_type_int)) | |
806 { | |
807 lwasm_register_error(as, l, "Conditions must be constant on pass 1"); | |
808 return; | |
809 } | |
810 if (lw_expr_intval(e) > 0) | |
811 { | |
812 as -> skipcond = 1; | |
813 as -> skipcount = 1; | |
814 } | |
815 } | |
816 | |
817 PARSEFUNC(pseudo_parse_endc) | |
818 { | |
819 l -> len = 0; | |
820 if (as -> skipcond && !(as -> skipmacro)) | |
821 { | |
822 as -> skipcount--; | |
823 if (as -> skipcount < 0) | |
824 as -> skipcond = 0; | |
825 } | |
826 } | |
827 | |
828 PARSEFUNC(pseudo_parse_else) | |
829 { | |
830 l -> len = 0; | |
831 | |
832 if (as -> skipmacro) | |
833 return; | |
834 | |
835 if (as -> skipcond) | |
836 { | |
837 if (as -> skipcount == 1) | |
838 { | |
839 as -> skipcount = 0; | |
840 as -> skipcond = 0; | |
841 } | |
842 return; | |
843 } | |
844 as -> skipcond = 1; | |
845 as -> skipcount = 1; | |
846 } | |
847 | |
848 PARSEFUNC(pseudo_parse_ifdef) | |
849 { | |
850 char *sym; | |
851 int i; | |
852 struct symtabe *s; | |
853 | |
854 l -> len = 0; | |
855 | |
856 if (as -> skipcond && !(as -> skipmacro)) | |
857 { | |
858 as -> skipcount++; | |
859 skip_operand(p); | |
860 return; | |
861 } | |
862 | |
863 for (i = 0; (*p)[i] && !isspace((*p)[i]); i++) | |
864 /* do nothing */ ; | |
865 | |
866 sym = lw_strndup(*p, i); | |
867 | |
868 s = lookup_symbol(as, l, sym, -1, -1); | |
869 | |
870 lw_free(sym); | |
871 | |
872 if (!s) | |
873 { | |
874 as -> skipcond = 1; | |
875 as -> skipcount = 1; | |
876 } | |
877 } | |
878 | |
879 PARSEFUNC(pseudo_parse_ifndef) | |
880 { | |
881 char *sym; | |
882 int i; | |
883 struct symtabe *s; | |
884 | |
885 l -> len = 0; | |
886 | |
887 if (as -> skipcond && !(as -> skipmacro)) | |
888 { | |
889 as -> skipcount++; | |
890 skip_operand(p); | |
891 return; | |
892 } | |
893 | |
894 for (i = 0; (*p)[i] && !isspace((*p)[i]); i++) | |
895 /* do nothing */ ; | |
896 | |
897 sym = lw_strndup(*p, i); | |
898 | |
899 s = lookup_symbol(as, l, sym, -1, -1); | |
900 | |
901 lw_free(sym); | |
902 | |
903 if (s) | |
904 { | |
905 as -> skipcond = 1; | |
906 as -> skipcount = 1; | |
907 } | |
908 } | |
909 | |
354 | 910 PARSEFUNC(pseudo_parse_error) |
911 { | |
912 lwasm_register_error(as, l, "User error: %s", *p); | |
913 skip_operand(p); | |
914 } |