Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine: fix CSR::RegisterMapByName key type to std::string #142

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading