1 from .._toolchain
.yosys
import *
5 __all__
= ["YosysError", "convert", "convert_fragment"]
8 def _convert_rtlil_text(rtlil_text
, black_boxes
, *, src_loc_at
=0):
9 if black_boxes
is not None:
10 if not isinstance(black_boxes
, dict):
11 raise TypeError("CXXRTL black boxes must be a dictionary, not {!r}"
13 for box_name
, box_source
in black_boxes
.items():
14 if not isinstance(box_name
, str):
15 raise TypeError("CXXRTL black box name must be a string, not {!r}"
17 if not isinstance(box_source
, str):
18 raise TypeError("CXXRTL black box source code must be a string, not {!r}"
21 yosys
= find_yosys(lambda ver
: ver
>= (0, 9, 3468))
24 if black_boxes
is not None:
25 for box_name
, box_source
in black_boxes
.items():
26 script
.append("read_ilang <<rtlil\n{}\nrtlil".format(box_source
))
27 script
.append("read_ilang <<rtlil\n{}\nrtlil".format(rtlil_text
))
28 script
.append("delete w:$verilog_initial_trigger")
29 script
.append("write_cxxrtl")
31 return yosys
.run(["-q", "-"], "\n".join(script
), src_loc_at
=1 + src_loc_at
)
34 def convert_fragment(*args
, black_boxes
=None, **kwargs
):
35 rtlil_text
, name_map
= rtlil
.convert_fragment(*args
, **kwargs
)
36 return _convert_rtlil_text(rtlil_text
, black_boxes
, src_loc_at
=1), name_map
39 def convert(*args
, black_boxes
=None, **kwargs
):
40 rtlil_text
= rtlil
.convert(*args
, **kwargs
)
41 return _convert_rtlil_text(rtlil_text
, black_boxes
, src_loc_at
=1)