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

Signal value random access fails with "IndexError: list index out of range" when accessing a time value larger than the last time of the last tv #13

Closed rob0tsunny closed 3 years ago

rob0tsunny commented 3 years ago

Hi,

I have a waveform where a lot of signals are toggling, however one signal toggled very few times. For example, let's say my time range from 0 to 1000. signal A changes its value at 800,900,1000. signal B changes its value only at 10, 20,30. In VCD file A values all way up to 1000 are defined, however the last record for B ends at 30. If I try to get signal value like this: vcd['B'][500] I get an error from inside the library:

~/opt/anaconda3/lib/python3.7/site-packages/vcdvcd/vcdvcd.py in __getitem__(self, time)
    267         """
    268         left = bisect.bisect_left(self.tv, (time, ''))
--> 269         if self.tv[left][0] == time:
    270             i = left
    271         else:

IndexError: list index out of range

I think the appropriate fix you be return the last value for that signal - in my example - you know value doesn't change after 30. so the correct answer for 500 should be the last value - the same for 30 timestamp.

rob0tsunny commented 3 years ago

attached a proposed fix as a file fix.diff.txt

rob0tsunny commented 3 years ago

the proposed fix works really great for me. please consider it to accept to your code base

cirosantilli commented 3 years ago

Thanks!