import os
import sys
+import subprocess
try:
import colorama
colorama.init() # install escape sequence translation on Windows
DDROutput: XilinxDDROutputKU,
DDRInput: XilinxDDRInputKU
}
+
+
+def _run_yosys(device, sources, vincpaths, build_name):
+ ys_contents = ""
+ incflags = ""
+ for path in vincpaths:
+ incflags += " -I" + path
+ for filename, language, library in sources:
+ ys_contents += "read_{}{} {}\n".format(language, incflags, filename)
+
+ ys_contents += """\
+# hierarchy -top top
+# proc; memory; opt; fsm; opt
+synth_xilinx -top top -edif {build_name}.edif""".format(build_name=build_name)
+
+ ys_name = build_name + ".ys"
+ tools.write_to_file(ys_name, ys_contents)
+ r = subprocess.call(["yosys", ys_name])
+ if r != 0:
+ raise OSError("Subprocess failed")
self.clocks = dict()
self.false_paths = set()
- def _build_batch(self, platform, sources, edifs, ips, build_name):
+ def _build_batch(self, platform, sources, edifs, ips, build_name, synth_mode="vivado"):
tcl = []
tcl.append("create_project -force -name {} -part {}".format(build_name, platform.device))
- for filename, language, library in sources:
- filename_tcl = "{" + filename + "}"
- tcl.append("add_files " + filename_tcl)
- tcl.append("set_property library {} [get_files {}]"
- .format(library, filename_tcl))
+ if synth_mode == "vivado":
+ # "-include_dirs {}" crashes Vivado 2016.4
+ for filename, language, library in sources:
+ filename_tcl = "{" + filename + "}"
+ tcl.append("add_files " + filename_tcl)
+ tcl.append("set_property library {} [get_files {}]"
+ .format(library, filename_tcl))
+
for filename in edifs:
filename_tcl = "{" + filename + "}"
tcl.append("read_edif " + filename_tcl)
tcl.append("read_xdc {}.xdc".format(build_name))
tcl.extend(c.format(build_name=build_name) for c in self.pre_synthesis_commands)
- # "-include_dirs {}" crashes Vivado 2016.4
- if platform.verilog_include_paths:
- tcl.append("synth_design -top {} -part {} -include_dirs {{{}}}".format(build_name, platform.device, " ".join(platform.verilog_include_paths)))
+
+ if synth_mode == "vivado":
+ if platform.verilog_include_paths:
+ tcl.append("synth_design -top {} -part {} -include_dirs {{{}}}".format(build_name, platform.device, " ".join(platform.verilog_include_paths)))
+ else:
+ tcl.append("synth_design -top {} -part {}".format(build_name, platform.device))
+ elif synth_mode == "yosys":
+ tcl.append("read_edif {}.edif".format(build_name))
+ tcl.append("link_design -top {} -part {}".format(build_name, platform.device))
else:
- tcl.append("synth_design -top {} -part {}".format(build_name, platform.device))
+ raise OSError("Unknown synthesis mode! {}".format(synth_mode))
+
tcl.append("report_timing_summary -file {}_timing_synth.rpt".format(build_name))
tcl.append("report_utilization -hierarchical -file {}_utilization_hierarchical_synth.rpt".format(build_name))
tcl.append("report_utilization -file {}_utilization_synth.rpt".format(build_name))
def build(self, platform, fragment, build_dir="build", build_name="top",
toolchain_path=None, source=True, run=True, **kwargs):
+ synth_mode = kwargs.get('synth_mode', 'yosys')
if toolchain_path is None:
if sys.platform == "win32":
toolchain_path = "C:\\Xilinx\\Vivado"
sources = platform.sources + [(v_file, "verilog", "work")]
edifs = platform.edifs
ips = platform.ips
- self._build_batch(platform, sources, edifs, ips, build_name)
+ self._build_batch(platform, sources, edifs, ips, build_name, synth_mode=synth_mode)
tools.write_to_file(build_name + ".xdc", _build_xdc(named_sc, named_pc))
if run:
+ if synth_mode == "yosys":
+ common._run_yosys(platform.device, sources, platform.verilog_include_paths, build_name)
+ else:
+ raise OSError("Error!")
_run_vivado(build_name, toolchain_path, source)
os.chdir(cwd)