changeset 369:898a41f7eb59

check for valid expressions in pass 6
author lost@starbug
date Thu, 15 Apr 2010 22:26:49 -0600
parents 656630007668
children 6b33faa21a0a
files lwasm/pass6.c
diffstat 1 files changed, 36 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/pass6.c	Thu Apr 15 22:18:48 2010 -0600
+++ b/lwasm/pass6.c	Thu Apr 15 22:26:49 2010 -0600
@@ -39,8 +39,39 @@
 
 Everything should reduce as far as it is going to in a single pass
 because all line addresses are now constant (or section-base offset)
+*/
 
-*/
+static int exprok_aux(lw_expr_t e, void *priv)
+{
+	asmstate_t *as = priv;
+	
+	if (lw_expr_istype(e, lw_expr_type_int))
+		return 0;
+	
+	if (as -> output_format == OUTPUT_OBJ)
+	{
+		if (lw_expr_istype(e, lw_expr_type_oper))
+			return 0;
+		if (lw_expr_istype(e, lw_expr_type_special) && as -> output_format == OUTPUT_OBJ)
+		{
+			int t;
+			t = lw_expr_specint(e);
+			if (t == lwasm_expr_secbase || t == lwasm_expr_syment || t == lwasm_expr_import)
+				return 0;
+		}
+	}
+	
+	return 1;
+}
+
+static int exprok(asmstate_t *as, lw_expr_t e)
+{
+	if (lw_expr_testterms(e, exprok_aux, as))
+		return 0;
+	return 1;
+}
+
+
 void do_pass6(asmstate_t *as)
 {
 	line_t *cl;
@@ -52,6 +83,10 @@
 		for (le = cl -> exprs; le; le = le -> next)
 		{
 			lwasm_reduce_expr(as, le -> expr);
+			if (!exprok(as, le -> expr))
+			{
+				lwasm_register_error(as, cl, "Invalid expression");
+			}
 		}
 	}
 }