comparison src/pseudo.c @ 90:6097cb1486f8

Added EXPORT pseudo op
author lost
date Sat, 17 Jan 2009 05:07:45 +0000
parents 033a328a10ae
children 83ba34ed11b3
comparison
equal deleted inserted replaced
89:11d38c9e5095 90:6097cb1486f8
719 s -> flags = 0; 719 s -> flags = 0;
720 s -> obytes = NULL; 720 s -> obytes = NULL;
721 s -> oblen = 0; 721 s -> oblen = 0;
722 s -> obsize = 0; 722 s -> obsize = 0;
723 s -> rl = NULL; 723 s -> rl = NULL;
724 s -> exports = NULL;
724 // parse options; only one "bss" 725 // parse options; only one "bss"
725 if (opts && as -> passnum == 1) 726 if (opts && as -> passnum == 1)
726 { 727 {
727 if (!strcasecmp(opts, "bss")) 728 if (!strcasecmp(opts, "bss"))
728 { 729 {
782 return; 783 return;
783 } 784 }
784 785
785 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN); 786 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN);
786 } 787 }
788
789 OPFUNC(pseudo_export)
790 {
791 lwasm_symbol_ent_t *se;
792 export_list_t *ex;
793
794 if (as -> outformat != OUTPUT_OBJ)
795 {
796 register_error(as, l, 1, "Symbol exports only supported for obj target");
797 return;
798 }
799
800 if (as -> passnum == 1)
801 return;
802
803 // the symbol better be defined at this point (pass 2)
804 // local symbols cannot be exported nor can "global" symbols
805 se = lwasm_find_symbol(as, l -> sym, -1);
806 if (!se)
807 {
808 register_error(as, l, 2, "Exported symbols must be fully defined within a section");
809 return;
810 }
811 if (se -> sect == NULL)
812 {
813 register_error(as, l, 2, "Only non-local symbols within a section can be exported");
814 return;
815 }
816
817 if (se -> flags & SYMBOL_SET)
818 {
819 register_error(as, l, 2, "You cannot export symbols defined with SET");
820 return;
821 }
822
823 // if the symbol is not already a simple value, re-evaluate it
824 // and see if it becomes simple
825
826
827 if (se -> flags & SYMBOL_COMPLEX)
828 {
829 register_error(as, l, 2, "Exported symbols must be fully resolved on pass 2");
830 return;
831 }
832
833 // search for existing export
834 for (ex = se -> sect -> exports; ex; ex = ex -> next)
835 if (!strcmp(l -> sym, ex -> sym))
836 break;
837 if (ex)
838 {
839 register_error(as, l, 2, "Symbol %s already exported", l -> sym);
840 return;
841 }
842
843 // add an external reference
844 ex = lwasm_alloc(sizeof(export_list_t));
845 ex -> next = se -> sect -> exports;
846 se -> sect -> exports = ex;
847 ex -> offset = se -> value;
848 ex -> sym = lwasm_strdup(se -> sym);
849 }