Mercurial > hg-old > index.cgi
comparison lwasm/pseudo.c @ 199:188037f0397c
Allow export to import undefined symbols
author | lost |
---|---|
date | Sun, 22 Mar 2009 18:32:13 +0000 |
parents | 6ddc861a07d4 |
children | 7824f94c5786 |
comparison
equal
deleted
inserted
replaced
198:6ddc861a07d4 | 199:188037f0397c |
---|---|
1091 return; | 1091 return; |
1092 } | 1092 } |
1093 | 1093 |
1094 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN); | 1094 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN); |
1095 } | 1095 } |
1096 else | |
1097 { | |
1096 if (!se) | 1098 if (!se) |
1097 { | 1099 { |
1098 register_error(as, l, 2, "Exported symbols must be fully defined within a section"); | 1100 register_error(as, l, 2, "Exported symbols must be fully defined within a section"); |
1099 return; | 1101 return; |
1100 } | 1102 } |
1101 if (se -> sect == NULL) | 1103 if (se -> sect == NULL) |
1102 { | 1104 { |
1103 register_error(as, l, 2, "Only non-local symbols within a section can be exported"); | 1105 register_error(as, l, 2, "Only non-local symbols within a section can be exported"); |
1104 return; | 1106 return; |
1105 } | 1107 } |
1106 | 1108 |
1107 if (se -> flags & SYMBOL_SET) | 1109 if (se -> flags & SYMBOL_SET) |
1108 { | 1110 { |
1109 register_error(as, l, 2, "You cannot export symbols defined with SET"); | 1111 register_error(as, l, 2, "You cannot export symbols defined with SET"); |
1110 return; | 1112 return; |
1111 } | 1113 } |
1112 | 1114 |
1113 // if the symbol is not already a simple value, re-evaluate it | 1115 // if the symbol is not already a simple value, re-evaluate it |
1114 // and see if it becomes simple | 1116 // and see if it becomes simple |
1115 | 1117 |
1116 | 1118 |
1117 if (se -> flags & SYMBOL_COMPLEX) | 1119 if (se -> flags & SYMBOL_COMPLEX) |
1118 { | 1120 { |
1119 register_error(as, l, 2, "Exported symbols must be fully resolved on pass 2"); | 1121 register_error(as, l, 2, "Exported symbols must be fully resolved on pass 2"); |
1120 return; | 1122 return; |
1121 } | 1123 } |
1122 | 1124 |
1123 // search for existing export | 1125 // search for existing export |
1124 for (ex = se -> sect -> exports; ex; ex = ex -> next) | 1126 for (ex = se -> sect -> exports; ex; ex = ex -> next) |
1125 if (!strcmp(l -> sym, ex -> sym)) | 1127 if (!strcmp(l -> sym, ex -> sym)) |
1126 break; | 1128 break; |
1127 if (ex) | 1129 if (ex) |
1128 { | 1130 { |
1129 register_error(as, l, 2, "Symbol %s already exported", l -> sym); | 1131 register_error(as, l, 2, "Symbol %s already exported", l -> sym); |
1130 return; | 1132 return; |
1131 } | 1133 } |
1132 | 1134 |
1133 // add an external reference | 1135 // add an external reference |
1134 ex = lwasm_alloc(sizeof(export_list_t)); | 1136 ex = lwasm_alloc(sizeof(export_list_t)); |
1135 ex -> next = se -> sect -> exports; | 1137 ex -> next = se -> sect -> exports; |
1136 se -> sect -> exports = ex; | 1138 se -> sect -> exports = ex; |
1137 ex -> offset = se -> value; | 1139 ex -> offset = se -> value; |
1138 ex -> sym = lwasm_strdup(se -> sym); | 1140 ex -> sym = lwasm_strdup(se -> sym); |
1141 } | |
1139 if (after == 1) | 1142 if (after == 1) |
1140 { | 1143 { |
1141 if (**p == ',') | 1144 if (**p == ',') |
1142 { | 1145 { |
1143 debug_message(2, "Export another symbol: %s", *p); | 1146 debug_message(2, "Export another symbol: %s", *p); |