comparison lwasm/insn_gen.c @ 476:eac8f5f0867d

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.
author William Astle <lost@l-w.ca>
date Wed, 12 Dec 2018 19:40:16 -0700
parents 2c1c5dd84024
children 62720ac9e28d
comparison
equal deleted inserted replaced
475:b9917c4dc6cf 476:eac8f5f0867d
337 l -> cycle_adj = lwasm_cycle_calc_ind(l); 337 l -> cycle_adj = lwasm_cycle_calc_ind(l);
338 return; 338 return;
339 } 339 }
340 340
341 if (l -> lint2 == 2) 341 if (l -> lint2 == 2)
342 {
342 lwasm_emitexpr(l, e, 2); 343 lwasm_emitexpr(l, e, 2);
344
345 if (CURPRAGMA(l, PRAGMA_OPERANDSIZE))
346 {
347 if (instab[l -> insn].ops[2] == 0xbd || instab[l -> insn].ops[2] == 0x7e)
348 {
349 // check if bsr or bra could be used instead
350 lw_expr_t e1, e2;
351 int offs;
352 e2 = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, l);
353 e1 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, e, e2);
354 lw_expr_destroy(e2);
355 e2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, e1, l -> addr);
356 lw_expr_destroy(e1);
357 lwasm_reduce_expr(as, e2);
358 if (lw_expr_istype(e2, lw_expr_type_int))
359 {
360 offs = lw_expr_intval(e2);
361 if (offs >= -128 && offs <= 127)
362 {
363 lwasm_register_error(as, l, W_OPERAND_SIZE);
364 }
365 }
366 lw_expr_destroy(e2);
367 }
368 }
369 }
343 else 370 else
371 {
344 lwasm_emitexpr(l, e, 1); 372 lwasm_emitexpr(l, e, 1);
373 }
345 } 374 }
346 375
347 // the various insn_gen? functions have an immediate mode of ? bits 376 // the various insn_gen? functions have an immediate mode of ? bits
348 PARSEFUNC(insn_parse_gen0) 377 PARSEFUNC(insn_parse_gen0)
349 { 378 {