Fix concat of long hashed names in traces etc (#2854)

This commit is contained in:
Graham Rushton 2021-04-20 14:08:29 +01:00 committed by GitHub
parent c443e229ee
commit 6660627558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 87 additions and 24 deletions

View File

@ -23,6 +23,7 @@ Garrett Smith
Geza Lore Geza Lore
Gianfranco Costamagna Gianfranco Costamagna
Glen Gibb Glen Gibb
Graham Rushton
Harald Heckmann Harald Heckmann
Howard Su Howard Su
Huang Rui Huang Rui

View File

@ -380,12 +380,52 @@ void VHashSha256::selfTest() {
// VName // VName
string VName::dehash(const string& in) { string VName::dehash(const string& in) {
const string::size_type pos = in.find("__Vhsh"); static const char VHSH[] = "__Vhsh";
if (VL_LIKELY(pos == string::npos)) return in; static const size_t DOT_LEN = strlen("__DOT__");
const string vhsh = in.substr(pos); std::string dehashed;
const auto& it = s_dehashMap.find(vhsh);
UASSERT(it != s_dehashMap.end(), "String not in reverse hash map '" << vhsh << "'"); // Need to split 'in' into components separated by __DOT__, 'last_dot_pos'
return in.substr(0, pos) + it->second; // keeps track of the position after the most recently found instance of __DOT__
for (string::size_type last_dot_pos = 0; last_dot_pos < in.size(); ) {
const string::size_type next_dot_pos = in.find("__DOT__", last_dot_pos);
// Two iterators defining the range between the last and next dots.
auto search_begin = std::begin(in) + last_dot_pos;
auto search_end = next_dot_pos == string::npos ? std::end(in)
: std::begin(in) + next_dot_pos;
// Search for __Vhsh between the two dots.
auto begin_vhsh = std::search(search_begin, search_end,
std::begin(VHSH), std::end(VHSH) - 1);
if (begin_vhsh != search_end) {
std::string vhsh(begin_vhsh, search_end);
const auto& it = s_dehashMap.find(vhsh);
UASSERT(it != s_dehashMap.end(), "String not in reverse hash map '" << vhsh << "'");
// Is this not the first component, but the first to require dehashing?
if (last_dot_pos > 0 && dehashed.empty()) {
// Seed 'dehashed' with the previously processed components.
dehashed = in.substr(0, last_dot_pos);
}
// Append the unhashed part of the component.
dehashed += std::string(search_begin, begin_vhsh);
// Append the bit that was lost to truncation but retrieved from the dehash map.
dehashed += it->second;
}
// This component doesn't need dehashing but a previous one might have.
else if (!dehashed.empty()) {
dehashed += std::string(search_begin, search_end);
}
if (next_dot_pos != string::npos) {
// Is there a __DOT__ to add to the dehashed version of 'in'?
if (!dehashed.empty()) {
dehashed += "__DOT__";
}
last_dot_pos = next_dot_pos + DOT_LEN;
} else {
last_dot_pos = string::npos;
}
}
return dehashed.empty() ? in : dehashed;
} }
string VName::hashedName() { string VName::hashedName() {

View File

@ -39,6 +39,9 @@ $timescale 1ps $end
$var wire 2 % v_strp [1:0] $end $var wire 2 % v_strp [1:0] $end
$var wire 4 & v_strp_strp [3:0] $end $var wire 4 & v_strp_strp [3:0] $end
$var wire 2 ' v_unip_strp [1:0] $end $var wire 2 ' v_unip_strp [1:0] $end
$scope module a_module_instantiation_with_a_very_long_name_that_once_its_signals_get_concatenated_and_inlined_will_almost_certainly_result_in_them_getting_hashed $end
$var wire 32 J PARAM [31:0] $end
$upscope $end
$scope module p2 $end $scope module p2 $end
$var wire 32 H PARAM [31:0] $end $var wire 32 H PARAM [31:0] $end
$upscope $end $upscope $end
@ -92,6 +95,7 @@ b00000000 F
0G 0G
b00000000000000000000000000000010 H b00000000000000000000000000000010 H
b00000000000000000000000000000011 I b00000000000000000000000000000011 I
b00000000000000000000000000000100 J
#10 #10
b00000000000000000000000000000001 $ b00000000000000000000000000000001 $
b11 % b11 %

View File

@ -78,6 +78,8 @@ module t (clk);
p #(.PARAM(2)) p2 (); p #(.PARAM(2)) p2 ();
p #(.PARAM(3)) p3 (); p #(.PARAM(3)) p3 ();
p #(.PARAM(4)) a_module_instantiation_with_a_very_long_name_that_once_its_signals_get_concatenated_and_inlined_will_almost_certainly_result_in_them_getting_hashed ();
always @ (posedge clk) begin always @ (posedge clk) begin
cyc <= cyc + 1; cyc <= cyc + 1;
v_strp <= ~v_strp; v_strp <= ~v_strp;

View File

@ -58,15 +58,19 @@ $upscope $end
$scope module p3 $end $scope module p3 $end
$var parameter 32 B PARAM $end $var parameter 32 B PARAM $end
$upscope $end $upscope $end
$scope module a_module_instantiation_with_a_very_long_name_that_once_its_signals_get_concatenated_and_inlined_will_almost_certainly_result_in_them_getting_hashed $end
$var parameter 32 C PARAM $end
$upscope $end
$upscope $end $upscope $end
$scope module $unit $end $scope module $unit $end
$var bit 1 C global_bit $end $var bit 1 D global_bit $end
$upscope $end $upscope $end
$upscope $end $upscope $end
$enddefinitions $end $enddefinitions $end
#0
$dumpvars $dumpvars
1C #0
1D
b00000000000000000000000000000100 C
b00000000000000000000000000000011 B b00000000000000000000000000000011 B
b00000000000000000000000000000010 A b00000000000000000000000000000010 A
b00000000000000000000000000000000 @ b00000000000000000000000000000000 @
@ -101,7 +105,6 @@ b0000 $
b00 # b00 #
b00000000000000000000000000000000 " b00000000000000000000000000000000 "
0! 0!
$end
#10 #10
1! 1!
b00000000000000000000000000000001 " b00000000000000000000000000000001 "

View File

@ -1,5 +1,5 @@
$date $date
Thu Apr 1 15:12:03 2021 Mon Apr 19 17:05:53 2021
$end $end
$version $version
@ -57,15 +57,19 @@ $upscope $end
$scope module p3 $end $scope module p3 $end
$var parameter 32 B PARAM $end $var parameter 32 B PARAM $end
$upscope $end $upscope $end
$scope module a_module_instantiation_with_a_very_long_name_that_once_its_signals_get_concatenated_and_inlined_will_almost_certainly_result_in_them_getting_hashed $end
$var parameter 32 C PARAM $end
$upscope $end
$upscope $end $upscope $end
$scope module $unit $end $scope module $unit $end
$var bit 1 C global_bit $end $var bit 1 D global_bit $end
$upscope $end $upscope $end
$upscope $end $upscope $end
$enddefinitions $end $enddefinitions $end
#0
$dumpvars $dumpvars
1C #0
1D
b00000000000000000000000000000100 C
b00000000000000000000000000000011 B b00000000000000000000000000000011 B
b00000000000000000000000000000010 A b00000000000000000000000000000010 A
b00000000000000000000000000000000 @ b00000000000000000000000000000000 @
@ -100,7 +104,6 @@ b0000 $
b00 # b00 #
b00000000000000000000000000000000 " b00000000000000000000000000000000 "
0! 0!
$end
#10 #10
1! 1!
b00000000000000000000000000000001 " b00000000000000000000000000000001 "

View File

@ -39,6 +39,9 @@ $timescale 1ps $end
$var wire 2 % v_strp [1:0] $end $var wire 2 % v_strp [1:0] $end
$var wire 4 & v_strp_strp [3:0] $end $var wire 4 & v_strp_strp [3:0] $end
$var wire 2 ' v_unip_strp [1:0] $end $var wire 2 ' v_unip_strp [1:0] $end
$scope module a_module_instantiation_with_a_very_long_name_that_once_its_signals_get_concatenated_and_inlined_will_almost_certainly_result_in_them_getting_hashed $end
$var wire 32 J PARAM [31:0] $end
$upscope $end
$scope module p2 $end $scope module p2 $end
$var wire 32 H PARAM [31:0] $end $var wire 32 H PARAM [31:0] $end
$upscope $end $upscope $end
@ -92,6 +95,7 @@ b00000000 F
0G 0G
b00000000000000000000000000000010 H b00000000000000000000000000000010 H
b00000000000000000000000000000011 I b00000000000000000000000000000011 I
b00000000000000000000000000000100 J
#10 #10
b00000000000000000000000000000001 $ b00000000000000000000000000000001 $
b11 % b11 %

View File

@ -58,15 +58,19 @@ $upscope $end
$scope module p3 $end $scope module p3 $end
$var parameter 32 B PARAM $end $var parameter 32 B PARAM $end
$upscope $end $upscope $end
$scope module a_module_instantiation_with_a_very_long_name_that_once_its_signals_get_concatenated_and_inlined_will_almost_certainly_result_in_them_getting_hashed $end
$var parameter 32 C PARAM $end
$upscope $end
$upscope $end $upscope $end
$scope module $unit $end $scope module $unit $end
$var bit 1 C global_bit $end $var bit 1 D global_bit $end
$upscope $end $upscope $end
$upscope $end $upscope $end
$enddefinitions $end $enddefinitions $end
#0
$dumpvars $dumpvars
1C #0
1D
b00000000000000000000000000000100 C
b00000000000000000000000000000011 B b00000000000000000000000000000011 B
b00000000000000000000000000000010 A b00000000000000000000000000000010 A
b00000000000000000000000000000000 @ b00000000000000000000000000000000 @
@ -101,7 +105,6 @@ b0000 $
b00 # b00 #
b00000000000000000000000000000000 " b00000000000000000000000000000000 "
0! 0!
$end
#10 #10
1! 1!
b00000000000000000000000000000001 " b00000000000000000000000000000001 "

View File

@ -1,5 +1,5 @@
$date $date
Thu Apr 1 15:17:39 2021 Mon Apr 19 17:07:10 2021
$end $end
$version $version
@ -57,15 +57,19 @@ $upscope $end
$scope module p3 $end $scope module p3 $end
$var parameter 32 B PARAM $end $var parameter 32 B PARAM $end
$upscope $end $upscope $end
$scope module a_module_instantiation_with_a_very_long_name_that_once_its_signals_get_concatenated_and_inlined_will_almost_certainly_result_in_them_getting_hashed $end
$var parameter 32 C PARAM $end
$upscope $end
$upscope $end $upscope $end
$scope module $unit $end $scope module $unit $end
$var bit 1 C global_bit $end $var bit 1 D global_bit $end
$upscope $end $upscope $end
$upscope $end $upscope $end
$enddefinitions $end $enddefinitions $end
#0
$dumpvars $dumpvars
1C #0
1D
b00000000000000000000000000000100 C
b00000000000000000000000000000011 B b00000000000000000000000000000011 B
b00000000000000000000000000000010 A b00000000000000000000000000000010 A
b00000000000000000000000000000000 @ b00000000000000000000000000000000 @
@ -100,7 +104,6 @@ b0000 $
b00 # b00 #
b00000000000000000000000000000000 " b00000000000000000000000000000000 "
0! 0!
$end
#10 #10
1! 1!
b00000000000000000000000000000001 " b00000000000000000000000000000001 "