5 #include "pybind11/operators.h"
6 #include "pybind11/pybind11.h"
7 #include "pybind11/stl.h"
8 #include "pybind11/stl_bind.h"
10 namespace py = pybind11;
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.
71 "propagate_module_pingroup_bitorder",
74 const bool enforce_continuous_bitorders =
true) -> std::optional<std::map<std::pair<
Module*,
PinGroup<ModulePin>*>, std::map<Net*, u32>>> {
82 log_error(
"python_context",
"{}", res.get_error().get());
88 py::arg(
"enforce_continuous_bitorders") =
true,
90 Propagate known bit-order information from the given module pin groups to module pin groups of unknown bit order.
91 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``.
92 After propagation, the algorithm tries to reconstruct valid bit orders from the propagated information.
94 :param dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] src: The known indices for the nets belonging to the given module pin groups.
95 :param set[tuple(hal_py.Module,hal_py.ModulePinGroup)] dst: The pairs of module ID and pin group name with unknown bit order.
96 :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``.
97 :returns: A dict containing all known bit orders (including new and already known ones) on success, ``None`` otherwise.
98 :rtype: dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] or None
102 "reorder_module_pin_groups",
111 log_error(
"python_context",
"{}", res.get_error().get());
115 py::arg(
"ordered_module_pin_groups"),
117 Reorder and rename the pins of the pin groups according to the provided bit-order information.
119 :param dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] ordered_module_pin_groups: A mapping from pairs of modules and their pin groups to known bit-order information given as a mapping from nets to their index.
120 :returns: ``True`` on success, ``False`` otherwise.
125 "propagate_bitorder",
126 [](
Netlist* nl,
const std::pair<u32, std::string>& src,
const std::pair<u32, std::string>& dst) -> std::optional<std::map<std::pair<Module*, PinGroup<ModulePin>*>, std::map<Net*, u32>>> {
134 log_error(
"python_context",
"{}", res.get_error().get());
142 Propagate known bit-order information from one module pin group to another module pin group of unknown bit order.
143 The known bit-order information is taken from the order of pins in the pin group of ``src``.
144 After propagation, the algorithm tries to reconstruct a valid bit order from the propagated information.
145 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.
147 :param hal_py.netlist nl: The netlist containing the module.
148 :param tuple(int,str) src: The pair of module ID and pin group name with known bit order.
149 :param tuple(int,str) dst: The pair of module ID and pin group name with unknown bit order.
150 :returns: A dict containing all known bit orders (including new and already known ones) on success, ``None`` otherwise.
151 :rtype: dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] or None
155 "propagate_bitorder",
157 const std::pair<
Module*,
PinGroup<ModulePin>*>& dst) -> std::optional<std::map<std::pair<Module*, PinGroup<ModulePin>*>, std::map<Net*, u32>>> {
165 log_error(
"python_context",
"{}", res.get_error().get());
172 Propagate known bit-order information from one module pin group to another module pin group of unknown bit order.
173 The known bit-order information is taken from the order of pins in the pin group of ``src``.
174 After propagation, the algorithm tries to reconstruct a valid bit order from the propagated information.
175 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.
177 :param tuple(hal_py.Module,hal_py.ModulePinGroup) src: The pair of module and pin group with known bit order.
178 :param tuple(hal_py.Module,hal_py.ModulePinGroup) dst: The pair of module and pin group with unknown bit order.
179 :returns: A dict containing all known bit orders (including new and already known ones) on success, ``None`` otherwise.
180 :rtype: dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] or None
184 "propagate_bitorder",
186 const std::vector<std::pair<u32, std::string>>& src,
187 const std::vector<std::pair<u32, std::string>>& dst) -> std::optional<std::map<std::pair<Module*, PinGroup<ModulePin>*>, std::map<Net*, u32>>> {
195 log_error(
"python_context",
"{}", res.get_error().get());
203 Propagate known bit-order information from the given module pin groups to module pin groups of unknown bit order.
204 The known bit-order information is taken from the order of pins in the pin groups of ``src``.
205 After propagation, the algorithm tries to reconstruct valid bit orders from the propagated information.
206 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.
208 :param hal_py.netlist nl: The netlist containing the modules.
209 :param list[tuple(int,str)] src: The pairs of module ID and pin group name with known bit order.
210 :param list[tuple(int,str)] dst: The pairs of module ID and pin group name with unknown bit order.
211 :returns: A dict containing all known bit orders (including new and already known ones) on success, ``None`` otherwise.
212 :rtype: dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] or None
216 "propagate_bitorder",
218 const std::vector<std::pair<
Module*,
PinGroup<ModulePin>*>>& dst) -> std::optional<std::map<std::pair<Module*, PinGroup<ModulePin>*>, std::map<Net*, u32>>> {
226 log_error(
"python_context",
"{}", res.get_error().get());
233 Propagate known bit-order information from the given module pin groups to module pin groups of unknown bit order.
234 The known bit-order information is taken from the order of pins in the pin groups of ``src``.
235 After propagation, the algorithm tries to reconstruct valid bit orders from the propagated information.
236 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.
238 :param list[tuple(hal_py.Module,hal_py.ModulePinGroup)] src: The pairs of module and pin group with known bit order.
239 :param list[tuple(hal_py.Module,hal_py.ModulePinGroup)] dst: The pairs of module and pin group with unknown bit order.
240 :returns: A dict containing all known bit orders (including new and already known ones) on success, ``None`` otherwise.
241 :rtype: dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] or None
245 "export_bitorder_propagation_information",
248 const std::string& export_filepath) -> std::optional<std::map<std::pair<Module*, PinGroup<ModulePin>*>,
u32>> {
256 log_error(
"python_context",
"{}", res.get_error().get());
262 py::arg(
"export_filepath"),
264 Export collected bitorder information like word composition, known bitorder and connectivity in ``.json`` format to solve with external tools.
266 :param dict[tuple(hal_py.Module,hal_py.ModulePinGroup),dict[hal_py.Net,int]] src: The known indices for the nets belonging to the given module pin groups.
267 :param set[tuple(hal_py.Module,hal_py.ModulePinGroup)] dst: The pairs of module ID and pin group name with unknown bit order.
268 :param str export_filepath: The filepath where the ``.json`` file should be written to.
269 :returns: The mapping from each mdoule/pingroup pair to its index on success, ``None`` otherwise.
270 :rtype: dict[tuple(hal_py.Module, hal_py.ModulePinGroup), int] or None
274 "export_bitorder_propagation_information",
277 const std::string& export_filepath) -> std::optional<std::map<std::pair<Module*, PinGroup<ModulePin>*>,
u32>> {
285 log_error(
"python_context",
"{}", res.get_error().get());
291 py::arg(
"export_filepath"),
293 Export collected bitorder information like word composition, known bitorder and connectivity in ``.json`` format to solve with external tools.
295 :param tuple(hal_py.Module,hal_py.ModulePinGroup) src: The pair of module and pin group with known bit order.
296 :param tuple(hal_py.Module,hal_py.ModulePinGroup) dst: The pair of module and pin group with unknown bit order.
297 :param str export_filepath: The filepath where the ``.json`` file should be written to.
298 :returns: The mapping from each mdoule/pingroup pair to its index on success, ``None`` otherwise.
299 :rtype: dict[tuple(hal_py.Module, hal_py.ModulePinGroup), int] or None
302 #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.
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)
Result< std::map< std::pair< Module *, PinGroup< ModulePin > * >, std::map< Net *, u32 > > > 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 std::map< std::pair< Module *, PinGroup< ModulePin > * >, std::map< Net *, u32 >> &ordered_module_pin_groups)
Reorder and rename the pins of the pin groups according to the provided bit-order information.
Result< std::map< std::pair< Module *, PinGroup< ModulePin > * >, u32 > > 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...
Result< std::map< std::pair< Module *, PinGroup< ModulePin > * >, std::map< Net *, u32 > > > propagate_module_pingroup_bitorder(const std::map< std::pair< Module *, PinGroup< ModulePin > * >, std::map< Net *, u32 >> &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...
This file contains all functions related to the HAL plugin API.