From: Florent Kermarrec Date: Wed, 18 Mar 2015 14:16:11 +0000 (+0100) Subject: fhdl/specials/memory: use $readmemh to initialize memories X-Git-Tag: 24jan2021_ls180~2099^2~163 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5a9afee234210d501a9a3960ceb1ef9b26aa270f;p=litex.git fhdl/specials/memory: use $readmemh to initialize memories --- diff --git a/migen/fhdl/specials.py b/migen/fhdl/specials.py index 78098dd1..768f55e4 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):