# HG changeset patch # User lost@l-w.ca # Date 1301961308 21600 # Node ID 18b49cf10ae9d0386f4cbc6c0b1d14ea2eea6fc2 # Parent 31adb7c09b4ee36bee24258aa82c3d472501d1ba Added an instruction reduction immediately after instruction parsing to minimize memory footprint and expression complexity diff -r 31adb7c09b4e -r 18b49cf10ae9 lwasm/pass1.c --- a/lwasm/pass1.c Sat Apr 02 22:37:41 2011 -0600 +++ b/lwasm/pass1.c Mon Apr 04 17:55:08 2011 -0600 @@ -277,6 +277,8 @@ { if (as -> instruct == 0 || instab[opnum].flags & lwasm_insn_struct) { + struct line_expr_s *le; + cl -> len = -1; // call parse function (instab[opnum].parse)(as, cl, &p1); @@ -286,6 +288,23 @@ // flag bad operand error lwasm_register_error(as, cl, "Bad operand (%s)", p1); } + + /* do a reduction on the line expressions to avoid carrying excessive expression baggage if not needed */ + as -> cl = cl; + + // simplify address + lwasm_reduce_expr(as, cl -> addr); + + // simplify each expression + for (le = cl -> exprs; le; le = le -> next) + lwasm_reduce_expr(as, le -> expr); + + /* try resolving the instruction as well */ + if (cl -> insn >= 0 && instab[cl -> insn].resolve) + { + (instab[cl -> insn].resolve)(as, cl, 0); + } + } else if (as -> instruct == 1) { diff -r 31adb7c09b4e -r 18b49cf10ae9 lwlib/lw_expr.c --- a/lwlib/lw_expr.c Sat Apr 02 22:37:41 2011 -0600 +++ b/lwlib/lw_expr.c Mon Apr 04 17:55:08 2011 -0600 @@ -40,6 +40,9 @@ int lw_expr_istype(lw_expr_t e, int t) { + /* NULL expression is never of any type */ + if (!e) + return 0; if (e -> type == t) return 1; return 0; @@ -115,6 +118,8 @@ lw_expr_t r; struct lw_expr_opers *o; + if (!E) + return NULL; r = lw_alloc(sizeof(struct lw_expr_priv)); *r = *E; r -> operands = NULL;