Skip to content

Instantly share code, notes, and snippets.

@atx
Last active June 30, 2018 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atx/2e916ea2e533b8d321a4f9c17b57c8d2 to your computer and use it in GitHub Desktop.
Save atx/2e916ea2e533b8d321a4f9c17b57c8d2 to your computer and use it in GitHub Desktop.
Script that filters VCD files produced by chisel in order to make it load in PulseView (EDIT: This does not seem necessary for the newest git version of sigrok)
#! /usr/bin/env python3
import argparse
import pathlib
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", type=pathlib.Path, required=True)
parser.add_argument("-o", "--output", type=pathlib.Path, required=True)
parser.add_argument("-s", "--signal", nargs="+")
parser.add_argument("-t", "--timescale", type=int)
args = parser.parse_args()
with args.input.open() as fin, args.output.open("w") as fout:
def copy_section(header):
fout.write(header)
while not header.endswith("$end\n"):
header = fin.readline()
fout.write(header)
def skip_section(header):
while not header.endswith("$end\n"):
header = fin.readline()
def filter_scope(header):
fout.write(header)
var = fin.readline()
while True:
var = fin.readline()
if var.startswith("$upscope"):
break
_, type_, bits, key, name, _ = var.split()
if bits != "1" or args.signal and name not in args.signal:
print("Filtering '{}'".format(name))
continue
fout.write(var)
fout.write(var)
def filter_dumpvars(header):
fout.write(header)
for line in fin:
if line[0] == "b" and " " in line:
continue
fout.write(line)
while True:
header = fin.readline()
if not header:
break
elif header.startswith("$scope"):
filter_scope(header)
elif header.startswith("$dumpvars"):
filter_dumpvars(header)
elif header.startswith("$timescale") and args.timescale:
skip_section(header)
fout.write("$timescale {}ps $end\n".format(args.timescale))
else:
copy_section(header)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment