Mercurial > hg > index.cgi
comparison lwasm/pseudo.c @ 370:8764142b3192
Convert internal error/warning handling framework to a new unified system
Replace the ad hoc error and warning handling with a new system that
codifies the errors with specific codes. This makes it possible in the
future for error numbers to be used for testing and other purposes. It also
makes sure the error strings themselves are consistent.
Thanks to Erik G <erik@6809.org> for the patch.
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 22 Jun 2015 18:49:38 -0600 |
parents | f318407d2469 |
children | 8e25147c2aa8 |
comparison
equal
deleted
inserted
replaced
369:682524a1f32f | 370:8764142b3192 |
---|---|
112 { | 112 { |
113 addr = lwasm_parse_expr(as, p); | 113 addr = lwasm_parse_expr(as, p); |
114 } | 114 } |
115 if (!addr) | 115 if (!addr) |
116 { | 116 { |
117 lwasm_register_error(as, l, "Bad expression"); | 117 lwasm_register_error(as, as->cl, E_EXPRESSION_BAD); |
118 addr = lw_expr_build(lw_expr_type_int, 0); | 118 addr = lw_expr_build(lw_expr_type_int, 0); |
119 } | 119 } |
120 lwasm_save_expr(l, 0, addr); | 120 lwasm_save_expr(l, 0, addr); |
121 } | 121 } |
122 | 122 |
127 addr = lwasm_fetch_expr(l, 0); | 127 addr = lwasm_fetch_expr(l, 0); |
128 | 128 |
129 if (addr) | 129 if (addr) |
130 { | 130 { |
131 if (!lw_expr_istype(addr, lw_expr_type_int)) | 131 if (!lw_expr_istype(addr, lw_expr_type_int)) |
132 lwasm_register_error(as, l, "Exec address not constant!"); | 132 lwasm_register_error(as, l, E_EXEC_ADDRESS); |
133 else | 133 else |
134 as -> execaddr = lw_expr_intval(addr); | 134 as -> execaddr = lw_expr_intval(addr); |
135 } | 135 } |
136 as -> endseen = 1; | 136 as -> endseen = 1; |
137 } | 137 } |
144 for (;;) | 144 for (;;) |
145 { | 145 { |
146 e = lwasm_parse_expr(as, p); | 146 e = lwasm_parse_expr(as, p); |
147 if (!e) | 147 if (!e) |
148 { | 148 { |
149 lwasm_register_error(as, l, "Bad expression (#%d)", i); | 149 lwasm_register_error2(as, l, E_EXPRESSION_BAD, "(#%d)", i); |
150 break; | 150 break; |
151 } | 151 } |
152 lwasm_save_expr(l, i++, e); | 152 lwasm_save_expr(l, i++, e); |
153 if (**p != ',') | 153 if (**p != ',') |
154 break; | 154 break; |
179 for (;;) | 179 for (;;) |
180 { | 180 { |
181 e = lwasm_parse_expr(as, p); | 181 e = lwasm_parse_expr(as, p); |
182 if (!e) | 182 if (!e) |
183 { | 183 { |
184 lwasm_register_error(as, l, "Bad expression (#%d)", i); | 184 lwasm_register_error2(as, l, E_EXPRESSION_BAD, "(#%d)", i); |
185 break; | 185 break; |
186 } | 186 } |
187 lwasm_save_expr(l, i++, e); | 187 lwasm_save_expr(l, i++, e); |
188 if (**p != ',') | 188 if (**p != ',') |
189 break; | 189 break; |
214 for (;;) | 214 for (;;) |
215 { | 215 { |
216 e = lwasm_parse_expr(as, p); | 216 e = lwasm_parse_expr(as, p); |
217 if (!e) | 217 if (!e) |
218 { | 218 { |
219 lwasm_register_error(as, l, "Bad expression (#%d)", i); | 219 lwasm_register_error2(as, l, E_EXPRESSION_BAD, "(#%d)", i); |
220 break; | 220 break; |
221 } | 221 } |
222 lwasm_save_expr(l, i++, e); | 222 lwasm_save_expr(l, i++, e); |
223 if (**p != ',') | 223 if (**p != ',') |
224 break; | 224 break; |
257 for (;;) | 257 for (;;) |
258 { | 258 { |
259 e = lwasm_parse_expr(as, p); | 259 e = lwasm_parse_expr(as, p); |
260 if (!e) | 260 if (!e) |
261 { | 261 { |
262 lwasm_register_error(as, l, "Bad expression (#%d)", i); | 262 lwasm_register_error2(as, l, E_EXPRESSION_BAD, "(#%d)", i); |
263 break; | 263 break; |
264 } | 264 } |
265 lwasm_save_expr(l, i++, e); | 265 lwasm_save_expr(l, i++, e); |
266 if (**p != ',') | 266 if (**p != ',') |
267 break; | 267 break; |
420 char delim; | 420 char delim; |
421 int i; | 421 int i; |
422 | 422 |
423 if (!**p) | 423 if (!**p) |
424 { | 424 { |
425 lwasm_register_error(as, l, "Bad operand"); | 425 lwasm_register_error(as, l, E_OPERAND_BAD); |
426 return; | 426 return; |
427 } | 427 } |
428 | 428 |
429 delim = **p; | 429 delim = **p; |
430 (*p)++; | 430 (*p)++; |
432 | 432 |
433 i = cstringlen(as, l, p, delim); | 433 i = cstringlen(as, l, p, delim); |
434 | 434 |
435 if (**p != delim) | 435 if (**p != delim) |
436 { | 436 { |
437 lwasm_register_error(as, l, "Bad operand"); | 437 lwasm_register_error(as, l, E_OPERAND_BAD); |
438 return; | 438 return; |
439 } | 439 } |
440 (*p)++; | 440 (*p)++; |
441 l -> len = i; | 441 l -> len = i; |
442 } | 442 } |
454 char delim; | 454 char delim; |
455 int i; | 455 int i; |
456 | 456 |
457 if (!**p) | 457 if (!**p) |
458 { | 458 { |
459 lwasm_register_error(as, l, "Bad operand"); | 459 lwasm_register_error(as, l, E_OPERAND_BAD); |
460 return; | 460 return; |
461 } | 461 } |
462 | 462 |
463 delim = **p; | 463 delim = **p; |
464 (*p)++; | 464 (*p)++; |
465 | 465 |
466 i = cstringlen(as, l, p, delim); | 466 i = cstringlen(as, l, p, delim); |
467 | 467 |
468 if (**p != delim) | 468 if (**p != delim) |
469 { | 469 { |
470 lwasm_register_error(as, l, "Bad operand"); | 470 lwasm_register_error(as, l, E_OPERAND_BAD); |
471 return; | 471 return; |
472 } | 472 } |
473 (*p)++; | 473 (*p)++; |
474 l -> len = i; | 474 l -> len = i; |
475 } | 475 } |
488 char delim; | 488 char delim; |
489 int i; | 489 int i; |
490 | 490 |
491 if (!**p) | 491 if (!**p) |
492 { | 492 { |
493 lwasm_register_error(as, l, "Bad operand"); | 493 lwasm_register_error(as, l, E_OPERAND_BAD); |
494 return; | 494 return; |
495 } | 495 } |
496 | 496 |
497 delim = **p; | 497 delim = **p; |
498 (*p)++; | 498 (*p)++; |
499 | 499 |
500 i = cstringlen(as, l, p, delim); | 500 i = cstringlen(as, l, p, delim); |
501 | 501 |
502 if (**p != delim) | 502 if (**p != delim) |
503 { | 503 { |
504 lwasm_register_error(as, l, "Bad operand"); | 504 lwasm_register_error(as, l, E_OPERAND_BAD); |
505 return; | 505 return; |
506 } | 506 } |
507 (*p)++; | 507 (*p)++; |
508 l -> len = i + 1; | 508 l -> len = i + 1; |
509 } | 509 } |
522 lw_expr_t expr; | 522 lw_expr_t expr; |
523 | 523 |
524 expr = lwasm_parse_expr(as, p); | 524 expr = lwasm_parse_expr(as, p); |
525 if (!expr) | 525 if (!expr) |
526 { | 526 { |
527 lwasm_register_error(as, l, "Bad expression"); | 527 lwasm_register_error(as, l, E_EXPRESSION_BAD); |
528 } | 528 } |
529 | 529 |
530 l -> lint = 0; | 530 l -> lint = 0; |
531 if (as -> instruct) | 531 if (as -> instruct) |
532 { | 532 { |
533 lwasm_reduce_expr(as, expr); | 533 lwasm_reduce_expr(as, expr); |
534 if (!lw_expr_istype(expr, lw_expr_type_int)) | 534 if (!lw_expr_istype(expr, lw_expr_type_int)) |
535 { | 535 { |
536 lwasm_register_error(as, l, "Expression must be constant at parse time"); | 536 lwasm_register_error(as, l, E_EXPRESSION_NOT_CONST); |
537 } | 537 } |
538 else | 538 else |
539 { | 539 { |
540 int e; | 540 int e; |
541 e = lw_expr_intval(expr); | 541 e = lw_expr_intval(expr); |
578 | 578 |
579 if (lw_expr_istype(expr, lw_expr_type_int)) | 579 if (lw_expr_istype(expr, lw_expr_type_int)) |
580 { | 580 { |
581 if (lw_expr_intval(expr) < 0) | 581 if (lw_expr_intval(expr) < 0) |
582 { | 582 { |
583 lwasm_register_error(as, l, "Negative reservation sizes make no sense! (%d)", lw_expr_intval(expr)); | 583 lwasm_register_error2(as, l, E_NEGATIVE_RESERVATION, "(%d)", lw_expr_intval(expr)); |
584 l -> len = 0; | 584 l -> len = 0; |
585 l -> dlen = 0; | 585 l -> dlen = 0; |
586 return; | 586 return; |
587 } | 587 } |
588 if (l -> inmod) | 588 if (l -> inmod) |
596 { | 596 { |
597 if (l -> lint) | 597 if (l -> lint) |
598 return; | 598 return; |
599 | 599 |
600 if (l -> len < 0 || l -> dlen < 0) | 600 if (l -> len < 0 || l -> dlen < 0) |
601 lwasm_register_error(as, l, "Expression not constant: %d %d", l -> len, l -> dlen); | 601 lwasm_register_error2(as, l, E_EXPRESSION_NOT_CONST, "%d %d", l -> len, l -> dlen); |
602 } | 602 } |
603 | 603 |
604 PARSEFUNC(pseudo_parse_rmd) | 604 PARSEFUNC(pseudo_parse_rmd) |
605 { | 605 { |
606 lw_expr_t expr; | 606 lw_expr_t expr; |
607 | 607 |
608 l -> lint = 0; | 608 l -> lint = 0; |
609 expr = lwasm_parse_expr(as, p); | 609 expr = lwasm_parse_expr(as, p); |
610 if (!expr) | 610 if (!expr) |
611 { | 611 { |
612 lwasm_register_error(as, l, "Bad expression"); | 612 lwasm_register_error(as, l, E_EXPRESSION_BAD); |
613 } | 613 } |
614 | 614 |
615 if (as -> instruct) | 615 if (as -> instruct) |
616 { | 616 { |
617 lwasm_reduce_expr(as, expr); | 617 lwasm_reduce_expr(as, expr); |
618 if (!lw_expr_istype(expr, lw_expr_type_int)) | 618 if (!lw_expr_istype(expr, lw_expr_type_int)) |
619 { | 619 { |
620 lwasm_register_error(as, l, "Expression must be constant at parse time"); | 620 lwasm_register_error(as, l, E_EXPRESSION_NOT_CONST); |
621 } | 621 } |
622 else | 622 else |
623 { | 623 { |
624 int e; | 624 int e; |
625 e = lw_expr_intval(expr) * 2; | 625 e = lw_expr_intval(expr) * 2; |
662 | 662 |
663 if (lw_expr_istype(expr, lw_expr_type_int)) | 663 if (lw_expr_istype(expr, lw_expr_type_int)) |
664 { | 664 { |
665 if (lw_expr_intval(expr) < 0) | 665 if (lw_expr_intval(expr) < 0) |
666 { | 666 { |
667 lwasm_register_error(as, l, "Negative reservation sizes make no sense! (%d)", lw_expr_intval(expr)); | 667 lwasm_register_error2(as, l, E_NEGATIVE_RESERVATION, "(%d)", lw_expr_intval(expr)); |
668 l -> len = 0; | 668 l -> len = 0; |
669 l -> dlen = 0; | 669 l -> dlen = 0; |
670 return; | 670 return; |
671 } | 671 } |
672 if (l -> inmod) | 672 if (l -> inmod) |
680 { | 680 { |
681 if (l -> lint) | 681 if (l -> lint) |
682 return; | 682 return; |
683 | 683 |
684 if (l -> len < 0 || l -> dlen < 0) | 684 if (l -> len < 0 || l -> dlen < 0) |
685 lwasm_register_error(as, l, "Expression not constant"); | 685 lwasm_register_error(as, l, E_EXPRESSION_NOT_CONST); |
686 } | 686 } |
687 | 687 |
688 | 688 |
689 PARSEFUNC(pseudo_parse_rmq) | 689 PARSEFUNC(pseudo_parse_rmq) |
690 { | 690 { |
692 | 692 |
693 l -> lint = 0; | 693 l -> lint = 0; |
694 expr = lwasm_parse_expr(as, p); | 694 expr = lwasm_parse_expr(as, p); |
695 if (!expr) | 695 if (!expr) |
696 { | 696 { |
697 lwasm_register_error(as, l, "Bad expression"); | 697 lwasm_register_error(as, l, E_EXPRESSION_BAD); |
698 } | 698 } |
699 if (as -> instruct) | 699 if (as -> instruct) |
700 { | 700 { |
701 lwasm_reduce_expr(as, expr); | 701 lwasm_reduce_expr(as, expr); |
702 if (!lw_expr_istype(expr, lw_expr_type_int)) | 702 if (!lw_expr_istype(expr, lw_expr_type_int)) |
703 { | 703 { |
704 lwasm_register_error(as, l, "Expression must be constant at parse time"); | 704 lwasm_register_error(as, l, E_EXPRESSION_NOT_CONST); |
705 } | 705 } |
706 else | 706 else |
707 { | 707 { |
708 int e; | 708 int e; |
709 e = lw_expr_intval(expr) * 4; | 709 e = lw_expr_intval(expr) * 4; |
746 | 746 |
747 if (lw_expr_istype(expr, lw_expr_type_int)) | 747 if (lw_expr_istype(expr, lw_expr_type_int)) |
748 { | 748 { |
749 if (lw_expr_intval(expr) < 0) | 749 if (lw_expr_intval(expr) < 0) |
750 { | 750 { |
751 lwasm_register_error(as, l, "Negative reservation sizes make no sense! (%d)", lw_expr_intval(expr)); | 751 lwasm_register_error2(as, l, E_NEGATIVE_RESERVATION, "(%d)", lw_expr_intval(expr)); |
752 l -> len = 0; | 752 l -> len = 0; |
753 l -> dlen = 0; | 753 l -> dlen = 0; |
754 return; | 754 return; |
755 } | 755 } |
756 if (l -> inmod) | 756 if (l -> inmod) |
764 { | 764 { |
765 if (l -> lint) | 765 if (l -> lint) |
766 return; | 766 return; |
767 | 767 |
768 if (l -> len < 0 || l -> dlen < 0) | 768 if (l -> len < 0 || l -> dlen < 0) |
769 lwasm_register_error(as, l, "Expression not constant"); | 769 lwasm_register_error(as, l, E_EXPRESSION_NOT_CONST); |
770 } | 770 } |
771 | 771 |
772 | 772 |
773 PARSEFUNC(pseudo_parse_zmq) | 773 PARSEFUNC(pseudo_parse_zmq) |
774 { | 774 { |
775 lw_expr_t expr; | 775 lw_expr_t expr; |
776 | 776 |
777 expr = lwasm_parse_expr(as, p); | 777 expr = lwasm_parse_expr(as, p); |
778 if (!expr) | 778 if (!expr) |
779 { | 779 { |
780 lwasm_register_error(as, l, "Bad expression"); | 780 lwasm_register_error(as, l, E_EXPRESSION_BAD); |
781 } | 781 } |
782 | 782 |
783 lwasm_save_expr(l, 0, expr); | 783 lwasm_save_expr(l, 0, expr); |
784 } | 784 } |
785 | 785 |
794 | 794 |
795 if (lw_expr_istype(expr, lw_expr_type_int)) | 795 if (lw_expr_istype(expr, lw_expr_type_int)) |
796 { | 796 { |
797 if (lw_expr_intval(expr) < 0) | 797 if (lw_expr_intval(expr) < 0) |
798 { | 798 { |
799 lwasm_register_error(as, l, "Negative block sizes make no sense! (%d)", lw_expr_intval(expr)); | 799 lwasm_register_error2(as, l, E_NEGATIVE_BLOCKSIZE, "(%d)", lw_expr_intval(expr)); |
800 l -> len = 0; | 800 l -> len = 0; |
801 return; | 801 return; |
802 } | 802 } |
803 l -> len = lw_expr_intval(expr) * 4; | 803 l -> len = lw_expr_intval(expr) * 4; |
804 } | 804 } |
808 { | 808 { |
809 int i; | 809 int i; |
810 | 810 |
811 if (l -> len < 0) | 811 if (l -> len < 0) |
812 { | 812 { |
813 lwasm_register_error(as, l, "Expression not constant"); | 813 lwasm_register_error(as, l, E_EXPRESSION_NOT_CONST); |
814 return; | 814 return; |
815 } | 815 } |
816 | 816 |
817 for (i = 0; i < l -> len; i++) | 817 for (i = 0; i < l -> len; i++) |
818 lwasm_emit(l, 0); | 818 lwasm_emit(l, 0); |
824 lw_expr_t expr; | 824 lw_expr_t expr; |
825 | 825 |
826 expr = lwasm_parse_expr(as, p); | 826 expr = lwasm_parse_expr(as, p); |
827 if (!expr) | 827 if (!expr) |
828 { | 828 { |
829 lwasm_register_error(as, l, "Bad expression"); | 829 lwasm_register_error(as, l, E_EXPRESSION_BAD); |
830 } | 830 } |
831 | 831 |
832 lwasm_save_expr(l, 0, expr); | 832 lwasm_save_expr(l, 0, expr); |
833 } | 833 } |
834 | 834 |
843 | 843 |
844 if (lw_expr_istype(expr, lw_expr_type_int)) | 844 if (lw_expr_istype(expr, lw_expr_type_int)) |
845 { | 845 { |
846 if (lw_expr_intval(expr) < 0) | 846 if (lw_expr_intval(expr) < 0) |
847 { | 847 { |
848 lwasm_register_error(as, l, "Negative block sizes make no sense! (%d)", lw_expr_intval(expr)); | 848 lwasm_register_error2(as, l, E_NEGATIVE_BLOCKSIZE, "(%d)", lw_expr_intval(expr)); |
849 l -> len = 0; | 849 l -> len = 0; |
850 return; | 850 return; |
851 } | 851 } |
852 l -> len = lw_expr_intval(expr) * 2; | 852 l -> len = lw_expr_intval(expr) * 2; |
853 } | 853 } |
857 { | 857 { |
858 int i; | 858 int i; |
859 | 859 |
860 if (l -> len < 0) | 860 if (l -> len < 0) |
861 { | 861 { |
862 lwasm_register_error(as, l, "Expression not constant"); | 862 lwasm_register_error(as, l, E_EXPRESSION_NOT_CONST); |
863 return; | 863 return; |
864 } | 864 } |
865 | 865 |
866 for (i = 0; i < l -> len; i++) | 866 for (i = 0; i < l -> len; i++) |
867 lwasm_emit(l, 0); | 867 lwasm_emit(l, 0); |
872 lw_expr_t expr; | 872 lw_expr_t expr; |
873 | 873 |
874 expr = lwasm_parse_expr(as, p); | 874 expr = lwasm_parse_expr(as, p); |
875 if (!expr) | 875 if (!expr) |
876 { | 876 { |
877 lwasm_register_error(as, l, "Bad expression"); | 877 lwasm_register_error(as, l, E_EXPRESSION_BAD); |
878 } | 878 } |
879 | 879 |
880 lwasm_save_expr(l, 0, expr); | 880 lwasm_save_expr(l, 0, expr); |
881 } | 881 } |
882 | 882 |
891 | 891 |
892 if (lw_expr_istype(expr, lw_expr_type_int)) | 892 if (lw_expr_istype(expr, lw_expr_type_int)) |
893 { | 893 { |
894 if (lw_expr_intval(expr) < 0) | 894 if (lw_expr_intval(expr) < 0) |
895 { | 895 { |
896 lwasm_register_error(as, l, "Negative block sizes make no sense! (%d)", lw_expr_intval(expr)); | 896 lwasm_register_error2(as, l, E_NEGATIVE_BLOCKSIZE, "(%d)", lw_expr_intval(expr)); |
897 l -> len = 0; | 897 l -> len = 0; |
898 return; | 898 return; |
899 } | 899 } |
900 l -> len = lw_expr_intval(expr); | 900 l -> len = lw_expr_intval(expr); |
901 } | 901 } |
905 { | 905 { |
906 int i; | 906 int i; |
907 | 907 |
908 if (l -> len < 0) | 908 if (l -> len < 0) |
909 { | 909 { |
910 lwasm_register_error(as, l, "Expression not constant"); | 910 lwasm_register_error(as, l, E_EXPRESSION_NOT_CONST); |
911 return; | 911 return; |
912 } | 912 } |
913 | 913 |
914 for (i = 0; i < l -> len; i++) | 914 for (i = 0; i < l -> len; i++) |
915 lwasm_emit(l, 0); | 915 lwasm_emit(l, 0); |
922 l -> len = 0; | 922 l -> len = 0; |
923 | 923 |
924 e = lwasm_parse_expr(as, p); | 924 e = lwasm_parse_expr(as, p); |
925 if (!e) | 925 if (!e) |
926 { | 926 { |
927 lwasm_register_error(as, l, "Bad operand"); | 927 lwasm_register_error(as, l, E_OPERAND_BAD); |
928 return; | 928 return; |
929 } | 929 } |
930 | 930 |
931 lw_expr_destroy(l -> daddr); | 931 lw_expr_destroy(l -> daddr); |
932 l -> daddr = e; | 932 l -> daddr = e; |
945 | 945 |
946 l -> len = 0; | 946 l -> len = 0; |
947 | 947 |
948 if (!(l -> sym)) | 948 if (!(l -> sym)) |
949 { | 949 { |
950 lwasm_register_error(as, l, "Missing symbol"); | 950 lwasm_register_error(as, l, E_SYMBOL_MISSING); |
951 return; | 951 return; |
952 } | 952 } |
953 | 953 |
954 e = lwasm_parse_expr(as, p); | 954 e = lwasm_parse_expr(as, p); |
955 if (!e) | 955 if (!e) |
956 { | 956 { |
957 lwasm_register_error(as, l, "Bad operand"); | 957 lwasm_register_error(as, l, E_OPERAND_BAD); |
958 return; | 958 return; |
959 } | 959 } |
960 | 960 |
961 register_symbol(as, l, l -> sym, e, symbol_flag_none); | 961 register_symbol(as, l, l -> sym, e, symbol_flag_none); |
962 l -> symset = 1; | 962 l -> symset = 1; |
970 | 970 |
971 l -> len = 0; | 971 l -> len = 0; |
972 | 972 |
973 if (!(l -> sym)) | 973 if (!(l -> sym)) |
974 { | 974 { |
975 lwasm_register_error(as, l, "Missing symbol"); | 975 lwasm_register_error(as, l, E_SYMBOL_MISSING); |
976 return; | 976 return; |
977 } | 977 } |
978 | 978 |
979 e = lwasm_parse_expr(as, p); | 979 e = lwasm_parse_expr(as, p); |
980 if (!e) | 980 if (!e) |
981 { | 981 { |
982 lwasm_register_error(as, l, "Bad operand"); | 982 lwasm_register_error(as, l, E_OPERAND_BAD); |
983 return; | 983 return; |
984 } | 984 } |
985 | 985 |
986 register_symbol(as, l, l -> sym, e, symbol_flag_set); | 986 register_symbol(as, l, l -> sym, e, symbol_flag_set); |
987 l -> symset = 1; | 987 l -> symset = 1; |
995 | 995 |
996 l -> len = 0; | 996 l -> len = 0; |
997 | 997 |
998 if (as -> output_format == OUTPUT_OBJ) | 998 if (as -> output_format == OUTPUT_OBJ) |
999 { | 999 { |
1000 lwasm_register_error(as, l, "SETDP not permitted for object target"); | 1000 lwasm_register_error(as, l, E_SETDP_INVALID); |
1001 return; | 1001 return; |
1002 } | 1002 } |
1003 | 1003 |
1004 e = lwasm_parse_expr(as, p); | 1004 e = lwasm_parse_expr(as, p); |
1005 if (!e) | 1005 if (!e) |
1006 { | 1006 { |
1007 lwasm_register_error(as, l, "Bad operand"); | 1007 lwasm_register_error(as, l, E_OPERAND_BAD); |
1008 return; | 1008 return; |
1009 } | 1009 } |
1010 | 1010 |
1011 // try simplifying the expression and see if it turns into an int | 1011 // try simplifying the expression and see if it turns into an int |
1012 lwasm_reduce_expr(as, e); | 1012 lwasm_reduce_expr(as, e); |
1013 if (!lw_expr_istype(e, lw_expr_type_int)) | 1013 if (!lw_expr_istype(e, lw_expr_type_int)) |
1014 { | 1014 { |
1015 lwasm_register_error(as, l, "SETDP must be constant on pass 1"); | 1015 lwasm_register_error(as, l, E_SETDP_NOT_CONST); |
1016 lw_expr_destroy(e); | 1016 lw_expr_destroy(e); |
1017 return; | 1017 return; |
1018 } | 1018 } |
1019 l -> dpval = lw_expr_intval(e) & 0xff; | 1019 l -> dpval = lw_expr_intval(e) & 0xff; |
1020 lw_expr_destroy(e); | 1020 lw_expr_destroy(e); |
1032 as -> skipcount++; | 1032 as -> skipcount++; |
1033 skip_operand(p); | 1033 skip_operand(p); |
1034 return; | 1034 return; |
1035 } | 1035 } |
1036 | 1036 |
1037 lwasm_register_warning(as, l, "IFP1 if is not supported; ignoring"); | 1037 lwasm_register_error2(as, l, W_NOT_SUPPORTED, "%s", "IFP1"); |
1038 | |
1039 } | 1038 } |
1040 | 1039 |
1041 PARSEFUNC(pseudo_parse_ifp2) | 1040 PARSEFUNC(pseudo_parse_ifp2) |
1042 { | 1041 { |
1043 l -> len = 0; | 1042 l -> len = 0; |
1048 as -> skipcount++; | 1047 as -> skipcount++; |
1049 skip_operand(p); | 1048 skip_operand(p); |
1050 return; | 1049 return; |
1051 } | 1050 } |
1052 | 1051 |
1053 lwasm_register_warning(as, l, "IFP2 if is not supported; ignoring"); | 1052 lwasm_register_error2(as, l, W_NOT_SUPPORTED, "%s", "IFP2"); |
1054 } | 1053 } |
1055 | 1054 |
1056 PARSEFUNC(pseudo_parse_ifeq) | 1055 PARSEFUNC(pseudo_parse_ifeq) |
1057 { | 1056 { |
1058 lw_expr_t e; | 1057 lw_expr_t e; |
1306 } | 1305 } |
1307 } | 1306 } |
1308 | 1307 |
1309 PARSEFUNC(pseudo_parse_error) | 1308 PARSEFUNC(pseudo_parse_error) |
1310 { | 1309 { |
1311 lwasm_register_error(as, l, "User error: %s", *p); | 1310 lwasm_register_error2(as, l, E_USER_SPECIFIED, "%s", *p); |
1312 skip_operand(p); | 1311 skip_operand(p); |
1313 } | 1312 } |
1314 | 1313 |
1315 PARSEFUNC(pseudo_parse_warning) | 1314 PARSEFUNC(pseudo_parse_warning) |
1316 { | 1315 { |
1317 lwasm_register_warning(as, l, "User warning: %s", *p); | 1316 lwasm_register_error2(as, l, W_USER_SPECIFIED, "%s", *p); |
1318 l -> len = 0; | 1317 l -> len = 0; |
1319 skip_operand(p); | 1318 skip_operand(p); |
1320 } | 1319 } |
1321 | 1320 |
1322 PARSEFUNC(pseudo_parse_includebin) | 1321 PARSEFUNC(pseudo_parse_includebin) |
1327 long flen; | 1326 long flen; |
1328 char *rfn; | 1327 char *rfn; |
1329 | 1328 |
1330 if (!**p) | 1329 if (!**p) |
1331 { | 1330 { |
1332 lwasm_register_error(as, l, "Missing filename"); | 1331 lwasm_register_error(as, l, E_FILENAME_MISSING); |
1333 return; | 1332 return; |
1334 } | 1333 } |
1335 | 1334 |
1336 if (**p == '"' || **p == '\'') | 1335 if (**p == '"' || **p == '\'') |
1337 { | 1336 { |
1352 (*p)++; | 1351 (*p)++; |
1353 | 1352 |
1354 fp = input_open_standalone(as, fn, &rfn); | 1353 fp = input_open_standalone(as, fn, &rfn); |
1355 if (!fp) | 1354 if (!fp) |
1356 { | 1355 { |
1357 lwasm_register_error(as, l, "Cannot open file"); | 1356 lwasm_register_error(as, l, E_FILE_OPEN); |
1358 lw_free(fn); | 1357 lw_free(fn); |
1359 return; | 1358 return; |
1360 } | 1359 } |
1361 | 1360 |
1362 l -> lstr = rfn; | 1361 l -> lstr = rfn; |
1374 int c; | 1373 int c; |
1375 | 1374 |
1376 fp = fopen(l -> lstr, "rb"); | 1375 fp = fopen(l -> lstr, "rb"); |
1377 if (!fp) | 1376 if (!fp) |
1378 { | 1377 { |
1379 lwasm_register_error(as, l, "Cannot open file (emit)!"); | 1378 lwasm_register_error2(as, l, E_FILE_OPEN, "%s", "(emit)!"); |
1380 return; | 1379 return; |
1381 } | 1380 } |
1382 | 1381 |
1383 for (;;) | 1382 for (;;) |
1384 { | 1383 { |
1400 int len; | 1399 int len; |
1401 char buf[110]; | 1400 char buf[110]; |
1402 | 1401 |
1403 if (!**p) | 1402 if (!**p) |
1404 { | 1403 { |
1405 lwasm_register_error(as, l, "Missing filename"); | 1404 lwasm_register_error(as, l, E_FILENAME_MISSING); |
1406 return; | 1405 return; |
1407 } | 1406 } |
1408 | 1407 |
1409 if (**p == '"' || **p == '\'') | 1408 if (**p == '"' || **p == '\'') |
1410 { | 1409 { |
1444 PARSEFUNC(pseudo_parse_align) | 1443 PARSEFUNC(pseudo_parse_align) |
1445 { | 1444 { |
1446 lw_expr_t e; | 1445 lw_expr_t e; |
1447 if (!**p) | 1446 if (!**p) |
1448 { | 1447 { |
1449 lwasm_register_error(as, l, "Bad operand"); | 1448 lwasm_register_error(as, l, E_OPERAND_BAD); |
1450 return; | 1449 return; |
1451 } | 1450 } |
1452 | 1451 |
1453 e = lwasm_parse_expr(as, p); | 1452 e = lwasm_parse_expr(as, p); |
1454 | 1453 |
1455 if (!e) | 1454 if (!e) |
1456 { | 1455 { |
1457 lwasm_register_error(as, l, "Bad operand"); | 1456 lwasm_register_error(as, l, E_OPERAND_BAD); |
1458 return; | 1457 return; |
1459 } | 1458 } |
1460 | 1459 |
1461 lwasm_save_expr(l, 0, e); | 1460 lwasm_save_expr(l, 0, e); |
1462 | 1461 |
1469 { | 1468 { |
1470 e = lw_expr_build(lw_expr_type_int, 0); | 1469 e = lw_expr_build(lw_expr_type_int, 0); |
1471 } | 1470 } |
1472 if (!e) | 1471 if (!e) |
1473 { | 1472 { |
1474 lwasm_register_error(as, l, "Bad padding"); | 1473 lwasm_register_error(as, l, E_PADDING_BAD); |
1475 return; | 1474 return; |
1476 } | 1475 } |
1477 | 1476 |
1478 lwasm_save_expr(l, 1, e); | 1477 lwasm_save_expr(l, 1, e); |
1479 } | 1478 } |
1490 if (lw_expr_istype(e, lw_expr_type_int)) | 1489 if (lw_expr_istype(e, lw_expr_type_int)) |
1491 { | 1490 { |
1492 align = lw_expr_intval(e); | 1491 align = lw_expr_intval(e); |
1493 if (align < 1) | 1492 if (align < 1) |
1494 { | 1493 { |
1495 lwasm_register_error(as, l, "Invalid alignment"); | 1494 lwasm_register_error(as, l, E_ALIGNMENT_INVALID); |
1496 return; | 1495 return; |
1497 } | 1496 } |
1498 } | 1497 } |
1499 else | 1498 else |
1500 { | 1499 { |
1546 PARSEFUNC(pseudo_parse_fill) | 1545 PARSEFUNC(pseudo_parse_fill) |
1547 { | 1546 { |
1548 lw_expr_t e, e1; | 1547 lw_expr_t e, e1; |
1549 if (!**p) | 1548 if (!**p) |
1550 { | 1549 { |
1551 lwasm_register_error(as, l, "Bad operand"); | 1550 lwasm_register_error(as, l, E_OPERAND_BAD); |
1552 return; | 1551 return; |
1553 } | 1552 } |
1554 | 1553 |
1555 e1 = lwasm_parse_expr(as, p); | 1554 e1 = lwasm_parse_expr(as, p); |
1556 if (**p != ',') | 1555 if (**p != ',') |
1557 { | 1556 { |
1558 lwasm_register_error(as, l, "Bad operand"); | 1557 lwasm_register_error(as, l, E_OPERAND_BAD); |
1559 return; | 1558 return; |
1560 } | 1559 } |
1561 (*p)++; | 1560 (*p)++; |
1562 e = lwasm_parse_expr(as, p); | 1561 e = lwasm_parse_expr(as, p); |
1563 | 1562 |
1564 if (!e) | 1563 if (!e) |
1565 { | 1564 { |
1566 lwasm_register_error(as, l, "Bad operand"); | 1565 lwasm_register_error(as, l, E_OPERAND_BAD); |
1567 return; | 1566 return; |
1568 } | 1567 } |
1569 | 1568 |
1570 lwasm_save_expr(l, 0, e); | 1569 lwasm_save_expr(l, 0, e); |
1571 lwasm_save_expr(l, 1, e1); | 1570 lwasm_save_expr(l, 1, e1); |
1572 | 1571 |
1573 if (!e1) | 1572 if (!e1) |
1574 { | 1573 { |
1575 lwasm_register_error(as, l, "Bad padding"); | 1574 lwasm_register_error(as, l, E_PADDING_BAD); |
1576 return; | 1575 return; |
1577 } | 1576 } |
1578 } | 1577 } |
1579 | 1578 |
1580 RESOLVEFUNC(pseudo_resolve_fill) | 1579 RESOLVEFUNC(pseudo_resolve_fill) |
1593 { | 1592 { |
1594 align = lw_expr_intval(te); | 1593 align = lw_expr_intval(te); |
1595 if (align < 0) | 1594 if (align < 0) |
1596 { | 1595 { |
1597 lw_expr_destroy(te); | 1596 lw_expr_destroy(te); |
1598 lwasm_register_error(as, l, "Invalid fill length"); | 1597 lwasm_register_error(as, l, E_FILL_INVALID); |
1599 return; | 1598 return; |
1600 } | 1599 } |
1601 } | 1600 } |
1602 else | 1601 else |
1603 { | 1602 { |
2050 } | 2049 } |
2051 | 2050 |
2052 tstr = strcond_parsearg(p); | 2051 tstr = strcond_parsearg(p); |
2053 if (!**p || isspace(**p)) | 2052 if (!**p || isspace(**p)) |
2054 { | 2053 { |
2055 lwasm_register_error(as, l, "Bad string condition"); | 2054 lwasm_register_error(as, l, E_STRING_BAD); |
2056 return; | 2055 return; |
2057 } | 2056 } |
2058 | 2057 |
2059 for (strop = 0; strops[strop].str != NULL; strop++) | 2058 for (strop = 0; strops[strop].str != NULL; strop++) |
2060 if (strcasecmp(strops[strop].str, tstr) == 0) | 2059 if (strcasecmp(strops[strop].str, tstr) == 0) |
2062 | 2061 |
2063 lw_free(tstr); | 2062 lw_free(tstr); |
2064 | 2063 |
2065 if (strops[strop].str == NULL) | 2064 if (strops[strop].str == NULL) |
2066 { | 2065 { |
2067 lwasm_register_error(as, l, "Bad string condition"); | 2066 lwasm_register_error(as, l, E_STRING_BAD); |
2068 } | 2067 } |
2069 | 2068 |
2070 tv = (*(strops[strop].fn))(p); | 2069 tv = (*(strops[strop].fn))(p); |
2071 | 2070 |
2072 if (!tv) | 2071 if (!tv) |