from copy import copy
+import os
from migen.fhdl.structure import *
from migen.corelogic.record import Record
from migen.fhdl import verilog
+from mibuild import tools
+
class ConstraintError(Exception):
pass
self.device = device
self.constraint_manager = ConstraintManager(io)
self.default_crg_factory = default_crg_factory
+ self.sources = []
def request(self, *args, **kwargs):
return self.constraint_manager.request(*args, **kwargs)
def add_platform_command(self, *args, **kwargs):
return self.constraint_manager.add_platform_command(*args, **kwargs)
+ def add_source(self, filename, language=None):
+ if language is None:
+ language = tools.language_by_filename(filename)
+ if language is None:
+ language = "verilog" # default to Verilog
+ self.sources.append((filename, language))
+
+ def add_sources(self, path, *filenames, language=None):
+ for f in filenames:
+ self.add_source(os.path.join(path, f), language)
+
+ def add_source_dir(self, path):
+ for root, dirs, files in os.walk(path):
+ for filename in files:
+ language = tools.language_by_filename(filename)
+ if language is not None:
+ self.add_source(os.path.join(root, filename), language)
+
def get_verilog(self, fragment, clock_domains=None):
# We may create a temporary clock/reset generator that would request pins.
# Save the constraint manager state so that such pin requests disappear
except OSError:
pass
+def language_by_filename(name):
+ extension = name.rsplit(".")[-1]
+ if extension in ["v", "vh", "vo"]:
+ return "verilog"
+ if extension in ["vhd", "vhdl", "vho"]:
+ return "vhdl"
+ return None
+
def write_to_file(filename, contents):
f = open(filename, "w")
f.write(contents)
tools.write_to_file(build_name + ".ucf", _build_ucf(named_sc, named_pc))
prj_contents = ""
- for s in sources:
- prj_contents += s["type"] + " work " + s["path"] + "\n"
+ for filename, language in sources:
+ prj_contents += language + " work " + filename + "\n"
tools.write_to_file(build_name + ".prj", prj_contents)
xst_contents = """run
v_src, named_sc, named_pc = self.get_verilog(fragment, clock_domains)
v_file = build_name + ".v"
tools.write_to_file(v_file, v_src)
- sources = [{"type": "verilog", "path": v_file}]
+ sources = self.sources + [(v_file, "verilog")]
_build(self.device, sources, named_sc, named_pc, build_name, xilinx_install_path)
os.chdir("..")