comparison lwasm/pseudo.c @ 192:bfd0fb0a85c2

Allow exporting multiple symbols on a single directive
author lost
date Sun, 22 Mar 2009 16:28:40 +0000
parents 563adfccb645
children 6ddc861a07d4
comparison
equal deleted inserted replaced
191:29ba546ceea0 192:bfd0fb0a85c2
1037 OPFUNC(pseudo_export) 1037 OPFUNC(pseudo_export)
1038 { 1038 {
1039 lwasm_symbol_ent_t *se; 1039 lwasm_symbol_ent_t *se;
1040 export_list_t *ex; 1040 export_list_t *ex;
1041 char *sym2, *sym3; 1041 char *sym2, *sym3;
1042 int after = 0;
1042 1043
1043 if (as -> outformat != OUTPUT_OBJ) 1044 if (as -> outformat != OUTPUT_OBJ)
1044 { 1045 {
1045 register_error(as, l, 1, "Symbol exports only supported for obj target"); 1046 register_error(as, l, 1, "Symbol exports only supported for obj target");
1046 return; 1047 return;
1047 } 1048 }
1048 1049
1049 if (as -> passnum == 1) 1050 if (as -> passnum == 1)
1050 return; 1051 return;
1051 1052
1052 if (!(l -> sym)) 1053 again:
1053 { 1054 if (!(l -> sym) || after == 1)
1055 {
1056
1057 after = 1;
1054 // look for symbol after op 1058 // look for symbol after op
1055 if (**p) 1059 if (**p)
1056 { 1060 {
1057 for (sym2 = *p; **p && !isspace(**p); (*p)++) 1061 for (sym2 = *p; **p && !isspace(**p) && **p != ','; (*p)++)
1058 /* do nothing */ ; 1062 /* do nothing */ ;
1063
1064 debug_message(2, "export expression: %s", sym2);
1065 if (l -> sym)
1066 lwasm_free(l -> sym);
1059 sym3 = lwasm_alloc(*p - sym2 + 1); 1067 sym3 = lwasm_alloc(*p - sym2 + 1);
1060 memcpy(sym3, sym2, *p - sym2); 1068 memcpy(sym3, sym2, *p - sym2);
1061 sym3[*p - sym2] = '\0'; 1069 sym3[*p - sym2] = '\0';
1062 1070
1063 l -> sym = sym3; 1071 l -> sym = sym3;
1072 debug_message(2, "export symbol: '%s'", sym3);
1064 } 1073 }
1065 } 1074 }
1066 if (!(l -> sym)) 1075 if (!(l -> sym))
1067 { 1076 {
1068 register_error(as, l, 2, "No symbol"); 1077 register_error(as, l, 2, "No symbol");
1114 ex = lwasm_alloc(sizeof(export_list_t)); 1123 ex = lwasm_alloc(sizeof(export_list_t));
1115 ex -> next = se -> sect -> exports; 1124 ex -> next = se -> sect -> exports;
1116 se -> sect -> exports = ex; 1125 se -> sect -> exports = ex;
1117 ex -> offset = se -> value; 1126 ex -> offset = se -> value;
1118 ex -> sym = lwasm_strdup(se -> sym); 1127 ex -> sym = lwasm_strdup(se -> sym);
1119 } 1128 if (after == 1)
1129 {
1130 if (**p == ',')
1131 {
1132 debug_message(2, "Export another symbol: %s", *p);
1133 (*p)++;
1134 for ( ; **p && isspace(**p); (*p)++)
1135 /* do nothing */ ;
1136 goto again;
1137 }
1138 }
1139 }