Mercurial > hg > index.cgi
changeset 43:18b49cf10ae9
Added an instruction reduction immediately after instruction parsing to minimize memory footprint and expression complexity
author | lost@l-w.ca |
---|---|
date | Mon, 04 Apr 2011 17:55:08 -0600 |
parents | 31adb7c09b4e |
children | 1bff302e62a3 |
files | lwasm/pass1.c lwlib/lw_expr.c |
diffstat | 2 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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) {
--- 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;