# HG changeset patch # User William Astle # Date 1544668816 25200 # Node ID eac8f5f0867dd6149b007d42510fa6fb0430a2cd # Parent b9917c4dc6cf4855680f36891f52cdbfdb5e0114 Update operandsizewarning to detect JMP and JSR that could use BRA or BSR The operandsizewarning pragma will now raise warnings when it detects that a JMP or JSR instruction is using extended addresing when the target of the branch is within range of a BRA or BSR instruction. diff -r b9917c4dc6cf -r eac8f5f0867d lwasm/insn_gen.c --- a/lwasm/insn_gen.c Mon Dec 10 21:27:08 2018 -0700 +++ b/lwasm/insn_gen.c Wed Dec 12 19:40:16 2018 -0700 @@ -339,9 +339,38 @@ } if (l -> lint2 == 2) + { lwasm_emitexpr(l, e, 2); + + if (CURPRAGMA(l, PRAGMA_OPERANDSIZE)) + { + if (instab[l -> insn].ops[2] == 0xbd || instab[l -> insn].ops[2] == 0x7e) + { + // check if bsr or bra could be used instead + lw_expr_t e1, e2; + int offs; + e2 = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, l); + e1 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, e, e2); + lw_expr_destroy(e2); + e2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, e1, l -> addr); + lw_expr_destroy(e1); + lwasm_reduce_expr(as, e2); + if (lw_expr_istype(e2, lw_expr_type_int)) + { + offs = lw_expr_intval(e2); + if (offs >= -128 && offs <= 127) + { + lwasm_register_error(as, l, W_OPERAND_SIZE); + } + } + lw_expr_destroy(e2); + } + } + } else + { lwasm_emitexpr(l, e, 1); + } } // the various insn_gen? functions have an immediate mode of ? bits