comparison lwasm/insn_indexed.c @ 465:7370a67caf7e

Fix really dumb code generation error The previous commit caused some unforuntate code generation errors. Fixed those. Also made the heuristic for guessing that 8 bit is okay for PCR allow a fudge factor so that some corner cases are much less likely to explode.
author William Astle <lost@l-w.ca>
date Wed, 28 Feb 2018 23:31:17 -0700
parents 9134f6426c57
children 51bed8c8dc53
comparison
equal deleted inserted replaced
464:9134f6426c57 465:7370a67caf7e
573 } 573 }
574 else 574 else
575 { 575 {
576 if ((l -> pb & 0x07) == 5 || (l -> pb & 0x07) == 6) 576 if ((l -> pb & 0x07) == 5 || (l -> pb & 0x07) == 6)
577 { 577 {
578 // NOTE: this will break in some particularly obscure corner cases
579 // which are not likely to show up in normal code. Notably, if, for
580 // some reason, the target gets *farther* away if shorter addressing
581 // modes are chosen, which should only happen if the symbol is before
582 // the instruction in the source file and there is some sort of ORG
583 // statement or similar in between which forces the address of this
584 // instruction, and the differences happen to cross the 8 bit boundary.
585 // For this reason, we use a heuristic and allow a margin on the 8
586 // bit boundary conditions.
578 v = as -> pretendmax; 587 v = as -> pretendmax;
579 as -> pretendmax = 1; 588 as -> pretendmax = 1;
580 lwasm_reduce_expr(as, e2); 589 lwasm_reduce_expr(as, e2);
581 as -> pretendmax = v; 590 as -> pretendmax = v;
582 v = lw_expr_intval(e2); 591 v = lw_expr_intval(e2);
583 if (v >= -128 || v <= 127) 592 // Actual range is -128 <= offset <= 127; we're allowing a fudge
593 // factor of 25 or so bytes so that we're less likely to accidentally
594 // cross into the 16 bit boundary in weird corner cases.
595 if (v >= -100 || v <= 100)
584 { 596 {
585 l -> lint = 1; 597 l -> lint = 1;
586 pb = (l -> pb & 0x80) ? 0x9C : 0x8C; 598 l -> pb = (l -> pb & 0x80) ? 0x9C : 0x8C;
587 return; 599 return;
588 } 600 }
589 } 601 }
590 } 602 }
591 lw_expr_destroy(e2); 603 lw_expr_destroy(e2);