Skip to content

Commit 083d371

Browse files
committedApr 16, 2015
mibuild: add support for libraries, move .replace("\\", "/") to generic_platform.py and execute it only on Windows machines.
We need to support libraries when Migen is used as a wrapper on large VHDL designs using libraries.
1 parent ae503bc commit 083d371

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed
 

Diff for: ‎mibuild/altera/quartus.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ def _build_qsf(named_sc, named_pc):
4747

4848
def _build_files(device, sources, vincpaths, named_sc, named_pc, build_name):
4949
qsf_contents = ""
50-
for filename, language in sources:
50+
for filename, language, library in sources:
5151
# Enforce use of SystemVerilog (Quartus does not support global parameters in Verilog)
5252
if language == "verilog":
5353
language = "systemverilog"
54-
qsf_contents += "set_global_assignment -name " + language.upper() + "_FILE " + filename.replace("\\", "/") + "\n"
54+
qsf_contents += "set_global_assignment -name " + language.upper() + "_FILE " + filename + " -library " + library + " \n"
5555

5656
for path in vincpaths:
57-
qsf_contents += "set_global_assignment -name SEARCH_PATH " + path.replace("\\", "/") + "\n"
57+
qsf_contents += "set_global_assignment -name SEARCH_PATH " + path + "\n"
5858

