Fixes error in parsing some disasm expressions. PiperOrigin-RevId: 696156669 Change-Id: I403a5799f3ac7e51bf7ffd632a369dfe945939db
diff --git a/mpact/sim/decoder/instruction_set_visitor.cc b/mpact/sim/decoder/instruction_set_visitor.cc index 0374561..acd112a 100644 --- a/mpact/sim/decoder/instruction_set_visitor.cc +++ b/mpact/sim/decoder/instruction_set_visitor.cc
@@ -2053,7 +2053,7 @@ if (num.empty()) { delete format_info; return absl::InternalError( - absl::StrCat("Malformed expression '", expr, "'")); + absl::StrCat("Malformed expression - no shift amount '", expr, "'")); } format_info->shift_amount = std::stoi(num); @@ -2063,13 +2063,14 @@ if (expr[pos] != ')') { delete format_info; return absl::InternalError( - absl::StrCat("Malformed expression '", expr, "'")); + absl::StrCat("Malformed expression - expected ')' '", expr, "'")); } + pos++; pos = skip_space(expr, pos); if (pos != std::string::npos) { delete format_info; - return absl::InternalError( - absl::StrCat("Malformed expression '", expr, "'")); + return absl::InternalError(absl::StrCat( + "Malformed expression - extra characters after ')' '", expr, "'")); } } return format_info;
diff --git a/mpact/sim/decoder/test/instruction_set_visitor_test.cc b/mpact/sim/decoder/test/instruction_set_visitor_test.cc index c1d7623..d5b0e74 100644 --- a/mpact/sim/decoder/test/instruction_set_visitor_test.cc +++ b/mpact/sim/decoder/test/instruction_set_visitor_test.cc
@@ -504,16 +504,18 @@ ptr = log_sink.error_log().find( "Error: Missing shift in expression '@+(rs1 +-)'"); EXPECT_TRUE(ptr != std::string::npos); - ptr = - log_sink.error_log().find("Error: Malformed expression '@+(rs1 << 5x)'"); + ptr = log_sink.error_log().find( + "Error: Malformed expression - expected ')' '@+(rs1 << 5x)'"); EXPECT_TRUE(ptr != std::string::npos); - ptr = log_sink.error_log().find("Error: Malformed expression '@+(rs1 >> )'"); + ptr = log_sink.error_log().find( + "Error: Malformed expression - no shift amount '@+(rs1 >> )'"); EXPECT_TRUE(ptr != std::string::npos); - ptr = - log_sink.error_log().find("Error: Malformed expression '@+(rs1 << 5 x)'"); + ptr = log_sink.error_log().find( + "Error: Malformed expression - expected ')' '@+(rs1 << 5 x)'"); EXPECT_TRUE(ptr != std::string::npos); - ptr = - log_sink.error_log().find("Error: Malformed expression '@+(rs1 << 5) x'"); + ptr = log_sink.error_log().find( + "Error: Malformed expression - extra characters after ')' '@+(rs1 << 5) " + "x'"); EXPECT_TRUE(ptr != std::string::npos); ptr = log_sink.error_log().find( "Error: Format width required when a leading 0 is specified - '0x'");