comparison lwasm/pseudo.c @ 351:4dba8c7e242c

conditional pseudo ops added
author lost@starbug
date Sat, 27 Mar 2010 23:37:30 -0600
parents f5666775d76f
children 60568b123281
comparison
equal deleted inserted replaced
350:f5666775d76f 351:4dba8c7e242c
509 509
510 PARSEFUNC(pseudo_parse_org) 510 PARSEFUNC(pseudo_parse_org)
511 { 511 {
512 lw_expr_t e; 512 lw_expr_t e;
513 513
514 l -> len = 0;
515
514 e = lwasm_parse_expr(as, p); 516 e = lwasm_parse_expr(as, p);
515 if (!e) 517 if (!e)
516 { 518 {
517 lwasm_register_error(as, l, "Bad operand"); 519 lwasm_register_error(as, l, "Bad operand");
518 return; 520 return;
525 527
526 PARSEFUNC(pseudo_parse_equ) 528 PARSEFUNC(pseudo_parse_equ)
527 { 529 {
528 lw_expr_t e; 530 lw_expr_t e;
529 531
532 l -> len = 0;
533
530 if (!(l -> sym)) 534 if (!(l -> sym))
531 { 535 {
532 lwasm_register_error(as, l, "Missing symbol"); 536 lwasm_register_error(as, l, "Missing symbol");
533 return; 537 return;
534 } 538 }
541 } 545 }
542 546
543 register_symbol(as, l, l -> sym, e, symbol_flag_none); 547 register_symbol(as, l, l -> sym, e, symbol_flag_none);
544 l -> symset = 1; 548 l -> symset = 1;
545 } 549 }
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