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
Gianfranco Costamagna
Glen Gibb
Graham Rushton
Harald Heckmann
Howard Su
Huang Rui

View File

@ -380,12 +380,52 @@ void VHashSha256::selfTest() {
// VName
string VName::dehash(const string& in) {
const string::size_type pos = in.find("__Vhsh");
if (VL_LIKELY(pos == string::npos)) return in;
const string vhsh = in.substr(pos);
const auto& it = s_dehashMap.find(vhsh);
UASSERT(it != s_dehashMap.end(), "String not in reverse hash map '" << vhsh << "'");
return in.substr(0, pos) + it->second;
static const char VHSH[] = "__Vhsh";
static const size_t DOT_LEN = strlen("__DOT__");
std::string dehashed;
// Need to split 'in' into components separated by __DOT__, 'last_dot_pos'
// 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() {

View File

@ -39,6 +39,9 @@ $timescale 1ps $end
$var wire 2 % v_strp [1:0] $end
$var wire 4 & v_strp_strp [3: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
$var wire 32 H PARAM [31:0] $end
$upscope $end
@ -92,6 +95,7 @@ b00000000 F
0G
b00000000000000000000000000000010 H
b00000000000000000000000000000011 I
b00000000000000000000000000000100 J
#10
b00000000000000000000000000000001 $
b11 %

View File

@ -78,6 +78,8 @@ module t (clk);
p #(.PARAM(2)) p2 ();
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
cyc <= cyc + 1;
v_strp <= ~v_strp;

View File

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

View File

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

View File

@ -39,6 +39,9 @@ $timescale 1ps $end
$var wire 2 % v_strp [1:0] $end
$var wire 4 & v_strp_strp [3: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
$var wire 32 H PARAM [31:0] $end
$upscope $end
@ -92,6 +95,7 @@ b00000000 F
0G
b00000000000000000000000000000010 H
b00000000000000000000000000000011 I
b00000000000000000000000000000100 J
#10
b00000000000000000000000000000001 $
b11 %

View File

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

View File

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