comparison lwasm/section.c @ 356:7166254491ed

Finished pseudo ops
author lost@starbug
date Wed, 31 Mar 2010 18:46:32 -0600
parents faa97115952e
children d96c30e60ddf
comparison
equal deleted inserted replaced
355:981e34165e97 356:7166254491ed
157 // end of section is a context break 157 // end of section is a context break
158 as -> context = lwasm_next_context(as); 158 as -> context = lwasm_next_context(as);
159 159
160 skip_operand(p); 160 skip_operand(p);
161 } 161 }
162
163 PARSEFUNC(pseudo_parse_export)
164 {
165 int after = 0;
166 char *sym = NULL;
167 exportlist_t *e;
168
169 if (as -> output_format != OUTPUT_OBJ)
170 {
171 lwasm_register_error(as, l, "EXPORT only supported for object target");
172 return;
173 }
174
175 if (l -> sym)
176 sym = lw_strdup(l -> sym);
177
178 if (l -> sym)
179 {
180 skip_operand(p);
181 }
182
183 again:
184 if (after || !sym)
185 {
186 char *p2;
187
188 after = 1;
189 for (p2 = *p; *p2 && *p2 != ',' && !isspace(*p2); p2++)
190 /* do nothing */ ;
191
192 sym = lw_strndup(*p, p2 - *p);
193 }
194 if (!sym)
195 {
196 lwasm_register_error(as, l, "No symbol for EXPORT");
197 return;
198 }
199
200 // add the symbol to the "export" list (which will be resolved
201 // after the parse pass is complete
202 e = lw_alloc(sizeof(exportlist_t));
203 e -> next = as -> exportlist;
204 e -> symbol = lw_strdup(sym);
205 as -> exportlist = e;
206 lw_free(sym);
207
208 if (after && **p == ',')
209 {
210 (*p)++;
211 for (; **p && isspace(**p); (*p)++)
212 /* do nothing */ ;
213 goto again;
214 }
215 }
216
217 PARSEFUNC(pseudo_parse_extern)
218 {
219 int after = 0;
220 char *sym = NULL;
221 importlist_t *e;
222
223 if (as -> output_format != OUTPUT_OBJ)
224 {
225 lwasm_register_error(as, l, "IMPORT only supported for object target");
226 return;
227 }
228
229 if (l -> sym)
230 sym = lw_strdup(l -> sym);
231
232 if (l -> sym)
233 {
234 skip_operand(p);
235 }
236
237 again:
238 if (after || !sym)
239 {
240 char *p2;
241
242 after = 1;
243 for (p2 = *p; *p2 && *p2 != ',' && !isspace(*p2); p2++)
244 /* do nothing */ ;
245
246 sym = lw_strndup(*p, p2 - *p);
247 }
248 if (!sym)
249 {
250 lwasm_register_error(as, l, "No symbol for IMPORT");
251 return;
252 }
253
254 // add the symbol to the "export" list (which will be resolved
255 // after the parse pass is complete
256 e = lw_alloc(sizeof(importlist_t));
257 e -> next = as -> importlist;
258 e -> symbol = lw_strdup(sym);
259 as -> importlist = e;
260 lw_free(sym);
261
262 if (after && **p == ',')
263 {
264 (*p)++;
265 for (; **p && isspace(**p); (*p)++)
266 /* do nothing */ ;
267 goto again;
268 }
269 }