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_il_text(il_text, strip_src): version, offset = _yosys_version() if version < (0, 9): raise YosysError("Yosys %d.%d is not suppored", *version) attr_map = [] if strip_src: attr_map.append("-remove src") script = """ # Convert nMigen's RTLIL to readable Verilog. read_ilang <