diff lwasm/pass1.c @ 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 d96037ea0b80
children bd8b3fbd1e28
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)
 					{