import os import re import subprocess from .._toolchain import * from . import rtlil __all__ = ["YosysError", "convert", "convert_fragment"] class YosysError(Exception): pass def _yosys_version(): yosys_path = require_tool("yosys") version = subprocess.check_output([yosys_path, "-V"], encoding="utf-8") m = re.match(r"^Yosys ([\d.]+)(?:\+(\d+))?", version) tag, offset = m[1], m[2] or 0 return tuple(map(int, tag.split("."))), offset def _convert_rtlil_text(rtlil_text, *, strip_internal_attrs=False, write_verilog_opts=()): version, offset = _yosys_version() if version < (0, 9): raise YosysError("Yosys {}.{} is not supported".format(*version)) attr_map = [] if strip_internal_attrs: attr_map.append("-remove generator") attr_map.append("-remove top") attr_map.append("-remove src") attr_map.append("-remove nmigen.hierarchy") attr_map.append("-remove nmigen.decoding") script = """ # Convert nMigen's RTLIL to readable Verilog. read_ilang <