from ..hdl import ast, rec, ir, mem, xfrm
-__all__ = ["convert"]
+__all__ = ["convert", "convert_fragment"]
class _Namer:
self.on_statement(stmt)
-def convert_fragment(builder, fragment, hierarchy):
+def _convert_fragment(builder, fragment, hierarchy):
if isinstance(fragment, ir.Instance):
port_map = OrderedDict()
for port_name, (value, dir) in fragment.named_ports.items():
sub_params[param_name] = param_value
sub_type, sub_port_map = \
- convert_fragment(builder, subfragment, hierarchy=hierarchy + (sub_name,))
+ _convert_fragment(builder, subfragment, hierarchy=hierarchy + (sub_name,))
sub_ports = OrderedDict()
for port, value in sub_port_map.items():
return module.name, port_map
-def convert(fragment, name="top", platform=None, **kwargs):
- fragment = ir.Fragment.get(fragment, platform).prepare(**kwargs)
+def convert_fragment(fragment, name="top"):
+ assert isinstance(fragment, ir.Fragment)
builder = _Builder()
- convert_fragment(builder, fragment, hierarchy=(name,))
+ _convert_fragment(builder, fragment, hierarchy=(name,))
return str(builder)
+
+
+def convert(elaboratable, name="top", platform=None, **kwargs):
+ fragment = ir.Fragment.get(elaboratable, platform).prepare(**kwargs)
+ return convert_fragment(fragment, name)
from . import rtlil
-__all__ = ["convert"]
+__all__ = ["YosysError", "convert", "convert_fragment"]
class YosysError(Exception):
pass
-def convert(*args, strip_src=False, **kwargs):
+def _convert_il_text(il_text, strip_src):
try:
popen = subprocess.Popen([os.getenv("YOSYS", "yosys"), "-q", "-"],
stdin=subprocess.PIPE,
if strip_src:
attr_map.append("-remove src")
- il_text = rtlil.convert(*args, **kwargs)
verilog_text, error = popen.communicate("""
# Convert nMigen's RTLIL to readable Verilog.
read_ilang <<rtlil
raise YosysError(error.strip())
else:
return verilog_text
+
+
+def convert_fragment(*args, strip_src=False, **kwargs):
+ il_text = rtlil.convert_fragment(*args, **kwargs)
+ return _convert_il_text(il_text, strip_src)
+
+
+def convert(*args, strip_src=False, **kwargs):
+ il_text = rtlil.convert(*args, **kwargs)
+ return _convert_il_text(il_text, strip_src)