Mercurial > hg-old > index.cgi
diff lwasm/lwasm.c @ 363:d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
author | lost@starbug |
---|---|
date | Tue, 06 Apr 2010 21:03:19 -0600 |
parents | f50a54d0293a |
children | 9c24d9d485b9 |
line wrap: on
line diff
--- a/lwasm/lwasm.c Thu Apr 01 20:56:19 2010 -0600 +++ b/lwasm/lwasm.c Tue Apr 06 21:03:19 2010 -0600 @@ -33,8 +33,53 @@ #include "lwasm.h" +void lwasm_register_error(asmstate_t *as, line_t *l, const char *msg, ...); + lw_expr_t lwasm_evaluate_var(char *var, void *priv) { + asmstate_t *as = (asmstate_t *)priv; + lw_expr_t e; + importlist_t *im; + struct symtabe *s; + + s = lookup_symbol(as, as -> cl, var); + if (s) + { + e = lw_expr_build(lw_expr_type_special, lwasm_expr_syment, s); + return e; + } + + // undefined here is undefied unless output is object + if (as -> output_format != OUTPUT_OBJ) + goto nomatch; + + // check for import + for (im = as -> importlist; im; im = im -> next) + { + if (!strcmp(im -> symbol, var)) + break; + } + + // check for "undefined" to import automatically + if (!im && CURPRAGMA(as -> cl, PRAGMA_UNDEFEXTERN)) + { + im = lw_alloc(sizeof(importlist_t)); + im -> symbol = lw_strdup(var); + im -> next = as -> importlist; + as -> importlist = im; + } + + if (!im) + goto nomatch; + + e = lw_expr_build(lw_expr_type_special, lwasm_expr_import, im); + return e; + +nomatch: + if (as -> badsymerr) + { + lwasm_register_error(as, as -> cl, "Undefined symbol %s", var); + } return NULL; } @@ -59,6 +104,26 @@ else return NULL; } + + case lwasm_expr_syment: + { + return NULL; + } + + case lwasm_expr_import: + { + return NULL; + } + + case lwasm_expr_nextbp: + { + return NULL; + } + + case lwasm_expr_prevbp: + { + return NULL; + } } return NULL; } @@ -482,6 +547,11 @@ return e; } +int lwasm_reduce_expr(asmstate_t *as, lw_expr_t expr) +{ + lw_expr_simplify(expr, as); +} + void lwasm_save_expr(line_t *cl, int id, lw_expr_t expr) { struct line_expr_s *e; @@ -612,3 +682,8 @@ (*p) += 3; return rval; } + +void lwasm_show_errors(asmstate_t *as) +{ + fprintf(stderr, "Errors encountered. FIXME - print out errors.\n"); +}