From 3567b689810b0718fcd6950c1c0eaf04a562a9e8 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 30 Aug 2018 14:39:09 +0200 Subject: [PATCH] dump/vcd: fix code generation --- litescope/software/dump/vcd.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/litescope/software/dump/vcd.py b/litescope/software/dump/vcd.py index 52df7ca..0e65403 100644 --- a/litescope/software/dump/vcd.py +++ b/litescope/software/dump/vcd.py @@ -1,7 +1,19 @@ +from itertools import count import datetime from litescope.software.dump.common import Dump, dec2bin +def vcd_codes(): + codechars = [chr(i) for i in range(33, 127)] + for n in count(): + q, r = divmod(n, len(codechars)) + code = codechars[r] + while q > 0: + q, r = divmod(q, len(codechars)) + code = codechars[r] + code + yield code + + class VCDDump(Dump): def __init__(self, dump=None, timescale="1ps", comment=""): Dump.__init__(self) @@ -19,7 +31,7 @@ class VCDDump(Dump): c += "b" c += dec2bin(v.values[self.cnt + 1], v.width) c += " " - c += v.vcd_id + c += v.code c += "\n" except: pass @@ -59,7 +71,7 @@ class VCDDump(Dump): r += "$var wire " r += str(v.width) r += " " - r += v.vcd_id + r += v.code r += " " r += v.name r += " $end\n" @@ -76,7 +88,7 @@ class VCDDump(Dump): r += "b" r += dec2bin(v.current_value, v.width) r += " " - r += v.vcd_id + r += v.code r += "\n" r += "$end\n" return r @@ -93,10 +105,9 @@ class VCDDump(Dump): return r def finalize(self): - vcd_id = "!" + codegen = vcd_codes() for v in self.variables: - v.vcd_id = vcd_id - vcd_id = chr(ord(vcd_id)+1) + v.code = next(codegen) def write(self, filename): self.finalize()