From 5a9afee234210d501a9a3960ceb1ef9b26aa270f Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 18 Mar 2015 15:16:11 +0100 Subject: [PATCH] fhdl/specials/memory: use $readmemh to initialize memories --- migen/fhdl/specials.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/migen/fhdl/specials.py b/migen/fhdl/specials.py index 78098dd11..768f55e4b 100644 --- a/migen/fhdl/specials.py +++ b/migen/fhdl/specials.py @@ -307,11 +307,20 @@ class Memory(Special): r += "\n" 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" - for i, c in enumerate(memory.init): - r += "\t" + gn(memory) + "[" + str(i) + "] <= " + str(memory.width) + "'d" + str(c) + ";\n" + r += "$readmemh(\"" + memory_filename + "\", " + gn(memory) + ");\n" r += "end\n\n" + return r class SynthesisDirective(Special):