comparison src/pseudo.c @ 74:c8c772ef5df9

Checkpointing object target implementation
author lost
date Thu, 08 Jan 2009 01:18:40 +0000
parents 31d8e85706e7
children 121bf4a588ea
comparison
equal deleted inserted replaced
73:4b37f17624a7 74:c8c772ef5df9
32 32
33 OPFUNC(pseudo_org) 33 OPFUNC(pseudo_org)
34 { 34 {
35 int rval; 35 int rval;
36 lwasm_expr_stack_t *s; 36 lwasm_expr_stack_t *s;
37
38 if (as -> csect)
39 {
40 register_error(as, l, 1, "ORG not allowed within sections");
41 return;
42 }
37 43
38 if (as -> passnum != 1) 44 if (as -> passnum != 1)
39 { 45 {
40 // org is not needed to be processed on pass 2 46 // org is not needed to be processed on pass 2
41 // this will prevent phasing errors for forward references that 47 // this will prevent phasing errors for forward references that
690 OPFUNC(pseudo_error) 696 OPFUNC(pseudo_error)
691 { 697 {
692 register_error(as, l, 1, "User error: %s", *p); 698 register_error(as, l, 1, "User error: %s", *p);
693 } 699 }
694 700
701
702 OPFUNC(pseudo_section)
703 {
704 sectiontab_t *s;
705 char *p2;
706 char *sn;
707 char *opts;
708
709
710 if (as -> outformat != OUTPUT_OBJ)
711 {
712 register_error(as, l, 1, "Sections only supported for obj target");
713 return;
714 }
715
716 if (as -> csect)
717 {
718 as -> csect -> offset = as -> addr;
719 as -> csect = NULL;
720 }
721
722 if (!**p)
723 {
724 register_error(as, l, 1, "Need section name");
725 return;
726 }
727
728 for (p2 = *p; *p2 && !isspace(*p2); p2++)
729 /* do nothing */ ;
730
731 sn = lwasm_alloc(p2 - *p + 1);
732 memcpy(sn, *p, p2 - *p);
733 sn[p2 - *p] = '\0';
734
735 *p = p2;
736
737 opts = strchr(sn, ',');
738 if (opts)
739 {
740 *opts++ = '\0';
741 }
742
743 // have we seen the section name already?
744 for (s = as -> sections; s; s = s -> next)
745 {
746 if (!strcmp(s -> name, sn))
747 break;
748 }
749
750 if (s)
751 {
752 lwasm_free(sn);
753 if (opts)
754 {
755 register_error(as, l, 1, "Section options can only be specified the first time");
756 return;
757 }
758 }
759 else if (!s)
760 {
761 s = lwasm_alloc(sizeof(sectiontab_t));
762 s -> name = sn;
763 s -> offset = 0;
764 s -> flags = 0;
765
766 // parse options; only one "bss"
767 if (opts && as -> passnum == 1)
768 {
769 if (!strcasecmp(opts, "bss"))
770 {
771 s -> flags = SECTION_BSS;
772 }
773 else
774 {
775 register_error(as, l, 1, "Unrecognized section option '%s'", opts);
776 lwasm_free(s -> name);
777 lwasm_free(s);
778 return;
779 }
780 }
781
782 s -> next = as -> sections;
783 as -> sections = s;
784 }
785 as -> addr = s -> offset;
786 as -> csect = s;
787 as -> context = lwasm_next_context(as);
788 }
789
790 OPFUNC(pseudo_endsection)
791 {
792 if (as -> outformat != OUTPUT_OBJ)
793 {
794 register_error(as, l, 1, "Sections only supported for obj target");
795 return;
796 }
797
798 if (!(as -> csect))
799 {
800 register_error(as, l, 1, "ENDSECTION when not in a section");
801 return;
802 }
803
804 as -> csect -> offset = as -> addr;
805 as -> addr = 0;
806 as -> csect = 0;
807 as -> context = lwasm_next_context(as);
808 }