Refactor symbol value getters for less redundancy

This commit is contained in:
Rangi42
2024-09-09 09:35:58 -04:00
committed by Eldred Habert
parent 6bc2446966
commit 56af572bfd
2 changed files with 9 additions and 20 deletions

View File

@@ -78,7 +78,6 @@ void sym_Export(std::string const &symName);
Symbol *sym_AddEqu(std::string const &symName, int32_t value); Symbol *sym_AddEqu(std::string const &symName, int32_t value);
Symbol *sym_RedefEqu(std::string const &symName, int32_t value); Symbol *sym_RedefEqu(std::string const &symName, int32_t value);
Symbol *sym_AddVar(std::string const &symName, int32_t value); Symbol *sym_AddVar(std::string const &symName, int32_t value);
uint32_t sym_GetPCValue();
int32_t sym_GetRSValue(); int32_t sym_GetRSValue();
void sym_SetRSValue(int32_t value); void sym_SetRSValue(int32_t value);
uint32_t sym_GetConstantValue(std::string const &symName); uint32_t sym_GetConstantValue(std::string const &symName);

View File

@@ -51,9 +51,7 @@ static int32_t Callback_NARG() {
} }
static int32_t CallbackPC() { static int32_t CallbackPC() {
Section const *section = sect_GetSymbolSection(); return sect_GetSymbolSection()->org + sect_GetSymbolOffset();
return section ? section->org + sect_GetSymbolOffset() : 0;
} }
int32_t Symbol::getValue() const { int32_t Symbol::getValue() const {
@@ -201,18 +199,6 @@ bool sym_IsPurgedScoped(std::string const &symName) {
return sym_IsPurgedExact(symName); return sym_IsPurgedExact(symName);
} }
uint32_t sym_GetPCValue() {
Section const *sect = sect_GetSymbolSection();
if (!sect)
error("PC has no value outside of a section\n");
else if (sect->org == (uint32_t)-1)
error("PC does not have a constant value; the current section is not fixed\n");
else
return CallbackPC();
return 0;
}
int32_t sym_GetRSValue() { int32_t sym_GetRSValue() {
return _RSSymbol->getOutputValue(); return _RSSymbol->getOutputValue();
} }
@@ -224,13 +210,17 @@ void sym_SetRSValue(int32_t value) {
// Return a constant symbol's value, assuming it's defined // Return a constant symbol's value, assuming it's defined
uint32_t Symbol::getConstantValue() const { uint32_t Symbol::getConstantValue() const {
if (sym_IsPC(this))
return sym_GetPCValue();
if (isConstant()) if (isConstant())
return getValue(); return getValue();
if (sym_IsPC(this)) {
if (!getSection())
error("PC has no value outside of a section\n");
else
error("PC does not have a constant value; the current section is not fixed\n");
} else {
error("\"%s\" does not have a constant value\n", name.c_str()); error("\"%s\" does not have a constant value\n", name.c_str());
}
return 0; return 0;
} }