diff lwasm/pass3.c @ 365:6a98cc90c14f

Added resolve passes
author lost@starbug
date Wed, 14 Apr 2010 20:49:04 -0600
parents 0b5a26bedbe1
children
line wrap: on
line diff
--- a/lwasm/pass3.c	Tue Apr 06 21:35:09 2010 -0600
+++ b/lwasm/pass3.c	Wed Apr 14 20:49:04 2010 -0600
@@ -39,4 +39,37 @@
 */
 void do_pass3(asmstate_t *as)
 {
+	int rc;
+	line_t *cl;
+	struct line_expr_s *le;
+	
+	do
+	{
+		rc = 0;
+		for (cl = as -> line_head; cl; cl = cl -> next)
+		{
+			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);
+			
+			if (cl -> len == -1)
+			{
+				// try resolving the instruction length
+				// but don't force resolution
+				if (cl -> insn >= 0 && instab[cl -> insn].resolve)
+				{
+					(instab[cl -> insn].resolve)(as, cl, 0);
+					if (cl -> len != -1)
+						rc++;
+				}
+			}
+		}
+		if (as -> errorcount > 0)
+			return;
+	} while (rc > 0);
 }