File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -253,7 +253,25 @@ namespace machine { namespace CSR {
253253 }
254254 };
255255
256+ class RegisterMapByName {
257+ bool initialized = false ;
258+ std::unordered_map<const char *, size_t > map;
259+
260+ void init () {
261+ for (size_t i = 0 ; i < REGISTERS.size (); i++) {
262+ map.emplace (REGISTERS[i].name , i);
263+ }
264+ initialized = true ;
265+ }
266+ public:
267+ size_t at (const char * name) {
268+ if (!initialized) init ();
269+ return map.at (name);
270+ }
271+ };
272+
256273 static RegisterMap REGISTER_MAP;
274+ static RegisterMapByName REGISTER_MAP_BY_NAME;
257275}} // namespace machine::CSR
258276
259277Q_DECLARE_METATYPE (machine::CSR::ControlState)
Original file line number Diff line number Diff line change @@ -145,6 +145,7 @@ struct InstructionMap {
145145#define IT_U Instruction::U
146146#define IT_J Instruction::J
147147#define IT_AMO Instruction::AMO
148+ #define IT_ZICSR Instruction::ZICSR
148149#define IT_UNKNOWN Instruction::UNKNOWN
149150
150151// clang-format off
@@ -1374,15 +1375,14 @@ bool parse_immediate_value(
13741375
13751376uint16_t parse_csr_address (const QString &field_token, uint &chars_taken) {
13761377 if (field_token.at (0 ).isLetter ()) {
1377- // TODO maybe optimize
1378- for (auto ® : CSR::REGISTERS) {
1379- if (field_token.startsWith (reg.name , Qt::CaseInsensitive)) {
1380- chars_taken = strlen (reg.name );
1381- return reg.address .data ;
1382- }
1378+ size_t index = CSR::REGISTER_MAP_BY_NAME.at (qPrintable (field_token));
1379+ if (index < 0 ) {
1380+ chars_taken = 0 ;
1381+ return 0 ;
13831382 }
1384- chars_taken = 0 ;
1385- return 0 ;
1383+ auto ® = CSR::REGISTERS[index];
1384+ chars_taken = strlen (reg.name );
1385+ return reg.address .data ;
13861386 } else {
13871387 char *r;
13881388 uint64_t val;
You can’t perform that action at this time.
0 commit comments