From 33f0d1bd576cc77d7d3a665a6d39630926026888 Mon Sep 17 00:00:00 2001 From: acharris Date: Wed, 26 Aug 2020 12:35:00 -0400 Subject: [PATCH 1/2] updated version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5dfa092..bc30d7f 100755 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ def readme(): setup( name='vcdvcd', - version='1.0.6', + version='1.0.7', description='Python Verilog value change dump (VCD) parser library + the nifty vcdcat VCD command line viewer', long_description=readme(), long_description_content_type='text/plain', From 74bae533c17c119e6a3c6b7dc5d56465125b5eb0 Mon Sep 17 00:00:00 2001 From: acharris Date: Wed, 26 Aug 2020 12:42:45 -0400 Subject: [PATCH 2/2] Added get_dumps and get_sorted_sig_dump You can use print_dumps tag as before to print automatically to the console OR you can return the results of a print_dump using get_dumps and get_sorted_sig_dump. These are separate since the user might want just one or the other. --- examples.py | 21 ++++++++++++++- vcdvcd/vcdvcd.py | 68 +++++++++++++++++++++++++++++++----------------- 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/examples.py b/examples.py index 0dd71f5..31089a0 100755 --- a/examples.py +++ b/examples.py @@ -13,6 +13,13 @@ vcd_path = 'counter_tb.vcd' pp = PrettyPrinter() + +print('# get_signals()') +vcd = VCDVCD(vcd_path, only_sigs=True) +sigs = vcd.get_signals() +pp.pprint(sigs) +for i in sigs: + print(i.split(".")) print('# get_data()') vcd = VCDVCD(vcd_path) pp.pprint(vcd.get_data()) @@ -23,6 +30,16 @@ PrettyPrinter().pprint(vcd.get_data()) print() +print('# get_sorted_sig_dumps') +vcd = VCDVCD(vcd_path) +pp.pprint(vcd.get_sorted_sig_dumps()) +print() + +print('# get_dumps()') +vcd = VCDVCD(vcd_path) +pp.pprint(vcd.get_dumps()) +print() + print('# get_signals()') vcd = VCDVCD(vcd_path, only_sigs=True) pp.pprint(vcd.get_signals()) @@ -49,9 +66,11 @@ print() print('# __init__(print_dumps=True)') -VCDVCD(vcd_path, print_dumps=True) +myString = VCDVCD(vcd_path, print_dumps=True) +print(type(myString)) print() + print('# __init__(print_dumps=True, store_tvs=False)') vcd = VCDVCD(vcd_path, print_dumps=True, store_tvs=False) PrettyPrinter().pprint(vcd.get_data()) diff --git a/vcdvcd/vcdvcd.py b/vcdvcd/vcdvcd.py index b8b6085..d02e81f 100644 --- a/vcdvcd/vcdvcd.py +++ b/vcdvcd/vcdvcd.py @@ -56,6 +56,8 @@ def __init__( self._signals = [] self._store_tvs = store_tvs self._signal_changed = False + self._dumps = [] + self._sorted = [] all_sigs = not signals cur_sig_vals = {} @@ -86,15 +88,18 @@ def __init__( time, value, identifier_code, print_deltas, print_dumps, cur_sig_vals ) - elif line0 == '#': - if print_dumps and (not print_dumps_deltas or self._signal_changed): + elif line0 == '#': # this is where the string is built for printing in print_dumps + if not print_dumps_deltas or self._signal_changed: ss = [] ss.append('{}'.format(time)) - for i, ref in enumerate(print_dumps_refs): + + for i, ref in enumerate(print_dumps_refs): # Builds the data for one line of the print_dumps table identifier_code = references_to_ids[ref] value = cur_sig_vals[identifier_code] - ss.append('{0:>{1}s}'.format(self._to_hex(value), references_to_widths[ref])) - print(' '.join(ss)) + ss.append('{0:>{1}s}'.format(self._to_hex(value), references_to_widths[ref])) + self._dumps.append(ss) + if print_dumps: + print(' '.join(ss)) # prints a line of values for the print_dumps table time = int(line[1:]) self._endtime = time self._signal_changed = False @@ -103,24 +108,29 @@ def __init__( break if print_dumps: print('0 time') - if signals: - print_dumps_refs = signals - else: - print_dumps_refs = sorted(self._data[i]['references'][0] for i in cur_sig_vals.keys()) - for i, ref in enumerate(print_dumps_refs, 1): - print('{} {}'.format(i, ref)) - if i == 0: - i = 1 - identifier_code = references_to_ids[ref] - size = int(self._data[identifier_code]['size']) - width = max(((size // 4)), int(math.floor(math.log10(i))) + 1) - references_to_widths[ref] = width + self._sorted.append('0 time') + if signals: + print_dumps_refs = signals + else: + print_dumps_refs = sorted(self._data[i]['references'][0] for i in cur_sig_vals.keys()) + for i, ref in enumerate(print_dumps_refs, 1): + sig_string = '{} {}'.format(i, ref) + self._sorted.append(sig_string) + if print_dumps: + print(sig_string) # Prints the signals one by one... for the print_dumps table legend + if i == 0: + i = 1 + identifier_code = references_to_ids[ref] + size = int(self._data[identifier_code]['size']) + width = max(((size // 4)), int(math.floor(math.log10(i))) + 1) + references_to_widths[ref] = width + if print_dumps: print() print('0 '.format(i, ), end='') for i, ref in enumerate(print_dumps_refs, 1): - print('{0:>{1}d} '.format(i, references_to_widths[ref]), end='') + print('{0:>{1}d} '.format(i, references_to_widths[ref]), end='') # Prints the header of the print_dumps table print() - print('=' * (sum(references_to_widths.values()) + len(references_to_widths) + 1)) + print('=' * (sum(references_to_widths.values()) + len(references_to_widths) + 1)) #prints header separator in print_dumps table elif '$scope' in line: hier.append(line.split()[2]) elif '$upscope' in line: @@ -143,9 +153,19 @@ def __init__( } self._data[identifier_code]['references'].append(reference) references_to_ids[reference] = identifier_code - if print_dumps: - cur_sig_vals[identifier_code] = 'x' - + cur_sig_vals[identifier_code] = 'x' + def get_dumps(self): + """ + Get the print_dumps values returned instead of just printed + """ + return self._dumps + + def get_sorted_sig_dumps(self): + """ + Get the print_dumps sorted list of signals + """ + return self._sorted + def get_data(self): """ Get the main parsed VCD data. @@ -180,14 +200,14 @@ def _add_value_identifier_code( if identifier_code in self._data: entry = self._data[identifier_code] self._signal_changed = True + cur_sig_vals[identifier_code] = value if self._store_tvs: if 'tv' not in entry: entry['tv'] = [] entry['tv'].append((time, value)) if print_deltas: print("{} {} {}".format(time, self._to_hex(value), entry['references'][0])) - if print_dumps: - cur_sig_vals[identifier_code] = value + @staticmethod def _to_hex(s):