diff lwasm/insn_indexed.c @ 455:cad5937314cb

Add operandsizewarning pragma Add operandsizewarning pragma that will raise warnings for certain operands if the operand size could be smaller. (Long branch used instead of short branch, for instance.)
author William Astle <lost@l-w.ca>
date Fri, 16 Feb 2018 22:53:46 -0700
parents b20f14edda5a
children 3948c874901b
line wrap: on
line diff
--- a/lwasm/insn_indexed.c	Fri Feb 16 22:52:44 2018 -0700
+++ b/lwasm/insn_indexed.c	Fri Feb 16 22:53:46 2018 -0700
@@ -709,6 +709,20 @@
 		}
 	}
 	
+	if (l -> lint == 2 && CURPRAGMA(l, PRAGMA_OPERANDSIZE))
+	{
+		int offs;
+		e = lwasm_fetch_expr(l, 0);
+		if (lw_expr_istype(e, lw_expr_type_int))
+		{
+			offs = lw_expr_intval(e);
+			if ((offs >= -128 && offs <= 127) || offs >= 0xFF80)
+			{
+				lwasm_register_error(as, l, W_OPERAND_SIZE);
+			}
+		}
+	}
+	
 	lwasm_emitop(l, instab[l -> insn].ops[0]);
 	lwasm_emitop(l, l -> pb);