3 #include "pybind11/operators.h"
4 #include "pybind11/pybind11.h"
5 #include "pybind11/stl.h"
6 #include "pybind11/stl_bind.h"
10 namespace py = pybind11;
18 #ifdef PYBIND11_MODULE
19 PYBIND11_MODULE(resynthesis, m)
21 m.doc() =
"Provides functions to decompose or re-synthesize combinational parts of a gate-level netlist.";
25 py::module m(
"resynthesis",
"Provides functions to decompose or re-synthesize combinational parts of a gate-level netlist.");
28 py::class_<ResynthesisPlugin, RawPtrWrapper<ResynthesisPlugin>,
BasePluginInterface> py_resynthesis_plugin(
29 m,
"ResynthesisPlugin", R
"(This class provides an interface to integrate the netlist resynthesis as a plugin within the HAL framework.)");
32 The name of the plugin.
38 Get the name of the plugin.
40 :returns: The name of the plugin.
45 The version of the plugin.
51 Get the version of the plugin.
53 :returns: The version of the plugin.
58 The description of the plugin.
64 Get the description of the plugin.
66 :returns: The description of the plugin.
71 A set of plugin names that this plugin depends on.
77 Get a set of plugin names that this plugin depends on.
79 :returns: A set of plugin names that this plugin depends on.
85 [](
Netlist* nl,
Gate* gate,
const bool delete_gate =
true) ->
bool {
93 log_error(
"python_context",
"{}", res.get_error().get());
99 py::arg(
"delete_gate") =
true,
101 Decompose a combinational gate into a small circuit of AND, OR, XOR, and INVERT gates.
102 For each output pin, the resolved Boolean function (only dependent on input pins) is determined.
103 All these Boolean functions are then converted into a netlist using the previously mentioned primitive gates.
104 The target gate is then replaced in the original netlist with the circuit that was just generated.
105 The target gate is only deleted if ``delete_gate`` is set to ``True``.
106 Gate replacement will fail if the gate library of the netlist does not contain suitable AND, OR, XOR, and INVERT gate types.
108 :param hal_py.Netlist nl: The netlist to operate on.
109 :param hal_py.Gate gate: The gate to decompose.
110 :param bool delete_gate: Set ``True`` to delete the original gate, ``False`` to keep it in the netlist. Defaults to ``True``.
111 :returns: ``True`` on success, ``False`` otherwise.
116 "decompose_gates_of_type",
117 [](
Netlist* nl,
const std::vector<const GateType*>& gate_types) -> std::optional<u32> {
125 log_error(
"python_context",
"{}", res.get_error().get());
130 py::arg(
"gate_types"),
132 Decompose all combinational gates of the specified types into small circuits of AND, OR, XOR, and INVERT gates.
133 For all output pins of each gate, the resolved Boolean function (only dependent on input pins) is determined.
134 All these Boolean functions are then converted into a circuit using the previously mentioned primitive gates.
135 The target gates are then replaced (and thereby deleted) in the original netlist with the circuit that was just generated.
136 Gate replacement will fail if the gate library of the netlist does not contain suitable AND, OR, XOR, and INVERT gate types.
138 :param hal_py.Netlist nl: The netlist to operate on.
139 :param list[hal_py.GateType] gate_types: The gate types to be decomposed.
140 :returns: The number of decomposed gates on success, ``None`` otherwise.
141 :rtype: int or ``None``
154 log_error(
"python_context",
"{}", res.get_error().get());
160 py::arg(
"target_gl"),
161 py::arg(
"delete_gate") =
true,
163 Re-synthesize a combinational gate by calling Yosys on a functional description of the gate using a reduced gate library.
164 For all output pins of each gate, the resolved Boolean function (only dependent on input pins) is determined.
165 All these Boolean functions are then written to an HDL file that is functionally equivalent to the target gate.
166 This file is fed to Yosys and subsequently synthesized to a netlist again by using the provided gate library.
167 The provided gate library should be a subset of the gate library that was used to parse the netlist.
168 The target gate is then replaced in the original netlist with the circuit that was just generated.
169 The target gate is only deleted if ``delete_gate`` is set to ``True``.
171 :param hal_py.Netlist nl: The netlist to operate on.
172 :param hal_py.Gate gate: The gate to re-synthesize.
173 :param hal_py.GateLibrary target_gl: The gate library that is a subset of the gate library used to parse the netlist.
174 :param bool delete_gate: Set ``True`` to delete the original gate, ``False`` to keep it in the netlist. Defaults to ``True``.
175 :returns: ``True`` on success, ``False`` otherwise.
180 "resynthesize_gates",
181 [](
Netlist* nl,
const std::vector<Gate*>& gates,
GateLibrary* target_gl) -> std::optional<u32> {
189 log_error(
"python_context",
"{}", res.get_error().get());
195 py::arg(
"target_gl"),
197 Re-synthesize all specified combinational gates by calling Yosys on a functional description of the gates using a reduced gate library.
198 For all output pins of each gate, the resolved Boolean function (only dependent on input pins) is determined.
199 All Boolean functions of a gate are then written to an HDL file that is functionally equivalent to the gate.
200 These files are fed to Yosys and subsequently synthesized to a netlist again by using the provided gate library.
201 The provided gate library should be a subset of the gate library that was used to parse the netlist.
202 The gates are then replaced in the original netlist with the circuits that were just generated.
203 This process is repeated for every gate, hence they are re-synthesized in isolation.
205 :param hal_py.Netlist nl: The netlist to operate on.
206 :param hal_py.Gate g: The gates to re-synthesize.
207 :param hal_py.GateLibrary target_gl: The gate library that is a subset of the gate library used to parse the netlist.
208 :returns: The number of re-synthesized gates on success, ``None`` otherwise.
209 :rtype: int or ``None``
213 "resynthesize_gates_of_type",
214 [](
Netlist* nl,
const std::vector<const GateType*>& gate_types,
GateLibrary* target_gl) -> std::optional<u32> {
222 log_error(
"python_context",
"{}", res.get_error().get());
227 py::arg(
"gate_types"),
228 py::arg(
"target_gl"),
230 Re-synthesize all combinational gates of the specified types by calling Yosys on a functional description of the gates using a reduced gate library.
231 For all output pins of each gate, the resolved Boolean function (only dependent on input pins) is determined.
232 All Boolean functions of a gate are then written to an HDL file that is functionally equivalent to the gate.
233 These files are fed to Yosys and subsequently synthesized to a netlist again by using the provided gate library.
234 The provided gate library should be a subset of the gate library that was used to parse the netlist.
235 The gates are then replaced in the original netlist with the circuits that were just generated.
236 This process is repeated for every gate, hence they are re-synthesized in isolation.
238 :param hal_py.Netlist nl: The netlist to operate on.
239 :param list[hal_py.GateType] gate_types: The gate types to be re-synthesized.
240 :param hal_py.GateLibrary target_gl: The gate library that is a subset of the gate library used to parse the netlist.
241 :returns: The number of re-synthesized gates on success, ``None`` otherwise.
242 :rtype: int or ``None``
246 "resynthesize_subgraph",
247 [](
Netlist* nl,
const std::vector<Gate*>& subgraph,
GateLibrary* target_gl) -> std::optional<u32> {
255 log_error(
"python_context",
"{}", res.get_error().get());
261 py::arg(
"target_gl"),
263 Re-synthesize the combinational gates of the subgraph by calling Yosys on a Verilog netlist representation of the subgraph using a reduced gate library.
264 All gates of the subgraph are written to a Verilog netlist file which is then fed to Yosys and subsequently synthesized to a netlist again by using the provided gate library.
265 The provided gate library should be a subset of the gate library that was used to parse the netlist.
266 The gates are then replaced in the original netlist with the circuit that was just generated.
268 :param hal_py.Netlist nl: The netlist to operate on.
269 :param list[hal_py.Gate] subgraph: The subgraph to re-synthesize.
270 :param hal_py.GateLibrary target_lib: The gate library that is a subset of the gate library used to parse the netlist.
271 :returns: The number of re-synthesized gates on success, ``None`` otherwise.
272 :rtype: int or ``None``
276 "resynthesize_subgraph_of_type",
277 [](
Netlist* nl,
const std::vector<const GateType*>& gate_types,
GateLibrary* target_gl) -> std::optional<u32> {
285 log_error(
"python_context",
"{}", res.get_error().get());
290 py::arg(
"gate_types"),
291 py::arg(
"target_gl"),
293 Re-synthesize the combinational gates of the specified types as a subgraph by calling Yosys on a Verilog netlist representation of the subgraph induced by these gates using a reduced gate library.
294 All gates of the subgraph are written to a Verilog netlist file which is then fed to Yosys and subsequently synthesized to a netlist again by using the provided gate library.
295 The provided gate library should be a subset of the gate library that was used to parse the netlist.
296 The gates are then replaced in the original netlist with the circuit that was just generated.
298 :param hal_py.Netlist nl: The netlist to operate on.
299 :param list[hal_py.GateType] gate_types: The gate types to be re-synthesized.
300 :param hal_py.GateLibrary target_lib: The gate library that is a subset of the gate library used to parse the netlist.
301 :returns: The number of re-synthesized gates on success, ``None`` otherwise.
302 :rtype: int or ``None``
305 #ifndef PYBIND11_MODULE
std::string get_description() const override
Get a short description of the plugin.
std::string get_name() const override
Get the name of the plugin.
std::set< std::string > get_dependencies() const override
Get the plugin dependencies.
std::string get_version() const override
Get the version of the plugin.
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)
Result< u32 > resynthesize_gates(Netlist *nl, const std::vector< Gate * > &gates, GateLibrary *target_gl)
Result< std::monostate > decompose_gate(Netlist *nl, Gate *gate, const bool delete_gate=true)
Result< std::monostate > resynthesize_gate(Netlist *nl, Gate *gate, GateLibrary *target_gl, const bool delete_gate=true)
Result< u32 > decompose_gates_of_type(Netlist *nl, const std::vector< const GateType * > &gate_types)
Result< u32 > resynthesize_subgraph_of_type(Netlist *nl, const std::vector< const GateType * > &gate_types, GateLibrary *target_gl)
Result< u32 > resynthesize_subgraph(Netlist *nl, const std::vector< Gate * > &subgraph, GateLibrary *target_gl)
Result< u32 > resynthesize_gates_of_type(Netlist *nl, const std::vector< const GateType * > &gate_types, GateLibrary *target_gl)
This file contains all functions related to the HAL plugin API.
This file contains functions to decompose or re-synthesize combinational parts of a gate-level netlis...