Allow the bit/res/set bit index to be determined at link time (#1654)

This increments the object file revision number from 11 to 12
since it adds a new `RPN_BIT_INDEX` command.
This commit is contained in:
Rangi
2025-02-12 17:14:10 +01:00
committed by GitHub
parent 48412e9c56
commit 2aef09c8d9
12 changed files with 97 additions and 19 deletions

View File

@@ -355,6 +355,7 @@ void Expression::makeUnaryOp(RPNCommand op, Expression &&src) {
case RPN_STARTOF_SECTTYPE:
case RPN_HRAM:
case RPN_RST:
case RPN_BIT_INDEX:
case RPN_CONST:
case RPN_SYM:
fatalerror("%d is not an unary operator\n", op);
@@ -514,6 +515,7 @@ void Expression::makeBinaryOp(RPNCommand op, Expression &&src1, Expression const
case RPN_STARTOF_SECTTYPE:
case RPN_HRAM:
case RPN_RST:
case RPN_BIT_INDEX:
case RPN_HIGH:
case RPN_LOW:
case RPN_BITWIDTH:
@@ -608,6 +610,20 @@ void Expression::makeCheckRST() {
}
}
void Expression::makeCheckBitIndex(uint8_t mask) {
assume((mask & 0xC0) != 0x00); // The high two bits must correspond to BIT, RES, or SET
if (!isKnown()) {
uint8_t *ptr = reserveSpace(2);
*ptr++ = RPN_BIT_INDEX;
*ptr = mask;
} else if (int32_t val = value(); val & ~0x07) {
// A valid bit index must be masked with 0x07
static char const *instructions[4] = {"instruction", "BIT", "RES", "SET"};
error("Invalid bit index %" PRId32 " for %s\n", val, instructions[mask >> 6]);
}
}
// Checks that an RPN expression's value fits within N bits (signed or unsigned)
void Expression::checkNBit(uint8_t n) const {
if (isKnown()) {