Ignore RPN strings when their value is known

This commit is contained in:
ISSOtm
2020-01-20 17:05:49 +01:00
parent 9fb9e63554
commit f9c25608e9
2 changed files with 213 additions and 163 deletions

View File

@@ -861,14 +861,25 @@ void out_PCRelByte(struct Expression *expr)
{
checkcodesection();
checksectionoverflow(1);
if (!rpn_isKnown(expr) || pCurrentSection->nOrg == -1) {
pCurrentSection->tData[nPC] = 0;
createpatch(PATCHTYPE_JR, expr);
pCurrentSection->nPC++;
nPC++;
pPCSymbol->nValue++;
} else {
/* Target is relative to the byte *after* the operand */
uint16_t address = pCurrentSection->nOrg + nPC + 1;
/* The offset wraps (jump from ROM to HRAM, for loopexample) */
int16_t offset = expr->nVal - address;
/* Always let the linker calculate the offset. */
pCurrentSection->tData[nPC] = 0;
createpatch(PATCHTYPE_JR, expr);
pCurrentSection->nPC++;
nPC++;
pPCSymbol->nValue++;
if (offset < -128 || offset > 127) {
yyerror("jr target out of reach (expected -129 < %d < 128)", offset);
out_AbsByte(0);
} else {
out_AbsByte(offset);
}
}
rpn_Free(expr);
}