dump/vcd: fix code generation

This commit is contained in:
Florent Kermarrec 2018-08-30 14:39:09 +02:00
parent 182b683586
commit 3567b68981
1 changed files with 17 additions and 6 deletions

View File

@ -1,7 +1,19 @@
from itertools import count
import datetime import datetime
from litescope.software.dump.common import Dump, dec2bin 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): class VCDDump(Dump):
def __init__(self, dump=None, timescale="1ps", comment=""): def __init__(self, dump=None, timescale="1ps", comment=""):
Dump.__init__(self) Dump.__init__(self)
@ -19,7 +31,7 @@ class VCDDump(Dump):
c += "b" c += "b"
c += dec2bin(v.values[self.cnt + 1], v.width) c += dec2bin(v.values[self.cnt + 1], v.width)
c += " " c += " "
c += v.vcd_id c += v.code
c += "\n" c += "\n"
except: except:
pass pass
@ -59,7 +71,7 @@ class VCDDump(Dump):
r += "$var wire " r += "$var wire "
r += str(v.width) r += str(v.width)
r += " " r += " "
r += v.vcd_id r += v.code
r += " " r += " "
r += v.name r += v.name
r += " $end\n" r += " $end\n"
@ -76,7 +88,7 @@ class VCDDump(Dump):
r += "b" r += "b"
r += dec2bin(v.current_value, v.width) r += dec2bin(v.current_value, v.width)
r += " " r += " "
r += v.vcd_id r += v.code
r += "\n" r += "\n"
r += "$end\n" r += "$end\n"
return r return r
@ -93,10 +105,9 @@ class VCDDump(Dump):
return r return r
def finalize(self): def finalize(self):
vcd_id = "!" codegen = vcd_codes()
for v in self.variables: for v in self.variables:
v.vcd_id = vcd_id v.code = next(codegen)
vcd_id = chr(ord(vcd_id)+1)
def write(self, filename): def write(self, filename):
self.finalize() self.finalize()