Skip to content

Commit 289aea8

Browse files
committed
Output VCD file compliant with the standard
1 parent eea5ff4 commit 289aea8

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

pymtl3/datatypes/PythonBits.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,7 @@ def oct( self ):
529529
def hex( self ):
530530
str = "{:x}".format(int(self._uint)).zfill(((self._nbits-1)//4)+1)
531531
return "0x"+str
532+
533+
def bin_vcd(self):
534+
str = "{:b}".format(int(self._uint)).zfill(self._nbits)
535+
return str

pymtl3/datatypes/test/bits_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,4 @@ def test_bin_oct_hex():
760760
assert Bits(15,35).bin() == "0b000000000100011"
761761
assert Bits(15,35).oct() == "0o00043"
762762
assert Bits(15,35).hex() == "0x0023"
763+
assert Bits(15,35).vcd_bin() == "000000000100011"

pymtl3/passes/tracing/VcdGenerationPass.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def recurse_models( m, spaces ):
202202
for i, net in enumerate(trimmed_value_nets):
203203
# Convert everything to Bits to get around lack of bit struct support.
204204
# The first cycle VCD contains the default value
205-
bin_str = net[0]._dsl.Type().to_bits().bin()
205+
bin_str = net[0]._dsl.Type().to_bits().vcd_bin()
206206

207207
print( f"b{bin_str} {net_symbol_mapping[i]}", file=vcd_file )
208208

@@ -221,7 +221,7 @@ def recurse_models( m, spaces ):
221221
if i != vcd_clock_net_idx ]
222222

223223
# Flip clock for the first cycle
224-
print( '\n#0\nb0b1 {}\n'.format( clock_symbol ), file=vcd_file, flush=True )
224+
print( '\n#0\n1{}\n'.format( clock_symbol ), file=vcd_file, flush=True )
225225

226226
# Returns a dump_vcd function that is ready to be appended to _sched.
227227
# TODO: type check?
@@ -243,21 +243,21 @@ def dump_vcd_inner( s ):
243243
except Exception as e:
244244
raise TypeError(f'{e}\n - {signal} becomes another type. Please check your code.')
245245

246-
net_bits_bin_str = net_bits_bin.bin()
246+
net_bits_bin_str = net_bits_bin.vcd_bin()
247247
# `last_value` is the string form of a Bits object in binary
248-
# e.g. '0b000' == Bits3(0).bin()
248+
# e.g. '000' == Bits3(0).vcd_bin()
249249
# We store strings instead of values ...
250250
if last_values[i] != net_bits_bin_str:
251251
last_values[i] = net_bits_bin_str
252252
print( f'b{net_bits_bin_str} {symbol}', file=vcd_file )
253253

254254
# Flop clock at the end of cycle
255255
next_neg_edge = 100 * vcd_sim_ncycles + 50
256-
print( f'\n#{next_neg_edge}\nb0b0 {clock_symbol}', file=vcd_file )
256+
print( f'\n#{next_neg_edge}\n0{clock_symbol}', file=vcd_file )
257257

258258
# Flip clock of the next cycle
259259
next_pos_edge = next_neg_edge + 50
260-
print( f'#{next_pos_edge}\nb0b1 {clock_symbol}\n', file=vcd_file, flush=True )
260+
print( f'#{next_pos_edge}\n1{clock_symbol}\n', file=vcd_file, flush=True )
261261
vcd_sim_ncycles += 1
262262

263263
def gen_dump_vcd( s ):

0 commit comments

Comments
 (0)