mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Don't call rpn.clear() when we can safely assume it's already empty()
This commit is contained in:
@@ -43,9 +43,9 @@ struct Expression {
|
||||
void makeUnaryOp(RPNCommand op, Expression &&src);
|
||||
void makeBinaryOp(RPNCommand op, Expression &&src1, Expression const &src2);
|
||||
|
||||
void makeCheckHRAM();
|
||||
void makeCheckRST();
|
||||
void makeCheckBitIndex(uint8_t mask);
|
||||
void addCheckHRAM();
|
||||
void addCheckRST();
|
||||
void addCheckBitIndex(uint8_t mask);
|
||||
|
||||
void checkNBit(uint8_t n) const;
|
||||
};
|
||||
|
||||
@@ -1891,7 +1891,7 @@ sm83_and:
|
||||
sm83_bit:
|
||||
SM83_BIT reloc_3bit COMMA reg_r {
|
||||
uint8_t mask = static_cast<uint8_t>(0x40 | $4);
|
||||
$2.makeCheckBitIndex(mask);
|
||||
$2.addCheckBitIndex(mask);
|
||||
sect_ConstByte(0xCB);
|
||||
if (!$2.isKnown()) {
|
||||
sect_RelByte($2, 0);
|
||||
@@ -2024,7 +2024,7 @@ sm83_ldd:
|
||||
|
||||
sm83_ldh:
|
||||
SM83_LDH MODE_A COMMA op_mem_ind {
|
||||
$4.makeCheckHRAM();
|
||||
$4.addCheckHRAM();
|
||||
sect_ConstByte(0xF0);
|
||||
if (!$4.isKnown()) {
|
||||
sect_RelByte($4, 1);
|
||||
@@ -2033,7 +2033,7 @@ sm83_ldh:
|
||||
}
|
||||
}
|
||||
| SM83_LDH op_mem_ind COMMA MODE_A {
|
||||
$2.makeCheckHRAM();
|
||||
$2.addCheckHRAM();
|
||||
sect_ConstByte(0xE0);
|
||||
if (!$2.isKnown()) {
|
||||
sect_RelByte($2, 1);
|
||||
@@ -2217,7 +2217,7 @@ sm83_push:
|
||||
sm83_res:
|
||||
SM83_RES reloc_3bit COMMA reg_r {
|
||||
uint8_t mask = static_cast<uint8_t>(0x80 | $4);
|
||||
$2.makeCheckBitIndex(mask);
|
||||
$2.addCheckBitIndex(mask);
|
||||
sect_ConstByte(0xCB);
|
||||
if (!$2.isKnown()) {
|
||||
sect_RelByte($2, 0);
|
||||
@@ -2296,7 +2296,7 @@ sm83_rrca:
|
||||
|
||||
sm83_rst:
|
||||
SM83_RST reloc_8bit {
|
||||
$2.makeCheckRST();
|
||||
$2.addCheckRST();
|
||||
if (!$2.isKnown()) {
|
||||
sect_RelByte($2, 0);
|
||||
} else {
|
||||
@@ -2324,7 +2324,7 @@ sm83_scf:
|
||||
sm83_set:
|
||||
SM83_SET reloc_3bit COMMA reg_r {
|
||||
uint8_t mask = static_cast<uint8_t>(0xC0 | $4);
|
||||
$2.makeCheckBitIndex(mask);
|
||||
$2.addCheckBitIndex(mask);
|
||||
sect_ConstByte(0xCB);
|
||||
if (!$2.isKnown()) {
|
||||
sect_RelByte($2, 0);
|
||||
|
||||
@@ -54,12 +54,12 @@ bool Expression::isDiffConstant(Symbol const *sym) const {
|
||||
}
|
||||
|
||||
void Expression::makeNumber(uint32_t value) {
|
||||
rpn.clear();
|
||||
assume(rpn.empty());
|
||||
data = static_cast<int32_t>(value);
|
||||
}
|
||||
|
||||
void Expression::makeSymbol(std::string const &symName) {
|
||||
rpn.clear();
|
||||
assume(rpn.empty());
|
||||
if (Symbol *sym = sym_FindScopedSymbol(symName); sym_IsPC(sym) && !sect_GetSymbolSection()) {
|
||||
error("PC has no value outside of a section");
|
||||
data = 0;
|
||||
@@ -80,7 +80,7 @@ void Expression::makeSymbol(std::string const &symName) {
|
||||
}
|
||||
|
||||
void Expression::makeBankSymbol(std::string const &symName) {
|
||||
rpn.clear();
|
||||
assume(rpn.empty());
|
||||
if (Symbol const *sym = sym_FindScopedSymbol(symName); sym_IsPC(sym)) {
|
||||
// The @ symbol is treated differently.
|
||||
if (std::optional<uint32_t> outputBank = sect_GetOutputBank(); !outputBank) {
|
||||
@@ -111,7 +111,7 @@ void Expression::makeBankSymbol(std::string const &symName) {
|
||||
}
|
||||
|
||||
void Expression::makeBankSection(std::string const §Name) {
|
||||
rpn.clear();
|
||||
assume(rpn.empty());
|
||||
if (Section *sect = sect_FindSectionByName(sectName); sect && sect->bank != UINT32_MAX) {
|
||||
data = static_cast<int32_t>(sect->bank);
|
||||
} else {
|
||||
@@ -121,7 +121,7 @@ void Expression::makeBankSection(std::string const §Name) {
|
||||
}
|
||||
|
||||
void Expression::makeSizeOfSection(std::string const §Name) {
|
||||
rpn.clear();
|
||||
assume(rpn.empty());
|
||||
if (Section *sect = sect_FindSectionByName(sectName); sect && sect->isSizeKnown()) {
|
||||
data = static_cast<int32_t>(sect->size);
|
||||
} else {
|
||||
@@ -131,7 +131,7 @@ void Expression::makeSizeOfSection(std::string const §Name) {
|
||||
}
|
||||
|
||||
void Expression::makeStartOfSection(std::string const §Name) {
|
||||
rpn.clear();
|
||||
assume(rpn.empty());
|
||||
if (Section *sect = sect_FindSectionByName(sectName); sect && sect->org != UINT32_MAX) {
|
||||
data = static_cast<int32_t>(sect->org);
|
||||
} else {
|
||||
@@ -141,13 +141,13 @@ void Expression::makeStartOfSection(std::string const §Name) {
|
||||
}
|
||||
|
||||
void Expression::makeSizeOfSectionType(SectionType type) {
|
||||
rpn.clear();
|
||||
assume(rpn.empty());
|
||||
data = "Section type's size is not known";
|
||||
rpn.push_back({.command = RPN_SIZEOF_SECTTYPE, .data = static_cast<uint8_t>(type)});
|
||||
}
|
||||
|
||||
void Expression::makeStartOfSectionType(SectionType type) {
|
||||
rpn.clear();
|
||||
assume(rpn.empty());
|
||||
data = "Section type's start is not known";
|
||||
rpn.push_back({.command = RPN_STARTOF_SECTTYPE, .data = static_cast<uint8_t>(type)});
|
||||
}
|
||||
@@ -247,7 +247,7 @@ static int32_t tryConstMask(Expression const &lhs, Expression const &rhs) {
|
||||
}
|
||||
|
||||
void Expression::makeUnaryOp(RPNCommand op, Expression &&src) {
|
||||
rpn.clear();
|
||||
assume(rpn.empty());
|
||||
// First, check if the expression is known
|
||||
if (src.isKnown()) {
|
||||
// If the expressions is known, just compute the value
|
||||
@@ -292,7 +292,7 @@ void Expression::makeUnaryOp(RPNCommand op, Expression &&src) {
|
||||
}
|
||||
|
||||
void Expression::makeBinaryOp(RPNCommand op, Expression &&src1, Expression const &src2) {
|
||||
rpn.clear();
|
||||
assume(rpn.empty());
|
||||
// First, check if the expressions are known
|
||||
if (src1.isKnown() && src2.isKnown()) {
|
||||
// If both expressions are known, just compute the value
|
||||
@@ -447,7 +447,7 @@ void Expression::makeBinaryOp(RPNCommand op, Expression &&src1, Expression const
|
||||
}
|
||||
}
|
||||
|
||||
void Expression::makeCheckHRAM() {
|
||||
void Expression::addCheckHRAM() {
|
||||
if (!isKnown()) {
|
||||
rpn.push_back({.command = RPN_HRAM, .data = std::monostate{}});
|
||||
} else if (int32_t val = value(); val >= 0xFF00 && val <= 0xFFFF) {
|
||||
@@ -458,7 +458,7 @@ void Expression::makeCheckHRAM() {
|
||||
}
|
||||
}
|
||||
|
||||
void Expression::makeCheckRST() {
|
||||
void Expression::addCheckRST() {
|
||||
if (!isKnown()) {
|
||||
rpn.push_back({.command = RPN_RST, .data = std::monostate{}});
|
||||
} else if (int32_t val = value(); val & ~0x38) {
|
||||
@@ -467,7 +467,7 @@ void Expression::makeCheckRST() {
|
||||
}
|
||||
}
|
||||
|
||||
void Expression::makeCheckBitIndex(uint8_t mask) {
|
||||
void Expression::addCheckBitIndex(uint8_t mask) {
|
||||
assume((mask & 0xC0) != 0x00); // The high two bits must correspond to BIT, RES, or SET
|
||||
if (!isKnown()) {
|
||||
rpn.push_back({.command = RPN_BIT_INDEX, .data = mask});
|
||||
|
||||
Reference in New Issue
Block a user