Skip to content

Commit

Permalink
migen/fhdl/specials: use fdict to pass memory initialization files to…
Browse files Browse the repository at this point in the history
… VerilogConvert and print them in __str__ method
  • Loading branch information
enjoy-digital committed Mar 30, 2015
1 parent ea04947 commit 95cfc44
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
19 changes: 10 additions & 9 deletions migen/fhdl/specials.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
from migen.fhdl.tracer import get_obj_var_name
from migen.fhdl.verilog import _printexpr as verilog_printexpr

def _new_file(fdict, requested_filename, contents):

This comment has been minimized.

Copy link
@sbourdeauducq

sbourdeauducq Mar 30, 2015

Member

This function should be exported.

filename = requested_filename
i = 1
while filename in fdict.keys():

This comment has been minimized.

Copy link
@sbourdeauducq

sbourdeauducq Mar 30, 2015

Member

in fdict
keys is unnecessary.

filename = requested_filename + str(i)
i += 1
fdict[filename] = contents
return filename, fdict

This comment has been minimized.

Copy link
@sbourdeauducq

sbourdeauducq Mar 30, 2015

Member

dict is a mutable type


class Special(HUID):
def iter_expressions(self):
for x in []:
Expand Down Expand Up @@ -307,15 +316,7 @@ def gn(e):
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()

memory_filename, fdict = _new_file(fdict, gn(memory) + ".init", memory.init)
r += "initial begin\n"
r += "$readmemh(\"" + memory_filename + "\", " + gn(memory) + ");\n"
r += "end\n\n"
Expand Down
5 changes: 5 additions & 0 deletions migen/fhdl/verilog.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ def __str__(self):
fdict = OrderedDict()
src, fdict = _printspecials(self.special_overrides, self.f.specials - self.lowered_specials, self.ns, fdict)
r += src
for filename, contents in fdict.items():

This comment has been minimized.

Copy link
@sbourdeauducq

sbourdeauducq Mar 30, 2015

Member

The purpose of the change was to get file I/O out of the FHDL backend and into mibuild.

f = open(filename, "w")
for data in contents:
f.write("{:x}\n".format(data))
f.close()
r += "endmodule\n"
return r

Expand Down

0 comments on commit 95cfc44

Please sign in to comment.