cirosantilli / vcdvcd

Python Verilog value change dump (VCD) parser library + the nifty vcdcat VCD command line pretty printer.
Other
54 stars 21 forks source link

vcdcat misses last time period #21

Closed GCHQDeveloper560 closed 3 years ago

GCHQDeveloper560 commented 3 years ago

The default case of ./vcdcat counter_tb.vcd produces the following:

0 time
1 counter_tb.clock
2 counter_tb.enable
3 counter_tb.out[1:0]
4 counter_tb.reset
5 counter_tb.top.out[1:0]

0 1 2 3 4 5
===========
0 1 0 x 0 x
1 0 0 x 1 x
2 1 0 0 1 0
<snip>
23 0 1 1 0 1
24 1 1 2 0 2
25 0 0 2 0 2

However, ./vcdcat -d counter_tb.vcd produces

0 x counter_tb.top.out[1:0]
0 0 counter_tb.reset
0 0 counter_tb.enable
0 1 counter_tb.clock
0 x counter_tb.out[1:0]
1 0 counter_tb.clock
1 1 counter_tb.reset
2 0 counter_tb.out[1:0]
2 0 counter_tb.top.out[1:0]
2 1 counter_tb.clock
<snip>
23 0 counter_tb.clock
24 2 counter_tb.out[1:0]
24 2 counter_tb.top.out[1:0]
24 1 counter_tb.clock
25 0 counter_tb.clock
25 0 counter_tb.enable
26 1 counter_tb.clock

From the end of the VCD file:

#24
b10 !
b10 %
1"
#25
0"
0#
#26
1"

there is a time 26 with a rising clock edge which the default vcdcat case is missing.

It appears that the delta option uses PrintDeltasStreamParserCallbacks and therefore the value callback method, which works as expected. However, the default case uses PrintDumpsStreamParserCallbacks and the time callback method. Since this callback happens before any of the values for the new time period are processed it is only able to handle values from the previous time period. Since there are no more time periods in the file the time callback isn't able to print the final value.

One option would be to just switch PrintDumpsStreamParserCallbacks to use the value callback. However, using time in this way seems more generally useful. Rather than drastically change the behaviour of the time callback perhaps an endfile callback or similar would make sense? For PrintDumpsStreamParserCallbacks and similar code the endfile callback could just call the same code as the time callback, catching the final time period. There may also be other cases where a final processing step at the end of the file would be useful.

Thoughts? I have a quick implementation of endfile I can submit if that's the way you'd like to go.

cirosantilli commented 3 years ago

Thanks for this and the other ticket!

I tried to fix this at: 6fd3a17bc40f60dd9ad990a64e05ef27f8774c86 now, let me know if any of the problems remain.

Sorry I took a while, last month was a bit crazy.