From 8299105b7f285867c53833f04b770bba4a9aa937 Mon Sep 17 00:00:00 2001 From: Franck Jullien Date: Mon, 20 Jun 2022 08:58:00 +0200 Subject: [PATCH] vcd: creates gtkw file if filter_*.txt file is present --- litescope/software/dump/vcd.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/litescope/software/dump/vcd.py b/litescope/software/dump/vcd.py index f5a8834..04dc86a 100644 --- a/litescope/software/dump/vcd.py +++ b/litescope/software/dump/vcd.py @@ -4,6 +4,7 @@ # Copyright (c) 2015-2018 Florent Kermarrec # SPDX-License-Identifier: BSD-2-Clause +from os.path import exists from itertools import count import datetime import re @@ -51,6 +52,7 @@ class VCDDump(Dump): # factor of 2 scale is because of 2x samples from fake clock self.count_timescale = int(1 / (timescale_seconds * samplerate * 2)) self.timescale_unit_str = si_prefix + "s" + self.filtered = [] def change(self): r = "" @@ -128,6 +130,16 @@ class VCDDump(Dump): self.cnt += 1 return r + def generate_gtkw(self, filename): + base_name = filename.split(".")[0] + with open("{}.gtkw".format(base_name), "w") as f: + f.write(f"[*] Auto-Generated by Litex\n") + f.write(f"[dumpfile] {filename}\n") + for s in self.filtered: + f.write("@2025\n") + f.write(f"^1 filter_{s.name}.txt\n") + f.write("{}[{}:0]\n".format(s.name, s.width - 1)) + def __repr__(self): r = "" return r @@ -147,5 +159,12 @@ class VCDDump(Dump): f.write(self.generate_valuechange()) f.close() + for v in self.variables: + if exists(f"filter_{v.name}.txt"): + self.filtered.append(v) + + if self.filtered: + self.generate_gtkw(filename) + def read(self, filename): raise NotImplementedError("VCD files can not (yet) be read, please contribute!")