diff --git a/include/asm/rpn.hpp b/include/asm/rpn.hpp index 22a073e4..c2e47046 100644 --- a/include/asm/rpn.hpp +++ b/include/asm/rpn.hpp @@ -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 §ionName); 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 §ionName); +void rpn_StartOfSection(Expression &expr, std::string const §ionName); void rpn_SizeOfSectionType(Expression &expr, SectionType type); void rpn_StartOfSectionType(Expression &expr, SectionType type); diff --git a/include/asm/section.hpp b/include/asm/section.hpp index 68bc7d86..fe670c21 100644 --- a/include/asm/section.hpp +++ b/include/asm/section.hpp @@ -54,7 +54,7 @@ extern std::deque
sectionList; extern std::unordered_map 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, diff --git a/src/asm/parser.y b/src/asm/parser.y index 923ee23e..8b8d05dd 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -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); diff --git a/src/asm/rpn.cpp b/src/asm/rpn.cpp index 070f6399..97a10d71 100644 --- a/src/asm/rpn.cpp +++ b/src/asm/rpn.cpp @@ -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 §ionName) { 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 §ionName) { 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 §ionName) { 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); } } diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 1047e2f6..f0dbbe9a 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -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() ? §ionList[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);