diff lwasm/insn_gen.c @ 355:3afb809c7add

Make 8 bit immediate operands flag a byte overflow if not in 8 bit range. 8 bit immediate operands should flag a byte overflow if they are out of range. The acceptable range is -128 <= x <= 255 to cover both signed and unsigned values.
author William Astle <lost@l-w.ca>
date Tue, 19 May 2015 12:26:35 -0600
parents 210d261a614d
children 433dbc18fb41
line wrap: on
line diff
--- a/lwasm/insn_gen.c	Fri May 15 15:47:26 2015 -0600
+++ b/lwasm/insn_gen.c	Tue May 19 12:26:35 2015 -0600
@@ -369,6 +369,16 @@
 	{
 		lw_expr_t e;
 		e = lwasm_fetch_expr(l, 0);
+		if (lw_expr_istype(e, lw_expr_type_int))
+		{
+			int i;
+			i = lw_expr_intval(e);
+			if (i < -128 || i > 255)
+			{
+				lwasm_register_error(as, l, "Byte overflow");
+			}
+		}
+
 		lwasm_emitop(l, instab[l -> insn].ops[3]);
 		lwasm_emitexpr(l, e, 1);
 		return;
@@ -528,5 +538,14 @@
 	
 	lwasm_emitop(l, instab[l -> insn].ops[0]);
 	e = lwasm_fetch_expr(l, 0);
+	if (lw_expr_istype(e, lw_expr_type_int))
+	{
+		int i;
+		i = lw_expr_intval(e);
+		if (i < -128 || i > 255)
+		{
+			lwasm_register_error(as, l, "Byte overflow");
+		}
+	}
 	lwasm_emitexpr(l, e, 1);
 }