Mercurial > hg-old > index.cgi
diff lwasm/section.c @ 356:7166254491ed
Finished pseudo ops
author | lost@starbug |
---|---|
date | Wed, 31 Mar 2010 18:46:32 -0600 |
parents | faa97115952e |
children | d96c30e60ddf |
line wrap: on
line diff
--- a/lwasm/section.c Tue Mar 30 23:12:41 2010 -0600 +++ b/lwasm/section.c Wed Mar 31 18:46:32 2010 -0600 @@ -159,3 +159,111 @@ skip_operand(p); } + +PARSEFUNC(pseudo_parse_export) +{ + int after = 0; + char *sym = NULL; + exportlist_t *e; + + if (as -> output_format != OUTPUT_OBJ) + { + lwasm_register_error(as, l, "EXPORT only supported for object target"); + return; + } + + if (l -> sym) + sym = lw_strdup(l -> sym); + + if (l -> sym) + { + skip_operand(p); + } + +again: + if (after || !sym) + { + char *p2; + + after = 1; + for (p2 = *p; *p2 && *p2 != ',' && !isspace(*p2); p2++) + /* do nothing */ ; + + sym = lw_strndup(*p, p2 - *p); + } + if (!sym) + { + lwasm_register_error(as, l, "No symbol for EXPORT"); + return; + } + + // add the symbol to the "export" list (which will be resolved + // after the parse pass is complete + e = lw_alloc(sizeof(exportlist_t)); + e -> next = as -> exportlist; + e -> symbol = lw_strdup(sym); + as -> exportlist = e; + lw_free(sym); + + if (after && **p == ',') + { + (*p)++; + for (; **p && isspace(**p); (*p)++) + /* do nothing */ ; + goto again; + } +} + +PARSEFUNC(pseudo_parse_extern) +{ + int after = 0; + char *sym = NULL; + importlist_t *e; + + if (as -> output_format != OUTPUT_OBJ) + { + lwasm_register_error(as, l, "IMPORT only supported for object target"); + return; + } + + if (l -> sym) + sym = lw_strdup(l -> sym); + + if (l -> sym) + { + skip_operand(p); + } + +again: + if (after || !sym) + { + char *p2; + + after = 1; + for (p2 = *p; *p2 && *p2 != ',' && !isspace(*p2); p2++) + /* do nothing */ ; + + sym = lw_strndup(*p, p2 - *p); + } + if (!sym) + { + lwasm_register_error(as, l, "No symbol for IMPORT"); + return; + } + + // add the symbol to the "export" list (which will be resolved + // after the parse pass is complete + e = lw_alloc(sizeof(importlist_t)); + e -> next = as -> importlist; + e -> symbol = lw_strdup(sym); + as -> importlist = e; + lw_free(sym); + + if (after && **p == ',') + { + (*p)++; + for (; **p && isspace(**p); (*p)++) + /* do nothing */ ; + goto again; + } +}