Skip to content

Commit

Permalink
fix CSR::RegisterMapByName key type to std::string
Browse files Browse the repository at this point in the history
  • Loading branch information
trdthg authored and jdupak committed Jun 29, 2024
1 parent 68a1b3a commit 853dcc9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/machine/csr/controlstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,16 @@ namespace machine { namespace CSR {

class RegisterMapByName {
bool initialized = false;
std::unordered_map<const char *, size_t> map;
std::unordered_map<std::string, size_t> map;

void init() {
for (size_t i = 0; i < REGISTERS.size(); i++) {
map.emplace(REGISTERS[i].name, i);
map.emplace(std::string(REGISTERS[i].name), i);
}
initialized = true;
}
public:
size_t at(const char* name) {
size_t at(std::string name) {
if (!initialized) init();
return map.at(name);
}
Expand Down
11 changes: 6 additions & 5 deletions src/machine/instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,14 +1375,15 @@ bool parse_immediate_value(

uint16_t parse_csr_address(const QString &field_token, uint &chars_taken) {
if (field_token.at(0).isLetter()) {
size_t index = CSR::REGISTER_MAP_BY_NAME.at(qPrintable(field_token));
if (index < 0) {
try {
size_t index = CSR::REGISTER_MAP_BY_NAME.at(field_token.toStdString());
auto &reg = CSR::REGISTERS[index];
chars_taken = strlen(reg.name);
return reg.address.data;
} catch (std::out_of_range &e) {
chars_taken = 0;
return 0;
}
auto &reg = CSR::REGISTERS[index];
chars_taken = strlen(reg.name);
return reg.address.data;
} else {
char *r;
uint64_t val;
Expand Down

0 comments on commit 853dcc9

Please sign in to comment.