diff lwasm/lwasm.c @ 387:a741d2e4869f

Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
author lost@l-w.ca
date Wed, 14 Jul 2010 20:15:23 -0600
parents cf8c92d70eb1
children c1d83336e1d1
line wrap: on
line diff
--- a/lwasm/lwasm.c	Sun May 16 13:03:17 2010 -0600
+++ b/lwasm/lwasm.c	Wed Jul 14 20:15:23 2010 -0600
@@ -781,3 +781,57 @@
 		fprintf(stderr, "  LINE: %s\n", cl -> ltext);
 	}
 }
+
+/*
+this does any passes and other gymnastics that might be useful
+to see if an expression reduces early
+*/
+extern void do_pass3(asmstate_t *as);
+extern void do_pass4_aux(asmstate_t *as, int force);
+
+void lwasm_interim_reduce(asmstate_t *as)
+{
+	do_pass3(as);
+//	do_pass4_aux(as, 0);
+}
+
+lw_expr_t lwasm_parse_cond(asmstate_t *as, char **p)
+{
+	lw_expr_t e;
+
+	debug_message(as, 250, "Parsing condition");
+	e = lwasm_parse_expr(as, p);
+	debug_message(as, 250, "COND EXPR: %s", lw_expr_print(e));
+	
+	if (!e)
+	{
+		lwasm_register_error(as, as -> cl, "Bad expression");
+		return NULL;
+	}
+
+	/* we need to simplify the expression here */
+	debug_message(as, 250, "Doing interim reductions");
+	lwasm_interim_reduce(as);
+	debug_message(as, 250, "COND EXPR: %s", lw_expr_print(e));
+	debug_message(as, 250, "Reducing expression");
+	lwasm_reduce_expr(as, e);
+	debug_message(as, 250, "COND EXPR: %s", lw_expr_print(e));
+/*	lwasm_reduce_expr(as, e);
+	debug_message(as, 250, "COND EXPR: %s", lw_expr_print(e));
+	lwasm_reduce_expr(as, e);
+	debug_message(as, 250, "COND EXPR: %s", lw_expr_print(e));
+	lwasm_reduce_expr(as, e);
+	debug_message(as, 250, "COND EXPR: %s", lw_expr_print(e));
+*/
+
+	lwasm_save_expr(as -> cl, 4242, e);
+
+	if (!lw_expr_istype(e, lw_expr_type_int))
+	{
+		debug_message(as, 250, "Non-constant expression");
+		lwasm_register_error(as, as -> cl, "Conditions must be constant on pass 1");
+		return NULL;
+	}
+	debug_message(as, 250, "Returning expression");
+	return e;
+}