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