5959
qsf_contents += _build_qsf(named_sc, named_pc)
6060
qsf_contents += "set_global_assignment -name DEVICE " + device
@@ -92,7 +92,7 @@ def build(self, platform, fragment, build_dir="build", build_name="top",
9292
named_sc, named_pc = platform.resolve_signals(v_output.ns)
9393
v_file = build_name + ".v"
9494
v_output.write(v_file)
95-
sources = platform.sources | {(v_file, "verilog")}
95+
sources = platform.sources | {(v_file, "verilog", "work")}
9696
_build_files(platform.device, sources, platform.verilog_include_paths, named_sc, named_pc, build_name)
9797
if run:
9898
_run_quartus(build_name, quartus_path)

Diff for: ‎mibuild/generic_platform.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,23 @@ def do_finalize(self, fragment, *args, **kwargs):
237237
except ConstraintError:
238238
pass
239239

240-
def add_source(self, filename, language=None):
240+
def add_source(self, filename, language=None, library=None):
241241
if language is None:
242242
language = tools.language_by_filename(filename)
243243
if language is None:
244244
language = "verilog" # default to Verilog
245+
if library is None:
246+
library = "work" # default to work
245247
filename = os.path.abspath(filename)
246-
self.sources.add((filename, language))
248+
if sys.platform == "win32" or sys.platform == "cygwin":
249+
filename = filename.replace("\\", "/")
250+
self.sources.add((filename, language, library))
247251

248-
def add_sources(self, path, *filenames, language=None):
252+
def add_sources(self, path, *filenames, language=None, library=None):
249253
for f in filenames:
250-
self.add_source(os.path.join(path, f), language)
254+
self.add_source(os.path.join(path, f), language, library)
251255

252-
def add_source_dir(self, path, recursive=True):
256+
def add_source_dir(self, path, recursive=True, library=None):
253257
dir_files = []
254258
if recursive:
255259
for root, dirs, files in os.walk(path):
@@ -262,10 +266,13 @@ def add_source_dir(self, path, recursive=True):
262266
for filename in dir_files:
263267
language = tools.language_by_filename(filename)
264268
if language is not None:
265-
self.add_source(filename, language)
269+
self.add_source(filename, language, library)
266270

267271
def add_verilog_include_path(self, path):
268-
self.verilog_include_paths.add(os.path.abspath(path))
272+
path = os.path.abspath(path)
273+
if sys.platform == "win32" or sys.platform == "cygwin":
274+
path = path.replace("\\", "/")
275+
self.verilog_include_paths.add(path)
269276

270277
def resolve_signals(self, vns):
271278
# resolve signal names in constraints

Diff for: ‎mibuild/lattice/diamond.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def _build_files(device, sources, vincpaths, build_name):
4747
tcl = []
4848
tcl.append("prj_project new -name \"{}\" -impl \"implementation\" -dev {} -synthesis \"synplify\"".format(build_name, device))
4949
for path in vincpaths:
50-
tcl.append("prj_impl option {include path} {\"" + path.replace("\\", "/") + "\"}")
51-
for filename, language in sources:
52-
tcl.append("prj_src add \"" + filename.replace("\\", "/") + "\"")
50+
tcl.append("prj_impl option {include path} {\"" + path + "\"}")
51+
for filename, language, library in sources:
52+
tcl.append("prj_src add \"" + filename + "\" -work " + library)
5353
tcl.append("prj_run Synthesis -impl implementation -forceOne")
5454
tcl.append("prj_run Translate -impl implementation")
5555
tcl.append("prj_run Map -impl implementation")
@@ -67,7 +67,7 @@ def _run_diamond(build_name, source, ver=None):
6767
r = subprocess.call([build_script_file])
6868
shutil.copy(os.path.join("implementation", build_name + "_implementation.bit"), build_name + ".bit")
6969
else:
70-
raise NotImplementedError()
70+
raise NotImplementedError
7171

7272
if r != 0:
7373
raise OSError("Subprocess failed")
@@ -87,7 +87,7 @@ def build(self, platform, fragment, build_dir="build", build_name="top",
8787
named_sc, named_pc = platform.resolve_signals(v_output.ns)
8888
v_file = build_name + ".v"
8989
v_output.write(v_file)
90-
sources = platform.sources | {(v_file, "verilog")}
90+
sources = platform.sources | {(v_file, "verilog", "work")}
9191
_build_files(platform.device, sources, platform.verilog_include_paths, build_name)
9292

9393
tools.write_to_file(build_name + ".lpf", _build_lpf(named_sc, named_pc))

Diff for: ‎mibuild/xilinx/ise.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def _build_ucf(named_sc, named_pc):
4848

4949
def _build_xst_files(device, sources, vincpaths, build_name, xst_opt):
5050
prj_contents = ""
51-
for filename, language in sources:
52-
prj_contents += language + " work " + filename + "\n"
51+
for filename, language, library in sources:
52+
prj_contents += language + " " + library + " " + filename + "\n"
5353
tools.write_to_file(build_name + ".prj", prj_contents)
5454

5555
xst_contents = """run
@@ -159,7 +159,7 @@ def build(self, platform, fragment, build_dir="build", build_name="top",
159159
named_sc, named_pc = platform.resolve_signals(vns)
160160
v_file = build_name + ".v"
161161
v_output.write(v_file)
162-
sources = platform.sources | {(v_file, "verilog")}
162+
sources = platform.sources | {(v_file, "verilog", "work")}
163163
if mode == "xst":
164164
_build_xst_files(platform.device, sources, platform.verilog_include_paths, build_name, self.xst_opt)
165165
isemode = "xst"

Diff for: ‎mibuild/xilinx/vivado.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ def __init__(self):
8181

8282
def _build_batch(self, platform, sources, build_name):
8383
tcl = []
84-
for filename, language in sources:
85-
tcl.append("add_files " + filename.replace("\\", "/"))
84+
for filename, language, library in sources:
85+
tcl.append("add_files " + filename)
86+
tcl.append("set_property library {} [get_files {}]".format(library, filename))
8687

8788
tcl.append("read_xdc {}.xdc".format(build_name))
8889
tcl.extend(c.format(build_name=build_name) for c in self.pre_synthesis_commands)
@@ -122,7 +123,7 @@ def build(self, platform, fragment, build_dir="build", build_name="top",
122123
named_sc, named_pc = platform.resolve_signals(v_output.ns)
123124
v_file = build_name + ".v"
124125
v_output.write(v_file)
125-
sources = platform.sources | {(v_file, "verilog")}
126+
sources = platform.sources | {(v_file, "verilog", "work")}
126127
self._build_batch(platform, sources, build_name)
127128
tools.write_to_file(build_name + ".xdc", _build_xdc(named_sc, named_pc))
128129
if run:

0 commit comments

Comments
 (0)
Please sign in to comment.