Skip to content

Commit

Permalink
Fix: handle VCD variable references with and without whitespace
Browse files Browse the repository at this point in the history
Co-authored-by: Miodrag Milanović <[email protected]>
Co-authored-by: Roland Coeurjoly <[email protected]>
  • Loading branch information
RCoeurjoly and mmicko committed Sep 30, 2024
1 parent 59404f8 commit 79a60a6
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
10 changes: 9 additions & 1 deletion kernel/fstdata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,22 @@ void FstData::extractVarNames()
if (!var.is_alias)
handle_to_var[h->u.var.handle] = var;
std::string clean_name;
bool has_space = false;
for(size_t i=0;i<strlen(h->u.var.name);i++)
{
char c = h->u.var.name[i];
if(c==' ') break;
if(c==' ') { has_space = true; break; }
clean_name += c;
}
if (clean_name[0]=='\\')
clean_name = clean_name.substr(1);
if (!has_space) {
size_t pos = clean_name.find_last_of("[");
std::string addr = clean_name.substr(pos+1);
if (addr.find(":") != std::string::npos) {
clean_name = clean_name.substr(0,pos);
}
}
size_t pos = clean_name.find_last_of("<");
if (pos != std::string::npos && clean_name.back() == '>') {
std::string mem_cell = clean_name.substr(0, pos);
Expand Down
28 changes: 28 additions & 0 deletions tests/sim/var_reference_with_whitespace.vcd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$date
Fri Sep 27 11:58:46 2024
$end
$version
GHDL v0
$end
$timescale
1 fs
$end
$scope module standard $end
$upscope $end
$scope module std_logic_1164 $end
$upscope $end
$scope module tb $end
$var reg 4 ! a [3:0] $end
$var reg 4 " b [3:0] $end
$scope module uut $end
$var reg 4 # a [3:0] $end
$var reg 4 $ b [3:0] $end
$upscope $end
$upscope $end
$enddefinitions $end
#0
b0001 !
b0001 "
b0001 #
b0001 $
#10000000
28 changes: 28 additions & 0 deletions tests/sim/var_reference_without_whitespace.vcd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$date
Fri Sep 27 11:58:46 2024
$end
$version
GHDL v0
$end
$timescale
1 fs
$end
$scope module standard $end
$upscope $end
$scope module std_logic_1164 $end
$upscope $end
$scope module tb $end
$var reg 4 ! a[3:0] $end
$var reg 4 " b[3:0] $end
$scope module uut $end
$var reg 4 # a[3:0] $end
$var reg 4 $ b[3:0] $end
$upscope $end
$upscope $end
$enddefinitions $end
#0
b0001 !
b0001 "
b0001 #
b0001 $
#10000000
3 changes: 3 additions & 0 deletions tests/sim/vcd_var_reference_whitespace.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
read_rtlil vector_assign.il
sim -r var_reference_without_whitespace.vcd -scope tb.uut
sim -r var_reference_with_whitespace.vcd -scope tb.uut
20 changes: 20 additions & 0 deletions tests/sim/vector_assign.il
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Yosys 0.45+139 (git sha1 e7fc1b0cc, g++ 13.2.0 -fPIC -O3)
autoidx 2
attribute \architecture "Behavioral"
attribute \library "work"
attribute \hdlname "vector_assign"
attribute \src "tests/verific/vector_assign.vhd:4.8-4.21"
module \vector_assign
attribute \src "tests/verific/vector_assign.vhd:6.9-6.10"
wire width 4 input 2 \a
attribute \src "tests/verific/vector_assign.vhd:7.9-7.10"
wire width 4 output 1 \b
attribute \src "tests/verific/vector_assign.vhd:13.5-13.6"
cell $pos $verific$buf_3$tests/verific/vector_assign.vhd:13$1
parameter \A_SIGNED 0
parameter \A_WIDTH 4
parameter \Y_WIDTH 4
connect \A \a
connect \Y \b
end
end

0 comments on commit 79a60a6

Please sign in to comment.