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 # FIXME: update this requirement once Yosys updates its node version
22 yosys
= find_yosys(lambda ver
: ver
>= (0, 9))
25 if black_boxes
is not None:
26 for box_name
, box_source
in black_boxes
.items():
27 script
.append("read_ilang <<rtlil\n{}\nrtlil".format(box_source
))
28 script
.append("read_ilang <<rtlil\n{}\nrtlil".format(rtlil_text
))
29 script
.append("delete w:$verilog_initial_trigger")
30 script
.append("write_cxxrtl")
32 return yosys
.run(["-q", "-"], "\n".join(script
), src_loc_at
=1 + src_loc_at
)
35 def convert_fragment(*args
, black_boxes
=None, **kwargs
):
36 rtlil_text
, name_map
= rtlil
.convert_fragment(*args
, **kwargs
)
37 return _convert_rtlil_text(rtlil_text
, black_boxes
, src_loc_at
=1), name_map
40 def convert(*args
, black_boxes
=None, **kwargs
):
41 rtlil_text
= rtlil
.convert(*args
, **kwargs
)
42 return _convert_rtlil_text(rtlil_text
, black_boxes
, src_loc_at
=1)