HAL
module.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
6  {
7  py::class_<Module, DataContainer, RawPtrWrapper<Module>> py_module(m, "Module", R"(
8  A module is a container for gates and their associated nets that enables hierarchization within the netlist.
9  Each gate can only be in one module at a time. Nets are only loosely associated with modules.
10  )");
11 
12  py_module.def(py::self == py::self, R"(
13  Check whether two modules are equal.
14  Does not check for parent module.
15 
16  :returns: ``True`` if both modules are equal, ``False`` otherwise.
17  :rtype: bool
18  )");
19 
20  py_module.def(py::self != py::self, R"(
21  Check whether two modules are unequal.
22  Does not check for parent module.
23 
24  :returns: ``True`` if both modules are unequal, ``False`` otherwise.
25  :rtype: bool
26  )");
27 
28  py_module.def("__hash__", &Module::get_hash, R"(
29  Python requires hash for set and dict container.
30 
31  :returns: The hash.
32  :rtype: Py_hash_t
33  )");
34 
35  py_module.def_property_readonly("id", &Module::get_id, R"(
36  The unique ID of the module.
37 
38  :type: int
39  )");
40 
41  py_module.def("get_id", &Module::get_id, R"(
42  Get the unique ID of the module.
43 
44  :returns: The unique id.
45  :rtype: int
46  )");
47 
48  py_module.def_property("name", &Module::get_name, &Module::set_name, R"(
49  The name of the module.
50 
51  :type: str
52  )");
53 
54  py_module.def("get_name", &Module::get_name, R"(
55  Get the name of the module.
56 
57  :returns: The name.
58  :rtype: str
59  )");
60 
61  py_module.def("set_name", &Module::set_name, py::arg("name"), R"(
62  Set the name of the module.
63 
64  :param str name: The new name.
65  )");
66 
67  py_module.def_property("type", &Module::get_type, &Module::set_type, R"(
68  The type of the module.
69 
70  :type: str
71  )");
72 
73  py_module.def("get_type", &Module::get_type, R"(
74  Get the type of the module.
75 
76  :returns: The type.
77  :rtype: str
78  )");
79 
80  py_module.def("set_type", &Module::set_type, py::arg("type"), R"(
81  Set the type of the module.
82 
83  :param str type: The new type.
84  )");
85 
86  py_module.def("get_grouping", &Module::get_grouping, R"(
87  Get the grouping in which this module is contained.
88 
89  :returns: The grouping.
90  :rtype: hal_py.Grouping
91  )");
92 
93  py_module.def_property_readonly("submodule_depth", &Module::get_submodule_depth, R"(
94  The depth of the module within the module hierarchie (0 = top module, 1 = direct child of top module, ...).
95 
96  :type: int
97  )");
98 
99  py_module.def("get_submodule_depth", &Module::get_submodule_depth, R"(
100  Get the depth of the module within the module hierarchie (0 = top module, 1 = direct child of top module, ...).
101 
102  :returns: The depth within the module hierarchie.
103  :rtype: int
104  )");
105 
106  py_module.def_property("parent_module", &Module::get_parent_module, &Module::set_parent_module, R"(
107  The parent module of this module.
108  Is set to None for the top module, but cannot be set to None by the user.
109 
110  :type: hal_py.Module or None
111  )");
112 
113  py_module.def("get_parent_module", &Module::get_parent_module, R"(
114  Get the parent module of this module.
115  For the top module, None is returned.
116 
117  :returns: The parent module.
118  :rtype: hal_py.Module or None
119  )");
120 
121  py_module.def_property_readonly("parent_modules", [](Module* mod) { return mod->get_parent_modules(); }, R"(
122  The parent modules of this module.
123 
124  :type: list[hal_py.Module]
125  )");
126 
127  py_module.def("get_parent_modules", &Module::get_parent_modules, py::arg("filter") = nullptr, py::arg("recursive") = true, R"(
128  Get all parents of this module.
129  If ``recursive`` is set to ``True``, all indirect parents are also included.
130  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
131 
132  :param lambda filter: An optional filter.
133  :param bool recursive: Set ``True`` to include indirect parents as well, ``False`` otherwise.
134  :returns: A list of parent modules.
135  :rtype: list[hal_py.Module]
136  )");
137 
138  py_module.def("set_parent_module", &Module::set_parent_module, py::arg("new_parent"), R"(
139  Set a new parent for this module.
140  If the new parent is a submodule of this module, the new parent is added as a direct submodule to the old parent first.
141 
142  :param hal_py.Module new_parent: The new parent module.
143  :returns: ``True`` if the parent was changed, ``False`` otherwise.
144  :rtype: bool
145  )");
146 
147  py_module.def("is_parent_module_of", &Module::is_parent_module_of, py::arg("module"), py::arg("recursive") = false, R"(
148  Check if the module is a parent of the specified module.
149 
150  :param hal_py.Module module: The module.
151  :param bool recursive: Set ``True`` to check recursively, ``False`` otherwise.
152  :returns: ``True`` if the module is a parent of the specified module, ``False`` otherwise.
153  :rtype: bool
154  )");
155 
156  py_module.def_property_readonly("submodules", [](Module* mod) { return mod->get_submodules(); }, R"(
157  A list of all direct submodules of this module.
158 
159  :type: list[hal_py.Module]
160  )");
161 
162  py_module.def("get_submodules", &Module::get_submodules, py::arg("filter") = nullptr, py::arg("recursive") = false, R"(
163  Get all direct submodules of this module.
164  If ``recursive`` is set to ``True``, all indirect submodules are also included.
165  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
166 
167  :param lambda filter: An optional filter.
168  :param bool recursive: Set ``True`` to include indirect submodules as well, ``False`` otherwise.
169  :returns: A list of submodules.
170  :rtype: list[hal_py.Module]
171  )");
172 
173  py_module.def("is_submodule_of", &Module::is_submodule_of, py::arg("module"), py::arg("recursive") = false, R"(
174  Check if the module is a submodule of the specified module.
175 
176  :param hal_py.Module module: The module.
177  :param bool recursive: Set ``True`` to check recursively, ``False`` otherwise.
178  :returns: ``True`` if the module is a submodule of the specified module, ``False`` otherwise.
179  )");
180 
181  py_module.def("contains_module", &Module::contains_module, py::arg("other"), py::arg("recusive") = false, R"(
182  Checks whether another module is a submodule of this module.
183  If recursive is set to ``True``, all indirect submodules are also included.
184 
185  :param hal_py.Module other: Other module to check for.
186  :param bool recursive: Set ``True`` to include indirect submodules as well, ``False`` otherwise.
187  :returns: ``True`` if the other module is a submodule, ``False`` otherwise.
188  :rtype: bool
189  )");
190 
191  py_module.def_property_readonly("top_module", &Module::is_top_module, R"(
192  True only if the module is the top module of the netlist.
193 
194  :type: bool
195  )");
196 
197  py_module.def("is_top_module", &Module::is_top_module, R"(
198  Returns true only if the module is the top module of the netlist.
199 
200  :returns: ``True`` if the module is the top module, ``False`` otherwise.
201  :rtype: bool
202  )");
203 
204  py_module.def_property_readonly("netlist", [](Module* module) { return RawPtrWrapper<Netlist>(module->get_netlist()); }, R"(
205  The netlist this module is associated with.
206 
207  :type: hal_py.Netlist
208  )");
209 
210  py_module.def("get_netlist", [](Module* module) { return RawPtrWrapper<Netlist>(module->get_netlist()); }, R"(
211  Get the netlist this module is associated with.
212 
213  :returns: The netlist.
214  :rtype: hal_py.Netlist
215  )");
216 
217  py_module.def("update_nets", &Module::update_nets, R"(
218  Iterates over all nets connected to at least one gate of the module to update the nets, internal nets, input nets, and output nets of the module.
219  Has no effect on module pins.
220 
221  WARNING: can only be used when automatic net checks have been disabled using hal_py.Netlist.enable_automatic_net_checks.
222 
223  :returns: ``True`` on success, ``False`` otherwise.
224  :rtype: bool
225  )");
226 
227  py_module.def("contains_net", &Module::contains_net, py::arg("net"), py::arg("recursive") = false, R"(
228  Check whether a net is contained in the module.
229  If ``recursive`` is set to ``True``, nets in submodules are considered as well.
230 
231  :param hal_py.Net net: The net to check for.
232  :param bool recursive: ``True`` to also consider nets in submodules, ``False`` otherwise.
233  :returns: ``True`` if the net is contained in the module, ``False`` otherwise.
234  :rtype: bool
235  )");
236 
237  py_module.def_property_readonly("nets", py::overload_cast<>(&Module::get_nets, py::const_), R"(
238  An unordered set of all nets that have at least one source or one destination within the module.
239 
240  :type: set[hal_py.Net]
241  )");
242 
243  py_module.def("get_nets", py::overload_cast<>(&Module::get_nets, py::const_), R"(
244  Get all nets that have at least one source or one destination within the module.
245 
246  :returns: An unordered set of nets.
247  :rtype: set[hal_py.Net]
248  )");
249 
250  py_module.def("get_nets", py::overload_cast<const std::function<bool(Net*)>&, bool>(&Module::get_nets, py::const_), py::arg("filter"), py::arg("recursive") = false, R"(
251  Get all nets that have at least one source or one destination within the module.
252  The filter is evaluated on every candidate such that the result only contains those matching the specified condition.
253  If ``recursive`` is ``True``, nets in submodules are considered as well.
254 
255  :param lambda filter: Filter function to be evaluated on each net.
256  :param bool recursive: ``True`` to also consider nets in submodules, ``False`` otherwise.
257  :returns: An unordered set of nets.
258  :rtype: set[hal_py.Net]
259  )");
260 
261  py_module.def_property_readonly("input_nets", &Module::get_input_nets, R"(
262  A set of all nets that are either a global input to the netlist or have at least one source outside of the module.
263 
264  :type: set[hal_py.Net]
265  )");
266 
267  py_module.def("get_input_nets", &Module::get_input_nets, R"(
268  Get all nets that are either a global input to the netlist or have at least one source outside of the module.
269 
270  :returns: A set of input nets.
271  :rtype: set[hal_py.Net]
272  )");
273 
274  py_module.def_property_readonly("output_nets", &Module::get_output_nets, R"(
275  A set of all nets that are either a global output to the netlist or have at least one destination outside of the module.
276 
277  :type: set[hal_py.Net]
278  )");
279 
280  py_module.def("get_output_nets", &Module::get_output_nets, R"(
281  Get all nets that are either a global output to the netlist or have at least one destination outside of the module.
282 
283  :returns: A set of output nets.
284  :rtype: set[hal_py.Net]
285  )");
286 
287  py_module.def_property_readonly("internal_nets", &Module::get_internal_nets, R"(
288  A set of all nets that have at least one source and one destination within the module, including its submodules. The result may contain nets that are also regarded as input or output nets.
289 
290  :type: set[hal_py.Net]
291  )");
292 
293  py_module.def("get_internal_nets", &Module::get_internal_nets, R"(
294  Get all nets that have at least one source and one destination within the module, including its submodules. The result may contain nets that are also regarded as input or output nets.
295 
296  :returns: A set of internal nets.
297  :rtype: set[hal_py.Net]
298  )");
299 
300  py_module.def("is_input_net", &Module::is_input_net, py::arg("net"), R"(
301  Check whether the given net is an input of the module, i.e., whether the net is a global input to the netlist or has at least one source outside of the module.
302 
303  :param hal_py.Net net: The net.
304  :returns: ``True`` if the net is an input net, ``False`` otherwise.
305  :rtype: bool
306  )");
307 
308  py_module.def("is_output_net", &Module::is_output_net, py::arg("net"), R"(
309  Check whether the given net is an output of the module, i.e., whether the net is a global output to the netlist or has at least one destination outside of the module.
310 
311  :param hal_py.Net net: The net.
312  :returns: ``True`` if the net is an output net, ``False`` otherwise.
313  :rtype: bool
314  )");
315 
316  py_module.def("is_internal_net", &Module::is_internal_net, py::arg("net"), R"(
317  Check whether the given net is an internal net of the module, i.e. whether the net has at least one source and one destination within the module.
318 
319  :param hal_py.Net net: The net.
320  :returns: ``True`` if the net is an internal net, ``False`` otherwise.
321  :rtype: bool
322  )");
323 
324  py_module.def("assign_gate", &Module::assign_gate, py::arg("gate"), R"(
325  Assign a gate to the module.
326  The gate is removed from its previous module in the process.
327 
328  :param hal_py.Gate gate: The gate to assign.
329  :returns: ``True`` on success, ``False`` otherwise.
330  :rtype: bool
331  )");
332 
333  py_module.def("assign_gates", &Module::assign_gates, py::arg("gates"), R"(
334  Assign a list of gates to the module.
335  The gates are removed from their previous module in the process.
336 
337  :param list[hal_py.Gate] gates: The gates to assign.
338  :returns: ``True`` on success, ``False`` otherwise.
339  :rtype: bool
340  )");
341 
342  py_module.def("remove_gate", &Module::remove_gate, py::arg("gate"), R"(
343  Remove a gate from the module.
344  Automatically moves the gate to the top module of the netlist.
345 
346  :param hal_py.Gate gate: The gate to remove.
347  :returns: ``True`` on success, ``False`` otherwise.
348  :rtype: bool
349  )");
350 
351  py_module.def("remove_gates", &Module::remove_gates, py::arg("gates"), R"(
352  Remove a list of gates from the module.
353  Automatically moves the gates to the top module of the netlist.
354 
355  :param list[hal_py.Gate] gates: The gates to remove.
356  :returns: ``True`` on success, ``False`` otherwise.
357  :rtype: bool
358  )");
359 
360  py_module.def("contains_gate", &Module::contains_gate, py::arg("gate"), py::arg("recursive") = false, R"(
361  Check whether a gate is contained in the module.
362  If ``recursive`` is ``True``, gates in submodules are considered as well.
363 
364  :param hal_py.Gate gate: The gate to check for.
365  :param bool recursive: ``True`` to also consider gates in submodules, ``False`` otherwise.
366  :returns: ``True`` if the gate is contained in the module, ``False`` otherwise.
367  :rtype: bool
368  )");
369 
370  py_module.def("get_gate_by_id", &Module::get_gate_by_id, py::arg("id"), py::arg("recursive") = false, R"(
371  Get a gate specified by the given ID.
372  If ``recursive`` is ``True``, gates in submodules are considered as well.
373 
374  :param int id: The unique ID of the gate.
375  :param bool recursive: ``True`` to also consider gates in submodules, ``False`` otherwise.
376  :returns: The gate if found, None otherwise.
377  :rtype: hal_py.Gate or None
378  )");
379 
380  py_module.def_property_readonly("gates", py::overload_cast<>(&Module::get_gates, py::const_), R"(
381  The list of all gates contained within the module.
382 
383  :type: list[hal_py.Gate]
384  )");
385 
386  py_module.def("get_gates", py::overload_cast<>(&Module::get_gates, py::const_), R"(
387  Get all gates contained within the module.
388 
389  :returns: A list of gates.
390  :rtype: list[hal_py.Gate]
391  )");
392 
393  py_module.def("get_gates", py::overload_cast<const std::function<bool(Gate*)>&, bool>(&Module::get_gates, py::const_), py::arg("filter") = nullptr, py::arg("recursive") = false, R"(
394  Get all gates contained within the module.
395  The filter is evaluated on every candidate such that the result only contains those matching the specified condition.
396  If ``recursive`` is ``True``, gates in submodules are considered as well.
397 
398  :param lambda filter: Filter function to be evaluated on each gate.
399  :param bool recursive: ``True`` to also consider gates in submodules, ``False`` otherwise. Defaults to ``False``.
400  :returns: A list of gates.
401  :rtype: list[hal_py.Gate]
402  )");
403 
404  py_module.def("get_unique_pin_id", &Module::get_unique_pin_id, R"(
405  Get a spare pin ID.
406  The value of 0 is reserved and represents an invalid ID.
407 
408  :returns: The pin ID.
409  :rtype: int
410  )");
411 
412  py_module.def("get_unique_pin_group_id", &Module::get_unique_pin_group_id, R"(
413  Get a spare pin group ID.
414  The value of 0 is reserved and represents an invalid ID.
415 
416  :returns: The pin group ID.
417  :rtype: int
418  )");
419 
420  py_module.def(
421  "create_pin",
422  [](Module& self, const u32 id, const std::string& name, Net* net, PinType type = PinType::none, bool create_group = true, bool force_name = false) -> ModulePin* {
423  auto res = self.create_pin(id, name, net, type, create_group, force_name);
424  if (res.is_ok())
425  {
426  return res.get();
427  }
428  else
429  {
430  log_error("python_context", "error encountered while creating pin:\n{}", res.get_error().get());
431  return nullptr;
432  }
433  },
434  py::arg("id"),
435  py::arg("name"),
436  py::arg("net"),
437  py::arg("type") = PinType::none,
438  py::arg("create_group") = true,
439  py::arg("force_name") = false,
440  R"(
441  Manually assign a module pin to a net.
442  Checks whether the given direction matches the actual properties of the net, i.e., checks whether the net actually is an input and/or output to the module.
443  Hence, make sure to update the module nets beforehand using ``hal_py.Module.update_net``.
444  If ``create_group`` is set to ``False``, the pin will not be added to a pin group.
445 
446  WARNING: can only be used when automatic net checks have been disabled using ``hal_py.Netlist.enable_automatic_net_checks``.
447 
448  :param int id: The ID of the pin.
449  :param str name: The name of the pin.
450  :param hal_py.Net net: The net that the pin is being assigned to.
451  :param hal_py.PinType type: The type of the pin. Defaults to ``hal_py.PinType.none``.
452  :param bool create_group: Set ``True`` to automatically create a pin group and assign the pin, ``False`` otherwise. Defaults to ``True``.
453  :param bool force_name: Set ``True`` to enforce the name, ``False`` otherwise. If a pin with the same name already exists, the existing pin will be renamed. Defaults to ``False``.
454  :returns: The module pin on success, ``None`` otherwise.
455  :rtype: hal_py.ModulePin or None
456  )");
457 
458  py_module.def(
459  "create_pin",
460  [](Module& self, const std::string& name, Net* net, PinType type = PinType::none, bool create_group = true, bool force_name = false) -> ModulePin* {
461  auto res = self.create_pin(name, net, type, create_group, force_name);
462  if (res.is_ok())
463  {
464  return res.get();
465  }
466  else
467  {
468  log_error("python_context", "error encountered while creating pin:\n{}", res.get_error().get());
469  return nullptr;
470  }
471  },
472  py::arg("name"),
473  py::arg("net"),
474  py::arg("type") = PinType::none,
475  py::arg("create_group") = true,
476  py::arg("force_name") = false,
477  R"(
478  Manually assign a module pin to a net.
479  The ID of the pin is set automatically.
480  Checks whether the given direction matches the actual properties of the net, i.e., checks whether the net actually is an input and/or output to the module.
481  Hence, make sure to update the module nets beforehand using ``hal_py.Module.update_net``.
482  If ``create_group`` is set to ``False``, the pin will not be added to a pin group.
483 
484  WARNING: can only be used when automatic net checks have been disabled using ``hal_py.Netlist.enable_automatic_net_checks``.
485 
486  :param str name: The name of the pin.
487  :param hal_py.Net net: The net that the pin is being assigned to.
488  :param hal_py.PinType type: The type of the pin. Defaults to ``hal_py.PinType.none``.
489  :param bool create_group: Set ``True`` to automatically create a pin group and assign the pin, ``False`` otherwise. Defaults to ``True``.
490  :param bool force_name: Set ``True`` to enforce the name, ``False`` otherwise. If a pin with the same name already exists, the existing pin will be renamed. Defaults to ``False``.
491  :returns: The module pin on success, ``None`` otherwise.
492  :rtype: hal_py.ModulePin or None
493  )");
494 
495  py_module.def_property_readonly("pins", &Module::get_pins, R"(
496  The (ordered) pins of the module.
497 
498  :type: list[hal_py.ModulePin]
499  )");
500 
501  py_module.def("get_pins", &Module::get_pins, py::arg("filter") = nullptr, R"(
502  Get the (ordered) pins of the module.
503  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
504 
505  :param lambda filter: An optional filter.
506  :returns: A list of pins.
507  :rtype: list[hal_py.ModulePin]
508  )");
509 
510  py_module.def_property_readonly(
511  "pin_names",
512  [](const Module& self) -> std::vector<std::string> { return self.get_pin_names(); },
513  R"(
514  An ordered list of the names of all pins of the module.
515 
516  :type: list[str]
517  )");
518 
519  py_module.def("get_pin_names", &Module::get_pin_names, py::arg("filter") = nullptr, R"(
520  Get an ordered list of the names of all pins of the module.
521  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
522 
523  :returns: A list of input pin names of the module.
524  :param lambda filter: An optional filter.
525  :returns: An ordered list of pins.
526  :rtype: list[str]
527  )");
528 
529  py_module.def_property_readonly("input_pins", &Module::get_input_pins, R"(
530  An ordered list of all input pins of the module (including inout pins).
531 
532  :type: list[hal_py.ModulePin]
533  )");
534 
535  py_module.def("get_input_pins", &Module::get_input_pins, R"(
536  Get an ordered list of all input pins of the module (including inout pins).
537 
538  :returns: An ordered list of input pins.
539  :rtype: list[hal_py.ModulePin]
540  )");
541 
542  py_module.def_property_readonly("input_pin_names", &Module::get_input_pin_names, R"(
543  An ordered list of the names of all input pins of the module (including inout pins).
544 
545  :type: list[str]
546  )");
547 
548  py_module.def("get_input_pin_names", &Module::get_input_pin_names, R"(
549  Get an ordered list of the names of all input pins of the module (including inout pins).
550 
551  :returns: An ordered list of input pin names.
552  :rtype: list[str]
553  )");
554 
555  py_module.def_property_readonly("output_pins", &Module::get_output_pins, R"(
556  An ordered list of all output pins of the module (including inout pins).
557 
558  :type: list[hal_py.ModulePin]
559  )");
560 
561  py_module.def("get_output_pins", &Module::get_output_pins, R"(
562  Get an ordered list of all output pins of the module (including inout pins).
563 
564  :returns: An ordered list of output pins.
565  :rtype: list[hal_py.ModulePin]
566  )");
567 
568  py_module.def_property_readonly("output_pin_names", &Module::get_output_pin_names, R"(
569  An ordered list of the names of all output pins of the module (including inout pins).
570 
571  :type: list[str]
572  )");
573 
574  py_module.def("get_output_pin_names", &Module::get_output_pin_names, R"(
575  Get an ordered list of the names of all output pins of the module (including inout pins).
576 
577  :returns: An ordered list of output pin names.
578  :rtype: list[str]
579  )");
580 
581  py_module.def_property_readonly("pin_groups", &Module::get_pin_groups, R"(
582  All pin_groups of the module.
583 
584  :type: list[hal_py.ModulePinGroup]
585  )");
586 
587  py_module.def("get_pin_groups", &Module::get_pin_groups, py::arg("filter") = nullptr, R"(
588  Get all pin groups of the module.
589  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
590 
591  :param lambda filter: An optional filter.
592  :returns: A list of pin groups.
593  :rtype: list[hal_py.ModulePinGroup]
594  )");
595 
596  py_module.def("get_pin_by_id", &Module::get_pin_by_id, py::arg("id"), R"(
597  Get the pin corresponding to the given ID.
598 
599  :param int id: The ID of the pin.
600  :returns: The pin on success, ``None`` otherwise.
601  :rtype: hal_py.ModulePin or None
602  )");
603 
604  py_module.def("get_pin_by_name", &Module::get_pin_by_name, py::arg("name"), R"(
605  Get the pin corresponding to the given name.
606 
607  :param str name: The name of the pin.
608  :returns: The pin on success, ``None`` otherwise.
609  :rtype: hal_py.ModulePin or None
610  )");
611 
612  py_module.def("get_pin_by_net", &Module::get_pin_by_net, py::arg("net"), R"(
613  Get the pin that passes through the specified net.
614 
615  :param hal_py.Net net: The net.
616  :returns: The pin on success, ``None`` otherwise.
617  :rtype: hal_py.ModulePin or None
618  )");
619 
620  py_module.def("get_pin_group_by_id", &Module::get_pin_group_by_id, py::arg("id"), R"(
621  Get the pin group corresponding to the given ID.
622 
623  :param int id: The ID of the pin group.
624  :returns: The pin group on success, ``None`` otherwise.
625  :rtype: hal_py.ModulePinGroup or None
626  )");
627 
628  py_module.def("get_pin_group_by_name", &Module::get_pin_group_by_name, py::arg("name"), R"(
629  Get the pin group corresponding to the given name.
630 
631  :param str name: The name of the pin group.
632  :returns: The pin group on success, ``None`` otherwise.
633  :rtype: hal_py.ModulePinGroup or None
634  )");
635 
636  py_module.def("set_pin_name", &Module::set_pin_name, py::arg("pin"), py::arg("new_name"), py::arg("force_name") = false, R"(
637  Set the name of the given pin.
638 
639  :param hal_py.ModulePin pin: The pin.
640  :param str new_name: The name to be assigned to the pin.
641  :param bool force_name: Set ``True`` to enforce the name, ``False`` otherwise. If a pin with the same name already exists, the existing pin will be renamed. Defaults to ``False``.
642  :returns: ``True`` on success, ``False`` otherwise.
643  :rtype: bool
644  )");
645 
646  py_module.def("set_pin_group_name", &Module::set_pin_group_name, py::arg("pin_group"), py::arg("new_name"), py::arg("force_name") = false, R"(
647  Set the name of the given pin group.
648 
649  :param hal_py.ModulePinGroup pin_group: The pin group.
650  :param str new_name: The name to be assigned to the pin group.
651  :param bool force_name: Set ``True`` to enforce the name, ``False`` otherwise. If a pin group with the same name already exists, the existing pin group will be renamed. Defaults to ``False``.
652  :returns: ``True`` on success, ``False`` otherwise.
653  :rtype: bool
654  )");
655 
656  py_module.def("set_pin_type", &Module::set_pin_type, py::arg("pin"), py::arg("new_type"), R"(
657  Set the type of the given pin.
658 
659  :param hal_py.ModulePin pin: The pin.
660  :param hal_py.PinType new_type: The type to be assigned to the pin.
661  :returns: ``True`` on success, ``False`` otherwise.
662  :rtype: bool
663  )");
664 
665  py_module.def("set_pin_group_type", &Module::set_pin_group_type, py::arg("pin_group"), py::arg("new_type"), R"(
666  Set the type of the given pin group.
667 
668  :param hal_py.ModulePinGroup pin_group: The pin group.
669  :param hal_py.PinType new_type: The type to be assigned to the pin group.
670  :returns: ``True`` on success, ``False`` otherwise.
671  :rtype: bool
672  )");
673 
674  py_module.def("set_pin_group_direction", &Module::set_pin_group_direction, py::arg("pin_group"), py::arg("new_direction"), R"(
675  Set the direction of the given pin group.
676 
677  :param hal_py.ModulePinGroup pin_group: The pin group.
678  :param hal_py.PinDirection new_direction: The direction to be assigned to the pin group.
679  :returns: ``True`` on success, ``False`` otherwise.
680  :rtype: bool
681  )");
682 
683  py_module.def(
684  "create_pin_group",
685  [](Module& self,
686  const u32 id,
687  const std::string& name,
688  const std::vector<ModulePin*> pins = {},
691  bool ascending = true,
692  u32 start_index = 0,
693  bool delete_empty_groups = true,
694  bool force_name = false) -> PinGroup<ModulePin>* {
695  auto res = self.create_pin_group(id, name, pins, direction, type, ascending, start_index, delete_empty_groups, force_name);
696  if (res.is_ok())
697  {
698  return res.get();
699  }
700  else
701  {
702  log_error("python_context", "error encountered while creating pin group:\n{}", res.get_error().get());
703  return nullptr;
704  }
705  },
706  py::arg("id"),
707  py::arg("name"),
708  py::arg("pins") = std::vector<ModulePin*>(),
709  py::arg("direction") = PinDirection::none,
710  py::arg("type") = PinType::none,
711  py::arg("ascending") = true,
712  py::arg("start_index") = 0,
713  py::arg("delete_empty_groups") = true,
714  py::arg("force_name") = false,
715  R"(
716  Create a new pin group with the given name.
717  All pins to be added to the pin group must have the same direction and type.
718 
719  :param int id: The ID of the pin group.
720  :param str name: The name of the pin group.
721  :param list[hal_py.ModulePin] pins: The pins to be assigned to the pin group. Defaults to an empty list.
722  :param hal_py.PinDirection direction: The direction of the pin group, if any. Defaults to ``hal_py.PinDirection.none``.
723  :param hal_py.PinType type: The type of the pin group, if any. Defaults to ``hal_py.PinType.none``.
724  :param bool ascending: Set ``True`` for ascending pin order (from 0 to n-1), ``False`` otherwise (from n-1 to 0). Defaults to ``True``.
725  :param int start_index: The start index of the pin group. Defaults to ``0``.
726  :param bool delete_empty_groups: Set ``True`` to delete groups that are empty after the pins have been assigned to the new group, ``False`` to keep empty groups. Defaults to ``True``.
727  :param bool force_name: Set ``True`` to enforce the name, ``False`` otherwise. If a pin group with the same name already exists, the existing pin group will be renamed. Defaults to ``False``.
728  :returns: The pin group on success, ``None`` otherwise.
729  :rtype: hal_py.ModulePinGroup or None
730  )");
731 
732  py_module.def(
733  "create_pin_group",
734  [](Module& self,
735  const std::string& name,
736  const std::vector<ModulePin*> pins = {},
739  bool ascending = true,
740  u32 start_index = 0,
741  bool delete_empty_groups = true,
742  bool force_name = false) -> PinGroup<ModulePin>* {
743  auto res = self.create_pin_group(name, pins, direction, type, ascending, start_index, delete_empty_groups, force_name);
744  if (res.is_ok())
745  {
746  return res.get();
747  }
748  else
749  {
750  log_error("python_context", "error encountered while creating pin group:\n{}", res.get_error().get());
751  return nullptr;
752  }
753  },
754  py::arg("name"),
755  py::arg("pins") = std::vector<ModulePin*>(),
756  py::arg("direction") = PinDirection::none,
757  py::arg("type") = PinType::none,
758  py::arg("ascending") = true,
759  py::arg("start_index") = 0,
760  py::arg("delete_empty_groups") = true,
761  py::arg("force_name") = false,
762  R"(
763  Create a new pin group with the given name.
764  All pins to be added to the pin group must have the same direction and type.
765 
766  :param str name: The name of the pin group.
767  :param list[hal_py.ModulePin] pins: The pins to be assigned to the pin group. Defaults to an empty list.
768  :param hal_py.PinDirection direction: The direction of the pin group, if any. Defaults to ``hal_py.PinDirection.none``.
769  :param hal_py.PinType type: The type of the pin group, if any. Defaults to ``hal_py.PinType.none``.
770  :param bool ascending: Set ``True`` for ascending pin order (from 0 to n-1), ``False`` otherwise (from n-1 to 0). Defaults to ``True``.
771  :param int start_index: The start index of the pin group. Defaults to ``0``.
772  :param bool delete_empty_groups: Set `True`` to delete groups that are empty after the pins have been assigned to the new group, ``False`` to keep empty groups. Defaults to ``True``.
773  :param bool force_name: Set ``True`` to enforce the name, ``False`` otherwise. If a pin group with the same name already exists, the existing pin group will be renamed. Defaults to ``False``.
774  :returns: The pin group on success, ``None`` otherwise.
775  :rtype: hal_py.ModulePinGroup or None
776  )");
777 
778  py_module.def(
779  "delete_pin_group",
780  [](Module& self, PinGroup<ModulePin>* pin_group) {
781  if (self.delete_pin_group(pin_group))
782  {
783  return true;
784  }
785  else
786  {
787  log_error("python_context", "error encountered while deleting pin group.");
788  return false;
789  }
790  },
791  py::arg("pin_group"),
792  R"(
793  Delete the given pin group.
794 
795  :param hal_py.ModulePinGroup pin_group: The pin group to be deleted.
796  :returns: ``True`` on success, ``False`` otherwise.
797  :rtype: bool
798  )");
799 
800  py_module.def(
801  "move_pin_group",
802  [](Module& self, PinGroup<ModulePin>* pin_group, u32 new_index) {
803  if (self.move_pin_group(pin_group, new_index))
804  {
805  return true;
806  }
807  else
808  {
809  log_error("python_context", "error encountered while moving pin group.");
810  return false;
811  }
812  },
813  py::arg("pin_group"),
814  py::arg("new_index"),
815  R"(
816  Move a pin group to another index within the module.
817  The indices of some other pin groups will be incremented or decremented to make room for the moved pin group to be inserted at the desired position.
818 
819  :param hal_py.ModulePinGroup pin_group: The pin group to be moved.
820  :param int new_index: The index to which the pin group is moved.
821  :returns: ``True`` on success, ``False`` otherwise.
822  :rtype: bool
823  )");
824 
825  py_module.def(
826  "assign_pin_to_group",
827  [](Module& self, PinGroup<ModulePin>* pin_group, ModulePin* pin, bool delete_empty_groups = true) {
828  if (self.assign_pin_to_group(pin_group, pin, delete_empty_groups))
829  {
830  return true;
831  }
832  else
833  {
834  log_error("python_context", "error encountered while assigning pin to pin group.");
835  return false;
836  }
837  },
838  py::arg("pin_group"),
839  py::arg("pin"),
840  py::arg("delete_empty_groups") = true,
841  R"(
842  Assign a pin to a pin group.
843 
844  :param hal_py.ModulePinGroup pin_group: The new pin group.
845  :param hal_py.ModulePin pin: The pin to be added.
846  :param bool delete_empty_groups: Set ``True`` to delete groups that are empty after the pin has been assigned to the new group, ``False`` to keep empty groups. Defaults to ``True``.
847  :returns: ``True`` on success, ``False`` otherwise.
848  :rtype: bool
849  )");
850 
851  py_module.def(
852  "move_pin_within_group",
853  [](Module& self, PinGroup<ModulePin>* pin_group, ModulePin* pin, u32 new_index) {
854  if (self.move_pin_within_group(pin_group, pin, new_index))
855  {
856  return true;
857  }
858  else
859  {
860  log_error("python_context", "error encountered while moving pin within pin group.");
861  return false;
862  }
863  },
864  py::arg("pin_group"),
865  py::arg("pin"),
866  py::arg("new_index"),
867  R"(
868  Move a pin to another index within the given pin group.
869  The indices of some other pins within the group will be incremented or decremented to make room for the moved pin to be inserted at the desired position.
870 
871  :param hal_py.ModulePinGroup pin_group: The pin group.
872  :param hal_py.ModulePin pin: The pin to be moved.
873  :param int new_index: The index to which the pin is moved.
874  :returns: ``True`` on success, ``False`` otherwise.
875  :rtype: bool
876  )");
877 
878  py_module.def(
879  "remove_pin_from_group",
880  [](Module& self, PinGroup<ModulePin>* pin_group, ModulePin* pin, bool delete_empty_groups = true) {
881  if (self.remove_pin_from_group(pin_group, pin, delete_empty_groups))
882  {
883  return true;
884  }
885  else
886  {
887  log_error("python_context", "error encountered while removing pin from pin group.");
888  return false;
889  }
890  },
891  py::arg("pin_group"),
892  py::arg("pin"),
893  py::arg("delete_empty_groups") = true,
894  R"(
895  Remove a pin from a pin group.
896  The pin will be moved to a new group that goes by the pin's name.
897 
898  :param hal_py.ModulePinGroup pin_group: The old pin group.
899  :param hal_py.ModulePin pin: The pin to be removed.
900  :param bool delete_empty_groups: Set ``True`` to delete the group of it is empty after the pin has been removed, ``False`` to keep the empty group. Defaults to ``True``.
901  :returns: ``True`` on success, ``False`` otherwise.
902  :rtype: bool
903  )");
904  }
905 } // namespace hal
Definition: gate.h:58
bool is_input_net(Net *net) const
Definition: module.cpp:557
void set_name(const std::string &name)
Definition: module.cpp:92
const std::unordered_set< Net * > & get_nets() const
Definition: module.cpp:505
void update_nets()
Definition: module.cpp:436
std::vector< std::string > get_pin_names(const std::function< bool(ModulePin *)> &filter=nullptr) const
Definition: module.cpp:901
PinGroup< ModulePin > * get_pin_group_by_name(const std::string &name) const
Definition: module.cpp:1053
Module * get_parent_module() const
Definition: module.cpp:125
bool is_parent_module_of(const Module *module, bool recursive=false) const
Definition: module.cpp:240
std::vector< ModulePin * > get_output_pins() const
Definition: module.cpp:948
bool set_parent_module(Module *new_parent)
Definition: module.cpp:170
bool remove_gate(Gate *gate)
Definition: module.cpp:334
std::vector< ModulePin * > get_pins(const std::function< bool(ModulePin *)> &filter=nullptr) const
Definition: module.cpp:873
std::vector< ModulePin * > get_input_pins() const
Definition: module.cpp:932
bool assign_gates(const std::vector< Gate * > &gates)
Definition: module.cpp:329
bool contains_net(Net *net, bool recursive=false) const
Definition: module.cpp:485
Gate * get_gate_by_id(const u32 id, bool recursive=false) const
Definition: module.cpp:372
const std::unordered_set< Net * > & get_internal_nets() const
Definition: module.cpp:552
ModulePin * get_pin_by_name(const std::string &name) const
Definition: module.cpp:1002
int get_submodule_depth() const
Definition: module.cpp:159
bool is_top_module() const
Definition: module.cpp:314
bool remove_gates(const std::vector< Gate * > &gates)
Definition: module.cpp:339
ModulePin * get_pin_by_id(const u32 id) const
Definition: module.cpp:985
bool set_pin_group_type(PinGroup< ModulePin > *pin_group, PinType new_type)
Definition: module.cpp:1203
bool set_pin_type(ModulePin *pin, PinType new_type)
Definition: module.cpp:1124
bool assign_gate(Gate *gate)
Definition: module.cpp:324
bool is_output_net(Net *net) const
Definition: module.cpp:567
const std::vector< Gate * > & get_gates() const
Definition: module.cpp:393
bool set_pin_name(ModulePin *pin, const std::string &new_name, bool force_name=false)
Definition: module.cpp:1070
std::string get_name() const
Definition: module.cpp:87
Grouping * get_grouping() const
Definition: module.cpp:120
const std::unordered_set< Net * > & get_input_nets() const
Definition: module.cpp:542
std::vector< std::string > get_input_pin_names() const
Definition: module.cpp:940
bool set_pin_group_direction(PinGroup< ModulePin > *pin_group, PinDirection new_direction)
Definition: module.cpp:1226
void set_type(const std::string &type)
Definition: module.cpp:111
u32 get_unique_pin_id()
Definition: module.cpp:763
bool contains_module(const Module *other, bool recursive=false) const
Definition: module.cpp:309
std::vector< Module * > get_parent_modules(const std::function< bool(Module *)> &filter=nullptr, bool recursive=true) const
Definition: module.cpp:130
Netlist * get_netlist() const
Definition: module.cpp:319
ModulePin * get_pin_by_net(Net *net) const
Definition: module.cpp:1019
bool set_pin_group_name(PinGroup< ModulePin > *pin_group, const std::string &new_name, bool force_name=false)
Definition: module.cpp:1147
std::vector< PinGroup< ModulePin > * > get_pin_groups(const std::function< bool(PinGroup< ModulePin > *)> &filter=nullptr) const
Definition: module.cpp:964
PinGroup< ModulePin > * get_pin_group_by_id(const u32 id) const
Definition: module.cpp:1036
ssize_t get_hash() const
Definition: module.cpp:77
std::vector< Module * > get_submodules(const std::function< bool(Module *)> &filter=nullptr, bool recursive=false) const
Definition: module.cpp:261
std::vector< std::string > get_output_pin_names() const
Definition: module.cpp:956
bool contains_gate(Gate *gate, bool recursive=false) const
Definition: module.cpp:352
std::string get_type() const
Definition: module.cpp:106
bool is_internal_net(Net *net) const
Definition: module.cpp:577
bool is_submodule_of(const Module *module, bool recursive=false) const
Definition: module.cpp:291
const std::unordered_set< Net * > & get_output_nets() const
Definition: module.cpp:547
u32 get_id() const
Definition: module.cpp:82
u32 get_unique_pin_group_id()
Definition: module.cpp:776
Definition: net.h:58
std::unique_ptr< T, py::nodelete > RawPtrWrapper
void module_init(py::module &m)
Definition: module.cpp:5
#define log_error(channel,...)
Definition: log.h:78
const Module * module(const Gate *g, const NodeBoxes &boxes)
PinDirection
Definition: pin_direction.h:36
PinType
Definition: pin_type.h:36
quint32 u32
PinType type
std::vector< PinInformation > pins
Net * net
u32 start_index
bool ascending
PinDirection direction
std::string name