mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
create dump class and specific export functions, add python dictionnary export
This commit is contained in:
parent
a737358919
commit
074a12b444
2 changed files with 58 additions and 60 deletions
|
@ -1,7 +1,7 @@
|
||||||
import csv
|
import csv
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
from miscope.host.export import *
|
from miscope.host.dump import *
|
||||||
from miscope.host.truthtable import *
|
from miscope.host.truthtable import *
|
||||||
|
|
||||||
class MiIoDriver():
|
class MiIoDriver():
|
||||||
|
@ -126,13 +126,13 @@ class MiLaDriver():
|
||||||
|
|
||||||
def export(self, export_fn=None):
|
def export(self, export_fn=None):
|
||||||
self.show_state("EXPORT")
|
self.show_state("EXPORT")
|
||||||
|
dump = Dump()
|
||||||
|
dump.add_from_layout(self.layout, self.dat)
|
||||||
if ".vcd" in export_fn:
|
if ".vcd" in export_fn:
|
||||||
vcd = VCD()
|
VCDExport(dump).write(export_fn)
|
||||||
vcd.add_from_layout(self.layout, self.dat)
|
|
||||||
vcd.write(export_fn)
|
|
||||||
elif ".csv" in export_fn:
|
elif ".csv" in export_fn:
|
||||||
csv = CSV()
|
CSVExport(dump).write(export_fn)
|
||||||
csv.add_from_layout(self.layout, self.dat)
|
elif ".py" in export_fn:
|
||||||
csv.write(export_fn)
|
PYExport(dump).write(export_fn)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
|
@ -98,13 +98,10 @@ class Var:
|
||||||
return r
|
return r
|
||||||
return r
|
return r
|
||||||
|
|
||||||
class VCD:
|
class Dump:
|
||||||
def __init__(self, timescale="1ps", comment=""):
|
def __init__(self):
|
||||||
self.timescale = timescale
|
|
||||||
self.comment = comment
|
|
||||||
self.vars = []
|
self.vars = []
|
||||||
self.vcd_id = "!"
|
self.vcd_id = "!"
|
||||||
self.cnt = -1
|
|
||||||
|
|
||||||
def add(self, var):
|
def add(self, var):
|
||||||
var.set_vcd_id(self.vcd_id)
|
var.set_vcd_id(self.vcd_id)
|
||||||
|
@ -122,11 +119,18 @@ class VCD:
|
||||||
for var in self.vars:
|
for var in self.vars:
|
||||||
l = max(len(var),l)
|
l = max(len(var),l)
|
||||||
return l
|
return l
|
||||||
|
|
||||||
|
class VCDExport():
|
||||||
|
def __init__(self, dump, timescale="1ps", comment=""):
|
||||||
|
self.dump = dump
|
||||||
|
self.timescale = timescale
|
||||||
|
self.comment = comment
|
||||||
|
self.cnt = -1
|
||||||
|
|
||||||
def change(self):
|
def change(self):
|
||||||
r = ""
|
r = ""
|
||||||
c = ""
|
c = ""
|
||||||
for var in self.vars:
|
for var in self.dump.vars:
|
||||||
c += var.change(self.cnt)
|
c += var.change(self.cnt)
|
||||||
if c != "":
|
if c != "":
|
||||||
r += "#"
|
r += "#"
|
||||||
|
@ -170,7 +174,7 @@ class VCD:
|
||||||
|
|
||||||
def p_vars(self):
|
def p_vars(self):
|
||||||
r = ""
|
r = ""
|
||||||
for var in self.vars:
|
for var in self.dump.vars:
|
||||||
r += "$var "
|
r += "$var "
|
||||||
r += var.type
|
r += var.type
|
||||||
r += " "
|
r += " "
|
||||||
|
@ -194,7 +198,7 @@ class VCD:
|
||||||
|
|
||||||
def p_dumpvars(self):
|
def p_dumpvars(self):
|
||||||
r = "$dumpvars\n"
|
r = "$dumpvars\n"
|
||||||
for var in self.vars:
|
for var in self.dump.vars:
|
||||||
r += "b"
|
r += "b"
|
||||||
r += dec2bin(var.val, var.width)
|
r += dec2bin(var.val, var.width)
|
||||||
r += " "
|
r += " "
|
||||||
|
@ -205,7 +209,7 @@ class VCD:
|
||||||
|
|
||||||
def p_valuechange(self):
|
def p_valuechange(self):
|
||||||
r = ""
|
r = ""
|
||||||
for i in range(len(self)):
|
for i in range(len(self.dump)):
|
||||||
r += self.change()
|
r += self.change()
|
||||||
self.cnt += 1
|
self.cnt += 1
|
||||||
return r
|
return r
|
||||||
|
@ -223,39 +227,23 @@ class VCD:
|
||||||
r += self.p_dumpvars()
|
r += self.p_dumpvars()
|
||||||
r += self.p_valuechange()
|
r += self.p_valuechange()
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def write(self, filename):
|
def write(self, filename):
|
||||||
f = open(filename, "w")
|
f = open(filename, "w")
|
||||||
f.write(str(self))
|
f.write(str(self))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
class CSV:
|
class CSVExport():
|
||||||
def __init__(self):
|
def __init__(self, dump):
|
||||||
self.vars = []
|
self.dump = dump
|
||||||
self.cnt = -1
|
|
||||||
|
|
||||||
def add(self, var):
|
|
||||||
self.vars.append(var)
|
|
||||||
|
|
||||||
def add_from_layout(self, layout, var):
|
|
||||||
i=0
|
|
||||||
for s, n in layout:
|
|
||||||
self.add(Var(s, n, var[i:i+n]))
|
|
||||||
i += n
|
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
l = 0
|
|
||||||
for var in self.vars:
|
|
||||||
l = max(len(var),l)
|
|
||||||
return l
|
|
||||||
|
|
||||||
def p_vars(self):
|
def p_vars(self):
|
||||||
r = ""
|
r = ""
|
||||||
for var in self.vars:
|
for var in self.dump.vars:
|
||||||
r += var.name
|
r += var.name
|
||||||
r += ","
|
r += ","
|
||||||
r += "\n"
|
r += "\n"
|
||||||
for var in self.vars:
|
for var in self.dump.vars:
|
||||||
r += str(var.width)
|
r += str(var.width)
|
||||||
r += ","
|
r += ","
|
||||||
r += "\n"
|
r += "\n"
|
||||||
|
@ -263,8 +251,8 @@ class CSV:
|
||||||
|
|
||||||
def p_dumpvars(self):
|
def p_dumpvars(self):
|
||||||
r = ""
|
r = ""
|
||||||
for i in range(len(self)):
|
for i in range(len(self.dump)):
|
||||||
for var in self.vars:
|
for var in self.dump.vars:
|
||||||
try:
|
try:
|
||||||
var.val = var.values[i]
|
var.val = var.values[i]
|
||||||
except:
|
except:
|
||||||
|
@ -282,31 +270,41 @@ class CSV:
|
||||||
r += self.p_vars()
|
r += self.p_vars()
|
||||||
r += self.p_dumpvars()
|
r += self.p_dumpvars()
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def write(self, filename):
|
def write(self, filename):
|
||||||
f = open(filename, "w")
|
f = open(filename, "w")
|
||||||
f.write(str(self))
|
f.write(str(self))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
class PYExport():
|
||||||
|
def __init__(self, dump):
|
||||||
|
self.dump = dump
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
r = "dump = {\n"
|
||||||
|
for var in self.dump.vars:
|
||||||
|
r += "\"" + var.name + "\""
|
||||||
|
r += " : "
|
||||||
|
r += str(var.values)
|
||||||
|
r += ",\n"
|
||||||
|
r += "}"
|
||||||
|
return r
|
||||||
|
|
||||||
|
def write(self, filename):
|
||||||
|
f = open(filename, "w")
|
||||||
|
f.write(str(self))
|
||||||
|
f.close()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
myvcd = VCD()
|
dump = Dump()
|
||||||
myvcd.add(Var("foo1", 1, [0,1,0,1,0,1]))
|
dump.add(Var("foo1", 1, [0,1,0,1,0,1]))
|
||||||
myvcd.add(Var("foo2", 2, [1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0]))
|
dump.add(Var("foo2", 2, [1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0]))
|
||||||
myvcd.add(Var("foo3", 3))
|
|
||||||
myvcd.add(Var("foo4", 4))
|
|
||||||
ramp = [i%128 for i in range(1024)]
|
ramp = [i%128 for i in range(1024)]
|
||||||
myvcd.add(Var("ramp", 16, ramp))
|
dump.add(Var("ramp", 16, ramp))
|
||||||
print(myvcd)
|
|
||||||
|
VCDExport(dump).write("mydump.vcd")
|
||||||
mycsv = CSV()
|
CSVExport(dump).write("mydump.csv")
|
||||||
mycsv.add(Var("foo1", 1, [0,1,0,1,0,1]))
|
PYExport(dump).write("mydump.py")
|
||||||
mycsv.add(Var("foo2", 2, [1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0]))
|
|
||||||
mycsv.add(Var("foo3", 3))
|
|
||||||
mycsv.add(Var("foo4", 4))
|
|
||||||
ramp = [i%128 for i in range(1024)]
|
|
||||||
mycsv.add(Var("ramp", 16, ramp))
|
|
||||||
print(mycsv)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
Loading…
Reference in a new issue