5 #include "pybind11/operators.h"
6 #include "pybind11/pybind11.h"
7 #include "pybind11/stl.h"
8 #include "pybind11/stl_bind.h"
18 #ifdef PYBIND11_MODULE
19 PYBIND11_MODULE(bitorder_propagation, m)
21 m.doc() =
"Tool to automatically propagate known bit orders to module pin groups of unknown bit order.";
25 py::module m(
"bitorder_propagation",
"Tool to automatically propagate known bit orders to module pin groups of unknown bit order.");
28 py::class_<BitorderPropagationPlugin, RawPtrWrapper<BitorderPropagationPlugin>,
BasePluginInterface> py_bitorder_propagation_plugin(
29 m,
"BitorderPropagationPlugin", R
"(This class provides an interface to integrate the bit-order propagation 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.
70 py::class_<bitorder_propagation::BitOrder> py_bit_order(m, "BitOrder", R
"(
71 The bit order of a single module pin group, i.e., which net of the pin group carries which bit.
74 py_bit_order.def(py::init<Module*, PinGroup<ModulePin>*, std::vector<std::pair<Net*, u32>>>(), py::arg("module"), py::arg(
"pin_group"), py::arg(
"order"), R
"(
75 Construct a bit order for a module pin group.
77 :param hal_py.Module module: The module the pin group belongs to.
78 :param hal_py.ModulePinGroup pin_group: The pin group.
79 :param list[tuple(hal_py.Net,int)] order: The index of each net of the pin group.
86 The module that the pin group belongs to.
92 The pin group whose bit order this is.
94 :type: hal_py.ModulePinGroup
98 The index of every net, ordered by index.
100 :type: list[tuple(hal_py.Net,int)]
104 Get the index of the given net.
106 :param hal_py.Net net: The net.
107 :returns: The index of the net, ``None`` if the net is not part of this bit order.
112 Get the net at the given index.
114 :param int index: The index.
115 :returns: The net at the index, ``None`` if no net carries that index.
116 :rtype: hal_py.Net or None
120 The number of nets that the bit order covers.
126 Check whether the indices run from 0 without leaving a gap.
128 :returns: ``True`` if the order is continuous, ``False`` otherwise.
132 py_bit_order.def(py::self == py::self);
133 py_bit_order.def(py::self != py::self);
135 py::class_<bitorder_propagation::BitOrderResult> py_bit_order_result(m, "BitOrderResult", R
"(
136 The bit orders that are known, which is what a propagation reports: the ones it was given as well as the ones it worked out.
138 Iterating over a result walks the bit orders by module ID and then by pin group ID, so it does not depend on where the modules and pin groups happen to be allocated.
141 py_bit_order_result.def(py::init<>(), R"(Construct a result that holds no bit order.)");
143 py_bit_order_result.def(py::init<std::vector<bitorder_propagation::BitOrder>>(), py::arg("bit_orders"), R
"(
144 Construct a result from the given bit orders.
146 :param list[bitorder_propagation.BitOrder] bit_orders: The bit orders.
150 Add a bit order, replacing one that is already known for the same pin group.
152 :param bitorder_propagation.BitOrder bit_order: The bit order.
155 py_bit_order_result.def_property_readonly(
157 Every bit order, ordered by module ID and pin group ID.
159 :type: list[bitorder_propagation.BitOrder]
163 Get the bit order of the given pin group.
165 :param hal_py.Module module: The module the pin group belongs to.
166 :param hal_py.ModulePinGroup pin_group: The pin group.
167 :returns: The bit order, ``None`` if the pin group has no known bit order.
168 :rtype: bitorder_propagation.BitOrder or None
172 Check whether the bit order of the given pin group is known.
174 :param hal_py.Module module: The module the pin group belongs to.
175 :param hal_py.ModulePinGroup pin_group: The pin group.
176 :returns: ``True`` if the bit order is known, ``False`` otherwise.
182 py_bit_order_result.def(
186 "propagate_module_pingroup_bitorder",
189 const bool enforce_continuous_bitorders =
true) -> std::optional<bitorder_propagation::BitOrderResult> {
197 log_error(
"python_context",
"{}", res.get_error().get());
203 py::arg(
"enforce_continuous_bitorders") =
true,
205 Propagate known bit-order information from the given module pin groups to module pin groups of unknown bit order.
206 The known bit-order information is taken from the map from net to index given for each pair of module and pin group in ``src``.
207 After propagation, the algorithm tries to reconstruct valid bit orders from the propagated information.
209 :param bitorder_propagation.BitOrderResult src: The bit orders that are already known.
210 :param set[tuple(hal_py.Module,hal_py.ModulePinGroup)] dst: The pairs of module ID and pin group name with unknown bit order.
211 :param bool enforce_continuous_bitorders: Set ``True`` to only allow for continuous bit orders, ``^`` to also allow bit orders that are not continuous. Defaults to ``True``.
212 :returns: All known bit orders, the new ones as well as the ones already known, on success, ``None`` otherwise.
213 :rtype: bitorder_propagation.BitOrderResult or None
217 "reorder_module_pin_groups",
226 log_error(
"python_context",
"{}", res.get_error().get());
230 py::arg(
"ordered_module_pin_groups"),
232 Reorder and rename the pins of the pin groups according to the provided bit-order information.
234 :param bitorder_propagation.BitOrderResult ordered_module_pin_groups: The bit orders to apply.
235 :returns: ``True`` on success, ``False`` otherwise.
240 "propagate_bitorder",
241 [](
Netlist* nl,
const std::pair<u32, std::string>& src,
const std::pair<u32, std::string>& dst) -> std::optional<bitorder_propagation::BitOrderResult> {
249 log_error(
"python_context",
"{}", res.get_error().get());
257 Propagate known bit-order information from one module pin group to another module pin group of unknown bit order.
258 The known bit-order information is taken from the order of pins in the pin group of ``src``.
259 After propagation, the algorithm tries to reconstruct a valid bit order from the propagated information.
260 The valid bit order is then annotated to the module pin group, i.e., the pins of the respective pin group are renamed and reordered.
262 :param hal_py.netlist nl: The netlist containing the module.
263 :param tuple(int,str) src: The pair of module ID and pin group name with known bit order.
264 :param tuple(int,str) dst: The pair of module ID and pin group name with unknown bit order.
265 :returns: A dict containing all known bit orders (including new and already known ones) on success, ``None`` otherwise.
266 :rtype: dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] or None
270 "propagate_bitorder",
280 log_error(
"python_context",
"{}", res.get_error().get());
287 Propagate known bit-order information from one module pin group to another module pin group of unknown bit order.
288 The known bit-order information is taken from the order of pins in the pin group of ``src``.
289 After propagation, the algorithm tries to reconstruct a valid bit order from the propagated information.
290 The valid bit order is then annotated to the module pin group, i.e., the pins of the respective pin group are renamed and reordered.
292 :param tuple(hal_py.Module,hal_py.ModulePinGroup) src: The pair of module and pin group with known bit order.
293 :param tuple(hal_py.Module,hal_py.ModulePinGroup) dst: The pair of module and pin group with unknown bit order.
294 :returns: A dict containing all known bit orders (including new and already known ones) on success, ``None`` otherwise.
295 :rtype: dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] or None
299 "propagate_bitorder",
301 const std::vector<std::pair<u32, std::string>>& src,
302 const std::vector<std::pair<u32, std::string>>& dst) -> std::optional<bitorder_propagation::BitOrderResult> {
310 log_error(
"python_context",
"{}", res.get_error().get());
318 Propagate known bit-order information from the given module pin groups to module pin groups of unknown bit order.
319 The known bit-order information is taken from the order of pins in the pin groups of ``src``.
320 After propagation, the algorithm tries to reconstruct valid bit orders from the propagated information.
321 The valid bit orders are then annotated to the module pin groups, i.e., the pins of the respective pin groups are renamed and reordered.
323 :param hal_py.netlist nl: The netlist containing the modules.
324 :param list[tuple(int,str)] src: The pairs of module ID and pin group name with known bit order.
325 :param list[tuple(int,str)] dst: The pairs of module ID and pin group name with unknown bit order.
326 :returns: A dict containing all known bit orders (including new and already known ones) on success, ``None`` otherwise.
327 :rtype: dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] or None
331 "propagate_bitorder",
333 const std::vector<std::pair<
Module*,
PinGroup<ModulePin>*>>& dst) -> std::optional<bitorder_propagation::BitOrderResult> {
341 log_error(
"python_context",
"{}", res.get_error().get());
348 Propagate known bit-order information from the given module pin groups to module pin groups of unknown bit order.
349 The known bit-order information is taken from the order of pins in the pin groups of ``src``.
350 After propagation, the algorithm tries to reconstruct valid bit orders from the propagated information.
351 The valid bit orders are then annotated to the module pin groups, i.e., the pins of the respective pin groups are renamed and reordered.
353 :param list[tuple(hal_py.Module,hal_py.ModulePinGroup)] src: The pairs of module and pin group with known bit order.
354 :param list[tuple(hal_py.Module,hal_py.ModulePinGroup)] dst: The pairs of module and pin group with unknown bit order.
355 :returns: A dict containing all known bit orders (including new and already known ones) on success, ``None`` otherwise.
356 :rtype: dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] or None
360 "export_bitorder_propagation_information",
363 const std::string& export_filepath) -> std::optional<std::map<std::pair<Module*, PinGroup<ModulePin>*>,
u32>> {
371 log_error(
"python_context",
"{}", res.get_error().get());
377 py::arg(
"export_filepath"),
379 Export collected bitorder information like word composition, known bitorder and connectivity in ``.json`` format to solve with external tools.
381 :param bitorder_propagation.BitOrderResult src: The bit orders that are already known.
382 :param set[tuple(hal_py.Module,hal_py.ModulePinGroup)] dst: The pairs of module ID and pin group name with unknown bit order.
383 :param str export_filepath: The filepath where the ``.json`` file should be written to.
384 :returns: The mapping from each mdoule/pingroup pair to its index on success, ``None`` otherwise.
385 :rtype: dict[tuple(hal_py.Module, hal_py.ModulePinGroup), int] or None
389 "export_bitorder_propagation_information",
392 const std::string& export_filepath) -> std::optional<std::map<std::pair<Module*, PinGroup<ModulePin>*>,
u32>> {
400 log_error(
"python_context",
"{}", res.get_error().get());
406 py::arg(
"export_filepath"),
408 Export collected bitorder information like word composition, known bitorder and connectivity in ``.json`` format to solve with external tools.
410 :param tuple(hal_py.Module,hal_py.ModulePinGroup) src: The pair of module and pin group with known bit order.
411 :param tuple(hal_py.Module,hal_py.ModulePinGroup) dst: The pair of module and pin group with unknown bit order.
412 :param str export_filepath: The filepath where the ``.json`` file should be written to.
413 :returns: The mapping from each mdoule/pingroup pair to its index on success, ``None`` otherwise.
414 :rtype: dict[tuple(hal_py.Module, hal_py.ModulePinGroup), int] or None
417 #ifndef PYBIND11_MODULE
This file contains functions for bit-order propagation from pin groups of known bit order to pin grou...
std::string get_description() const override
Get a short description of the plugin.
std::string get_version() const override
Get the version of the plugin.
std::string get_name() const override
Get the name of the plugin.
Module * get_module() const
Net * get_net_at(u32 index) const
std::optional< u32 > get_index(const Net *net) const
bool is_continuous() const
const std::vector< std::pair< Net *, u32 > > & get_order() const
PinGroup< ModulePin > * get_pin_group() const
bool contains(const Module *module, const PinGroup< ModulePin > *pin_group) const
const BitOrder * get(const Module *module, const PinGroup< ModulePin > *pin_group) const
const std::vector< BitOrder > & get_bit_orders() const
void add(BitOrder bit_order)
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)
Result< BitOrderResult > propagate_bitorder(Netlist *nl, const std::pair< u32, std::string > &src, const std::pair< u32, std::string > &dst)
Propagate known bit-order information from one module pin group to another module pin group of unknow...
Result< std::monostate > reorder_module_pin_groups(const BitOrderResult &ordered_module_pin_groups)
Reorder and rename the pins of the pin groups according to the provided bit-order information.
Result< BitOrderResult > propagate_module_pingroup_bitorder(const BitOrderResult &src, const std::set< std::pair< Module *, PinGroup< ModulePin > * >> &dst, const bool enforce_continuous_bitorders=true)
Propagate known bit-order information from the given module pin groups to module pin groups of unknow...
Result< std::map< std::pair< Module *, PinGroup< ModulePin > * >, WordIndex > > export_bitorder_propagation_information(const std::vector< std::pair< Module *, PinGroup< ModulePin > * >> &src, const std::vector< std::pair< Module *, PinGroup< ModulePin > * >> &dst, const std::string &export_filepath)
Export word composition, known bitorder and connectivity in .json format to solve with external tools...
This file contains all functions related to the HAL plugin API.