2015-02-28 04:27:16 -05:00
|
|
|
from misoclib.tools.litescope.host.dump import *
|
2015-02-18 09:32:34 -05:00
|
|
|
|
2015-04-13 07:18:21 -04:00
|
|
|
|
2015-02-18 09:32:34 -05:00
|
|
|
class CSVDump(Dump):
|
2015-04-13 07:09:44 -04:00
|
|
|
def __init__(self, init_dump=None):
|
|
|
|
Dump.__init__(self)
|
|
|
|
if init_dump:
|
|
|
|
self.vars = init_dump.vars
|
2015-02-18 09:32:34 -05:00
|
|
|
|
2015-04-13 07:09:44 -04:00
|
|
|
def generate_vars(self):
|
|
|
|
r = ""
|
|
|
|
for var in self.vars:
|
|
|
|
r += var.name
|
|
|
|
r += ","
|
|
|
|
r += "\n"
|
|
|
|
for var in self.vars:
|
|
|
|
r += str(var.width)
|
|
|
|
r += ","
|
|
|
|
r += "\n"
|
|
|
|
return r
|
2015-02-18 09:32:34 -05:00
|
|
|
|
2015-04-13 07:09:44 -04:00
|
|
|
def generate_dumpvars(self):
|
|
|
|
r = ""
|
|
|
|
for i in range(len(self)):
|
|
|
|
for var in self.vars:
|
|
|
|
try:
|
|
|
|
var.val = var.values[i]
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if var.val == "x":
|
|
|
|
r += "x"
|
|
|
|
else:
|
|
|
|
r += dec2bin(var.val, var.width)
|
|
|
|
r += ", "
|
|
|
|
r+= "\n"
|
|
|
|
return r
|
2015-02-18 09:32:34 -05:00
|
|
|
|
2015-04-13 07:09:44 -04:00
|
|
|
def write(self, filename):
|
|
|
|
f = open(filename, "w")
|
|
|
|
f.write(self.generate_vars())
|
|
|
|
f.write(self.generate_dumpvars())
|
|
|
|
f.close()
|
2015-02-18 09:32:34 -05:00
|
|
|
|
2015-04-13 07:09:44 -04:00
|
|
|
def read(self, filename):
|
|
|
|
raise NotImplementedError("CSV files can not (yet) be read, please contribute!")
|
2015-02-18 09:32:34 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-04-13 07:09:44 -04:00
|
|
|
dump = CSVDump()
|
2015-04-13 07:23:48 -04:00
|
|
|
dump.add(Var("foo1", 1, [0, 1, 0, 1, 0, 1]))
|
|
|
|
dump.add(Var("foo2", 2, [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]))
|
2015-04-13 07:09:44 -04:00
|
|
|
ramp = [i%128 for i in range(1024)]
|
|
|
|
dump.add(Var("ramp", 16, ramp))
|
|
|
|
dump.write("dump.csv")
|