Pass std::string references to RPN functions

This commit is contained in:
Rangi42
2024-03-18 13:45:59 -04:00
committed by Sylvie
parent e96675be03
commit 05d79d87f6
5 changed files with 18 additions and 18 deletions

View File

@@ -43,10 +43,10 @@ void rpn_ISCONST(Expression &expr, Expression const &src);
void rpn_NEG(Expression &expr, Expression &&src);
void rpn_NOT(Expression &expr, Expression &&src);
void rpn_BankSymbol(Expression &expr, std::string const &symName);
void rpn_BankSection(Expression &expr, char const *sectionName);
void rpn_BankSection(Expression &expr, std::string const &sectionName);
void rpn_BankSelf(Expression &expr);
void rpn_SizeOfSection(Expression &expr, char const *sectionName);
void rpn_StartOfSection(Expression &expr, char const *sectionName);
void rpn_SizeOfSection(Expression &expr, std::string const &sectionName);
void rpn_StartOfSection(Expression &expr, std::string const &sectionName);
void rpn_SizeOfSectionType(Expression &expr, SectionType type);
void rpn_StartOfSectionType(Expression &expr, SectionType type);

View File

@@ -54,7 +54,7 @@ extern std::deque<Section> sectionList;
extern std::unordered_map<std::string, size_t> sectionMap; // Indexes into `sectionList`
extern Section *currentSection;
Section *sect_FindSectionByName(char const *name);
Section *sect_FindSectionByName(std::string const &name);
void sect_NewSection(
std::string const &name,
SectionType type,

View File

@@ -1415,13 +1415,13 @@ relocexpr_no_str:
rpn_BankSymbol($$, $3);
}
| OP_BANK LPAREN string RPAREN {
rpn_BankSection($$, $3.c_str());
rpn_BankSection($$, $3);
}
| OP_SIZEOF LPAREN string RPAREN {
rpn_SizeOfSection($$, $3.c_str());
rpn_SizeOfSection($$, $3);
}
| OP_STARTOF LPAREN string RPAREN {
rpn_StartOfSection($$, $3.c_str());
rpn_StartOfSection($$, $3);
}
| OP_SIZEOF LPAREN sectiontype RPAREN {
rpn_SizeOfSectionType($$, (SectionType)$3);

View File

@@ -126,7 +126,7 @@ void rpn_BankSymbol(Expression &expr, std::string const &symName) {
}
}
void rpn_BankSection(Expression &expr, char const *sectionName) {
void rpn_BankSection(Expression &expr, std::string const &sectionName) {
initExpression(expr);
Section *section = sect_FindSectionByName(sectionName);
@@ -136,16 +136,16 @@ void rpn_BankSection(Expression &expr, char const *sectionName) {
} else {
makeUnknown(expr, "Section \"", sectionName, "\"'s bank is not known");
size_t nameLen = strlen(sectionName) + 1; // Room for NUL!
size_t nameLen = sectionName.length() + 1; // Room for NUL!
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
expr.rpnPatchSize += nameLen + 1;
*ptr++ = RPN_BANK_SECT;
memcpy(ptr, sectionName, nameLen);
memcpy(ptr, sectionName.data(), nameLen);
}
}
void rpn_SizeOfSection(Expression &expr, char const *sectionName) {
void rpn_SizeOfSection(Expression &expr, std::string const &sectionName) {
initExpression(expr);
Section *section = sect_FindSectionByName(sectionName);
@@ -155,16 +155,16 @@ void rpn_SizeOfSection(Expression &expr, char const *sectionName) {
} else {
makeUnknown(expr, "Section \"", sectionName, "\"'s size is not known");
size_t nameLen = strlen(sectionName) + 1; // Room for NUL!
size_t nameLen = sectionName.length() + 1; // Room for NUL!
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
expr.rpnPatchSize += nameLen + 1;
*ptr++ = RPN_SIZEOF_SECT;
memcpy(ptr, sectionName, nameLen);
memcpy(ptr, sectionName.data(), nameLen);
}
}
void rpn_StartOfSection(Expression &expr, char const *sectionName) {
void rpn_StartOfSection(Expression &expr, std::string const &sectionName) {
initExpression(expr);
Section *section = sect_FindSectionByName(sectionName);
@@ -174,12 +174,12 @@ void rpn_StartOfSection(Expression &expr, char const *sectionName) {
} else {
makeUnknown(expr, "Section \"", sectionName, "\"'s start is not known");
size_t nameLen = strlen(sectionName) + 1; // Room for NUL!
size_t nameLen = sectionName.length() + 1; // Room for NUL!
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
expr.rpnPatchSize += nameLen + 1;
*ptr++ = RPN_STARTOF_SECT;
memcpy(ptr, sectionName, nameLen);
memcpy(ptr, sectionName.data(), nameLen);
}
}

View File

@@ -109,7 +109,7 @@ attr_(warn_unused_result) static bool reserveSpace(uint32_t delta_size) {
&& (!currentLoadSection || currentLoadSection->size != UINT32_MAX);
}
Section *sect_FindSectionByName(char const *name) {
Section *sect_FindSectionByName(std::string const &name) {
auto search = sectionMap.find(name);
return search != sectionMap.end() ? &sectionList[search->second] : nullptr;
}
@@ -401,7 +401,7 @@ static Section *getSection(
// Check if another section exists with the same name; merge if yes, otherwise create one
Section *sect = sect_FindSectionByName(name.c_str());
Section *sect = sect_FindSectionByName(name);
if (sect) {
mergeSections(*sect, type, org, bank, alignment, alignOffset, mod);