fhdl/specials/memory: use $readmemh to initialize memories
This commit is contained in:
parent
c0fb0ef600
commit
5a9afee234
|
@ -307,11 +307,20 @@ class Memory(Special):
|
||||||
r += "\n"
|
r += "\n"
|
||||||
|
|
||||||
if memory.init is not None:
|
if memory.init is not None:
|
||||||
|
memory_filename = gn(memory) + ".init"
|
||||||
|
|
||||||
|
# XXX move I/O to mibuild?
|
||||||
|
# (Implies mem init won't work with simple Migen examples?)
|
||||||
|
f = open(memory_filename, "w")
|
||||||
|
for d in memory.init:
|
||||||
|
f.write("{:x}\n".format(d))
|
||||||
|
f.close()
|
||||||
|
|
||||||
r += "initial begin\n"
|
r += "initial begin\n"
|
||||||
for i, c in enumerate(memory.init):
|
r += "$readmemh(\"" + memory_filename + "\", " + gn(memory) + ");\n"
|
||||||
r += "\t" + gn(memory) + "[" + str(i) + "] <= " + str(memory.width) + "'d" + str(c) + ";\n"
|
|
||||||
r += "end\n\n"
|
r += "end\n\n"
|
||||||
|
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
class SynthesisDirective(Special):
|
class SynthesisDirective(Special):
|
||||||
|
|
Loading…
Reference in New Issue