Parsing a VCD File
Once you have generated a VCD file, PySilicon provides a VcdParser tool for reading the data into python for analysis.
Loading the VCD file
First, we load the VCD file into a VCDVCD object. For example, if the file is dump.vcd:
from vcdvcd import VCDVCD
vcd = VCDVCD('dump.vcd', signals=None, store_tvs=True)
You can see the names of the signals in vcd with:
# Print number of signals
nsig = len(vcd.signals)
print(f"Number of signals in VCD: {nsig}")
# Find the signals with TDATA in their names
tdatas = [s for s in vcd.signals if 'TDATA' in s]
print(tdatas)
Creating a VCD Parser and Adding Signals
Then, we create a PySilicon VcdParser object:
from pysilicon.utils.vcd import VcdParser
vp = VcdParser(vcd)
You can add signals to the parser as:
sig_name = 'apatb_poly_top.AESL_inst_poly.in_stream_TDATA[31:0]'
short_name = 'in_stream_TDATA'
vp.add_signal(name=sig_name, short_name=short_name)
where sig_name is the name of the signal in the VCD and short_name is an optional (typically shorter)
name since the Vitis names for simulation are typically very long and do not display well.
You can also load a clock signal:
clk_name = vp.add_clock_signal()
Viewing Signals on a Timing Diagram
To view signals on a timing diagram:
# Get the timing signals
sig_list = vp.get_td_signals()
# Create the timing diagram
td = TimingDiagram()
td.add_signals(sig_list)
trange = None
ax = td.plot_signals(add_clk_grid=True, trange=trange,
text_scale_factor=1e4, text_mode='never')
_ = ax.set_xlabel('Time [ns]')