2015-05-01 14:27:31 -04:00
|
|
|
from misoclib.tools.litescope.software.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 PythonDump(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_data(self):
|
|
|
|
r = "dump = {\n"
|
|
|
|
for var in self.vars:
|
|
|
|
r += "\"" + var.name + "\""
|
|
|
|
r += " : "
|
|
|
|
r += str(var.values)
|
|
|
|
r += ",\n"
|
|
|
|
r += "}"
|
|
|
|
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_data())
|
|
|
|
f.close()
|
2015-02-18 09:32:34 -05:00
|
|
|
|
2015-04-13 07:09:44 -04:00
|
|
|
def read(self, filename):
|
|
|
|
raise NotImplementedError("Python 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 = PythonDump()
|
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.py")
|