fhdl/specials/memory: use $readmemh to initialize memories

This commit is contained in:
Florent Kermarrec 2015-03-18 15:16:11 +01:00
parent c0fb0ef600
commit 5a9afee234
1 changed files with 11 additions and 2 deletions

View File

@ -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):