7 py::class_<Gate, DataContainer, RawPtrWrapper<Gate>> py_gate(m,
"Gate", R
"(Gate class containing information about a gate including its location, functions, and module.)");
9 py_gate.def(py::self == py::self, R"(
10 Check whether two gates are equal.
11 Does not check for connected nets or containing module.
13 :returns: ``True`` if both gates are equal, ``False`` otherwise.
17 py_gate.def(py::self != py::self, R"(
18 Check whether two gates are unequal.
19 Does not check for connected nets or containing module.
21 :returns: ``True`` if both gates are unequal, ``False`` otherwise.
26 Python requires hash for set and dict container.
33 The unique ID of the gate.
39 Get the unique ID of the gate.
41 :returns: The unique id.
46 The netlist this gate is associated with.
52 Get the netlist this gate is associated with.
54 :returns: The netlist.
55 :rtype: hal_py.Netlist
65 Get the name of the gate.
72 Set the name of the gate.
74 :param str name: The new name.
80 :type: hal_py.Gate_type
84 Get the type of the gate.
87 :rtype: hal_py.Gate_type
91 Checks whether the gate's location in the layout is available.
93 :returns: ``True`` if valid location data is available, ``False`` otherwise.
98 The x-coordinate of the physical location of the gate in the layout. Only positive values are valid, negative values will be regarded as no location assigned.
104 Get the physical location x-coordinate of the gate in the layout.
105 If no valid physical location x-coordinate is assigned, a negative value is returned.
107 :returns: The gate's x-coordinate.
112 Set the physical location x-coordinate of the gate in the layout.
113 Only positive values are valid, negative values will be regarded as no location assigned.
115 :param int x: The gate's x-coordinate.
119 The y-coordinate of the physical location of the gate in the layout.
120 Only positive values are valid, negative values will be regarded as no location assigned.
126 Get the physical location y-coordinate of the gate in the layout.
127 If no valid physical location y-coordinate is assigned, a negative value is returned.
129 :returns: The gate's y-coordinate.
134 Set the physical location y-coordinate of the gate in the layout.
135 Only positive values are valid, negative values will be regarded as no location assigned.
137 :param int y: The gate's y-coordinate.
141 The physical location of the gate in the layout.
142 Only positive values are valid, negative values will be regarded as no location assigned.
144 :type: tuple(int,int)
148 Get the physical location of the gate in the layout.
149 If no valid physical location coordinate is assigned, a negative value is returned for the respective coordinate.
151 :returns: A tuple <x-coordinate, y-coordinate>.
152 :rtype: tuple(int,int)
156 Set the physical location of the gate in the layout.
157 Only positive coordinates are valid, negative values will be regarded as no location assigned.
159 :param tuple(int,int) location: A tuple <x-coordinate, y-coordinate>.
162 py_gate.def_property_readonly("module", py::cpp_function(&
Gate::get_module, py::is_method(py_gate),
borrowed()), R
"(
163 The module in which contains this gate.
169 Get the module which contains this gate.
171 :returns: The module.
172 :rtype: hal_py.Module
175 py_gate.def_property_readonly("modules", py::cpp_function([](
Gate* g) {
return g->
get_modules(); }, py::is_method(py_gate),
borrowed()), R
"(
176 A list of all modules that contain this gate, either directly or as parent of another module.
178 :type: list[hal_py.Module]
182 Get all modules that contain this gate, either directly or as parent of another module.
183 If recursive is set to ``True``, indirect parent modules are also included. Otherwise, only the module containing the gate directly is returned.
184 The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
186 :param lambda filter: An optional filter.
187 :param bool recursive: Set ``True`` to include indirect parents as well, ``False`` otherwise.
188 :returns: A list of modules.
189 :rtype: list[hal_py.Module]
193 Gets the grouping in which this gate is contained.
194 If no grouping contains this gate, ``None`` is returned.
196 :returns: The grouping.
197 :rtype: hal_py.Grouping
200 py_gate.def("get_boolean_function",
204 Get the raw Boolean function specified by the given name without inlining or net substitution.
205 This name can for example be an ``output`` pin of the gate or any other user-defined function name.
206 For full control over inlining and net substitution use ``get_boolean_function`` with ``inlined`` and ``substitute_nets``.
208 :param str name: The name. If empty, the first output pin is used.
209 :returns: The Boolean function on success, an empty Boolean function otherwise.
210 :rtype: hal_py.BooleanFunction
214 "get_boolean_function",
215 [](
const Gate&
self,
const std::string&
name,
bool inlined,
bool substitute_nets) -> std::optional<BooleanFunction> {
216 auto res =
self.get_boolean_function(
name, inlined, substitute_nets);
223 log_error(
"python_context",
"{}", res.get_error().get());
229 py::arg(
"substitute_nets"),
231 Get the Boolean function specified by the given name, with full error reporting.
232 When ``inlined`` is ``True``, ``internal`` and ``output`` pin variables are recursively substituted with
233 their definitions, and any gate-instance parameter values are reduced.
234 When ``substitute_nets`` is ``True``, the remaining input pin variables are additionally substituted
235 with variable names derived from the fan-in nets using ``BooleanFunctionNetDecorator``.
236 ``substitute_nets`` requires ``inlined`` to be ``True``; passing ``substitute_nets=True`` with ``inlined=False`` returns ``None``.
238 :param str name: The name. Must not be empty.
239 :param bool inlined: Set ``True`` to inline ``internal`` and ``output`` pins and reduce parameter-conditional expressions.
240 :param bool substitute_nets: Set ``True`` to substitute input pin variables with fan-in net variables. Requires ``inlined=True`` and every input pin to have a connected net.
241 :returns: The Boolean function on success, ``None`` otherwise.
242 :rtype: hal_py.BooleanFunction or None
245 py_gate.def("get_boolean_function",
247 py::arg(
"pin") =
nullptr,
249 Get the raw Boolean function corresponding to the given ``output`` pin without inlining or net substitution.
250 If ``pin`` is ``None``, the Boolean function of the first ``output`` pin is returned.
251 For full control over inlining and net substitution use ``get_boolean_function`` with ``inlined`` and ``substitute_nets``.
253 :param hal_py.GatePin pin: The pin.
254 :returns: The Boolean function on success, an empty Boolean function otherwise.
255 :rtype: hal_py.BooleanFunction
259 "get_boolean_function",
260 [](
const Gate&
self,
const GatePin* pin,
bool inlined,
bool substitute_nets) -> std::optional<BooleanFunction> {
261 auto res =
self.get_boolean_function(pin, inlined, substitute_nets);
268 log_error(
"python_context",
"{}", res.get_error().get());
274 py::arg(
"substitute_nets"),
276 Get the Boolean function corresponding to the given ``output`` pin, with full error reporting.
277 When ``inlined`` is ``True``, ``internal`` and ``output`` pin variables are recursively substituted with
278 their definitions, and any gate-instance parameter values are reduced.
279 When ``substitute_nets`` is ``True``, the remaining input pin variables are additionally substituted
280 with variable names derived from the fan-in nets using ``BooleanFunctionNetDecorator``.
281 ``substitute_nets`` requires ``inlined`` to be ``True``; passing ``substitute_nets=True`` with ``inlined=False`` returns ``None``.
282 Returns ``None`` if ``pin`` is ``None``.
284 :param hal_py.GatePin pin: The output pin.
285 :param bool inlined: Set ``True`` to inline ``internal`` and ``output`` pins and reduce parameter-conditional expressions.
286 :param bool substitute_nets: Set ``True`` to substitute input pin variables with fan-in net variables. Requires ``inlined=True`` and every input pin to have a connected net.
287 :returns: The Boolean function on success, ``None`` otherwise.
288 :rtype: hal_py.BooleanFunction or None
291 py_gate.def("has_boolean_function", py::overload_cast<const std::string&>(&
Gate::has_boolean_function, py::const_), py::arg(
"name"), R
"(
292 Check whether the gate has a Boolean function with the given name, i.e., whether ``get_boolean_function`` finds one.
293 This name can for example be an output pin of the gate or any other user-defined function name.
294 Every LUT output pin has a Boolean function, even if the LUT is not configured.
296 :param str name: The name.
297 :returns: ``True`` if the gate has a Boolean function with that name, ``False`` otherwise.
301 py_gate.def("has_boolean_function", py::overload_cast<const GatePin*>(&
Gate::has_boolean_function, py::const_), py::arg(
"pin"), R
"(
302 Check whether the gate has a Boolean function for the given output pin, i.e., whether ``get_boolean_function`` finds one.
303 If pin is ``None``, the first output pin is checked.
304 Every LUT output pin has a Boolean function, even if the LUT is not configured.
306 :param hal_py.GatePin pin: The pin.
307 :returns: ``True`` if the gate has a Boolean function for the pin, ``False`` otherwise.
312 A dictionary from function name to raw Boolean function for all boolean functions associated with this gate.
314 :rtype: dict[str,hal_py.BooleanFunction]
317 py_gate.def("get_boolean_functions",
319 py::arg(
"only_custom_functions") =
false,
321 Get a dictionary from function name to raw Boolean function for all boolean functions associated with this gate.
322 For full control over inlining and net substitution use ``get_boolean_functions`` with ``inlined`` and ``substitute_nets``.
324 :param bool only_custom_functions: Set ``True`` to get only Boolean functions that are local to the gate, ``False`` otherwise.
325 :returns: A dict from function name to function on success, an empty dict otherwise.
326 :rtype: dict[str,hal_py.BooleanFunction]
330 "get_boolean_functions",
331 [](
const Gate&
self,
bool only_custom_functions,
bool inlined,
bool substitute_nets) -> std::optional<std::unordered_map<std::string, BooleanFunction>> {
332 auto res =
self.get_boolean_functions(only_custom_functions, inlined, substitute_nets);
339 log_error(
"python_context",
"{}", res.get_error().get());
343 py::arg(
"only_custom_functions"),
345 py::arg(
"substitute_nets"),
347 Get a dictionary from function name to Boolean function for all boolean functions associated with this gate.
348 When ``inlined`` is ``True``, ``internal`` and ``output`` pin variables are recursively substituted with
349 their definitions, and gate-instance parameter values are reduced.
350 When ``substitute_nets`` is ``True``, the remaining input pin variables are additionally substituted with
351 variable names derived from the fan-in nets. ``substitute_nets`` requires ``inlined`` to be ``True``.
352 Aborts on the first failure and returns ``None``.
354 :param bool only_custom_functions: If ``True``, returns only functions set via :func:`add_boolean_function`.
355 :param bool inlined: Set ``True`` to inline ``internal`` and ``output`` pins and reduce parameter-conditional expressions.
356 :param bool substitute_nets: Set ``True`` to substitute input pin variables with fan-in net variables. Requires ``inlined=True``.
357 :returns: A map from function name to function on success, ``None`` otherwise.
358 :rtype: dict[str,hal_py.BooleanFunction] or None
362 Add a Boolean function with the given name to the gate.
364 :param str name: The name.
365 :param hal_py.BooleanFunction func: The function.
366 :returns: ``True`` on success, ``False`` otherwise.
371 Mark this gate as a global vcc gate.
373 :returns: ``True`` on success, ``False`` otherwise.
378 Mark this gate as a global gnd gate.
380 :returns: ``True`` on success, ``False`` otherwise.
385 Unmark this gate as a global vcc gate.
387 :returns: ``True`` on success, ``False`` otherwise.
392 Unmark this gate as a global gnd gate.
394 :returns: ``True`` on success, ``False`` otherwise.
399 Checks whether this gate is a global vcc gate.
401 :returns: ``True`` if the gate is a global vcc gate, ``False`` otherwise.
406 Checks whether this gate is a global gnd gate.
408 :returns: ``True`` if the gate is a global gnd gate, ``False`` otherwise.
412 py_gate.def_property_readonly("fan_in_nets", py::cpp_function(py::overload_cast<>(&
Gate::get_fan_in_nets, py::const_), py::is_method(py_gate),
borrowed()), R
"(
413 A list of all fan-in nets of the gate, i.e., all nets that are connected to one of the input pins.
415 :type: list[hal_py.Net]
419 Get a list of all fan-in nets of the gate, i.e., all nets that are connected to one of the input pins.
421 :returns: A list of all fan-in nets.
422 :rtype: list[hal_py.Net]
426 Get a list of all fan-in nets of the gate, i.e., all nets that are connected to one of the input pins.
427 The filter is evaluated on every candidate such that the result only contains those matching the specified condition.
429 :param lambda filter: Filter function to be evaluated on each net.
430 :returns: A list of all fan-in nets.
431 :rtype: list[hal_py.Net]
434 py_gate.def("get_fan_in_net", py::overload_cast<const std::string&>(&
Gate::get_fan_in_net, py::const_), py::arg(
"pin_name"),
borrowed(), R
"(
435 Get the fan-in net corresponding to the input pin specified by name.
437 :param str pin_name: The input pin name.
438 :returns: The fan-in net on success, ``None`` otherwise.
439 :rtype: hal_py.Net or None
443 Get the fan-in net corresponding to the specified input pin.
445 :param hal_py.GatePin pin: The input pin.
446 :returns: The fan-in net on success, ``None`` otherwise.
447 :rtype: hal_py.Net or None
451 Check whether the given net is a fan-in of the gate.
453 :param hal_py.Net net: The net.
454 :returns: ``True`` if the net is a fan-in of the gate, ``False`` otherwise.
458 py_gate.def_property_readonly("fan_in_endpoints", py::cpp_function(py::overload_cast<>(&
Gate::get_fan_in_endpoints, py::const_), py::is_method(py_gate),
borrowed()), R
"(
459 A list of all fan-in endpoints of the gate, i.e., all endpoints associated with an input pin of the gate.
461 :type: list[hal_py.Endpoint]
465 Get a list of all fan-in endpoints of the gate, i.e., all endpoints associated with an input pin of the gate.
467 :returns: A list of all fan-in endpoints.
468 :rtype: list[hal_py.Endpoint]
472 Get a list of all fan-in endpoints of the gate, i.e., all endpoints associated with an input pin of the gate.
473 The filter is evaluated on every candidate such that the result only contains those matching the specified condition.
475 :param lambda filter: Filter function to be evaluated on each endpoint.
476 :returns: A list of all fan-in endpoints.
477 :rtype: list[hal_py.Endpoint]
481 Get the fan-in endpoint corresponding to the input pin specified by name.
483 :param str pin_name: The input pin name.
484 :returns: The endpoint on success, ``None`` otherwise.
485 :rtype: hal_py.Endpoint or None
489 Get the fan-in endpoint corresponding to the specified input pin.
491 :param hal_py.GatePin pin: The input pin.
492 :returns: The endpoint on success, ``None`` otherwise.
493 :rtype: hal_py.Endpoint or None
497 Get the fan-in endpoint connected to the specified input net.
499 :param hal_py.Net net: The input net.
500 :returns: The endpoint on success, ``None`` otherwise.
501 :rtype: hal_py.Endpoint or None
504 py_gate.def_property_readonly("fan_out_nets", py::cpp_function(py::overload_cast<>(&
Gate::get_fan_out_nets, py::const_), py::is_method(py_gate),
borrowed()), R
"(
505 A list of all fan-out nets of the gate, i.e., all nets that are connected to one of the output pins.
507 :type: list[hal_py.Net]
511 Get a list of all fan-out nets of the gate, i.e., all nets that are connected to one of the output pins.
513 :returns: A list of all fan-out nets.
514 :rtype: list[hal_py.Net]
518 Get a list of all fan-out nets of the gate, i.e., all nets that are connected to one of the output pins.
519 The filter is evaluated on every candidate such that the result only contains those matching the specified condition.
521 :param lambda filter: Filter function to be evaluated on each net.
522 :returns: A list of all fan-out nets.
523 :rtype: list[hal_py.Net]
526 py_gate.def("get_fan_out_net", py::overload_cast<const std::string&>(&
Gate::get_fan_out_net, py::const_), py::arg(
"pin_name"),
borrowed(), R
"(
527 Get the fan-out net corresponding to the output pin specified by name.
529 :param str pin_name: The output pin name.
530 :returns: The fan-out net on success, ``None`` otherwise.
531 :rtype: hal_py.Net or None
535 Get the fan-out net corresponding to the specified output pin.
537 :param hal_py.GatePin pin: The output pin.
538 :returns: The fan-out net on success, ``None`` otherwise.
539 :rtype: hal_py.Net or None
543 Check whether the given net is a fan-out of the gate.
545 :param hal_py.Net net: The net.
546 :returns: ``True`` if the net is a fan-out of the gate, ``False`` otherwise.
550 py_gate.def_property_readonly("fan_out_endpoints", py::cpp_function(py::overload_cast<>(&
Gate::get_fan_out_endpoints, py::const_), py::is_method(py_gate),
borrowed()), R
"(
551 A list of all fan-out endpoints of the gate, i.e., all endpoints associated with an output pin of the gate.
553 :type: list[hal_py.Endpoint]
557 Get a list of all fan-out endpoints of the gate, i.e., all endpoints associated with an output pin of the gate.
559 :returns: A list of all fan-out endpoints.
560 :rtype: list[hal_py.Endpoint]
564 Get a list of all fan-out endpoints of the gate, i.e., all endpoints associated with an output pin of the gate.
565 The filter is evaluated on every candidate such that the result only contains those matching the specified condition.
567 :param lambda filter: Filter function to be evaluated on each endpoint.
568 :returns: A list of all fan-out endpoints.
569 :rtype: list[hal_py.Endpoint]
573 Get the fan-out endpoint corresponding to the output pin specified by name.
575 :param str pin_name: The output pin name.
576 :returns: The endpoint on success, ``None`` otherwise.
577 :rtype: hal_py.Endpoint or None
581 Get the fan-out endpoint corresponding to the specified output pin.
583 :param hal_py.GatePin pin: The output pin.
584 :returns: The endpoint on success, ``None`` otherwise.
585 :rtype: hal_py.Endpoint or None
589 Get the fan-out endpoint connected to the specified output net.
591 :param hal_py.Net net: The output net.
592 :returns: The endpoint on success, ``None`` otherwise.
593 :rtype: hal_py.Endpoint or None
597 A list of all unique predecessor gates of the gate.
599 :type: list[hal_py.Gate]
603 Get a list of all unique predecessor gates of the gate.
604 The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
606 :param lambda filter: An optional filter being evaluated on the gate's input pin as well as the predecessor endpoint.
607 :returns: A list of unique predecessor gates.
608 :rtype: list[hal_py.Gate]
611 py_gate.def_property_readonly("predecessors", py::cpp_function([](
Gate* g) {
return g->
get_predecessors(); }, py::is_method(py_gate),
borrowed()), R
"(
612 A list of all direct predecessor endpoints of the gate, i.e., all predecessor endpoints that are connected to an input pin of the gate.
614 :type: list[hal_py.Endpoint]
618 Get a list of all direct predecessor endpoints of the gate, i.e., all predecessor endpoints that are connected to an input pin of the gate.
619 The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
621 :param lambda filter: An optional filter being evaluated on the gate's input pin as well as the predecessor endpoint.
622 :returns: A list of predecessor endpoints.
623 :rtype: list[hal_py.Endpoint]
626 py_gate.def("get_predecessor", py::overload_cast<const std::string&>(&
Gate::get_predecessor, py::const_), py::arg(
"pin_name"),
borrowed(), R
"(
627 Get a single direct predecessor endpoint that is connected to the input pin specified by name.
628 Fails if there are no or more than one predecessors.
630 :param str pin_name: The input pin name.
631 :returns: The predecessor endpoint on success, ``None`` otherwise.
632 :rtype: hal_py.Endpoint or None
636 Get a single direct predecessor endpoint that is connected to the specified input pin.
637 Fails if there are no or more than one predecessors.
639 :param hal_py.GatePin pin: The input pin.
640 :returns: The predecessor endpoint on success, ``None`` otherwise.
641 :rtype: hal_py.Endpoint or None
645 A list of all unique successor gates of the gate.
647 :type: list[hal_py.Gate]
651 Get a list of all unique successor gates of the gate.
652 The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
654 :param lambda filter: An optional filter being evaluated on the gate's output pin as well as the successor endpoint.
655 :returns: A list of unique successor gates.
656 :rtype: list[hal_py.Gate]
659 py_gate.def_property_readonly("successors", py::cpp_function([](
Gate* g) {
return g->
get_successors(); }, py::is_method(py_gate),
borrowed()), R
"(
660 A list of all direct successor endpoints of the gate, i.e., all successor endpoints that are connected to an output pin of the gate.
662 :type: list[hal_py.Endpoint]
666 Get a list of all direct successor endpoints of the gate, i.e., all successor endpoints that are connected to an output pin of the gate.
667 The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
669 :param lambda filter: An optional filter being evaluated on the gate's output pin as well as the successor endpoint.
670 :returns: A list of successor endpoints.
671 :rtype: list[hal_py.Endpoint]
674 py_gate.def("get_successor", py::overload_cast<const std::string&>(&
Gate::get_successor, py::const_), py::arg(
"pin_name"),
borrowed(), R
"(
675 Get a single direct successor endpoint that is connected to the output pin specified by name.
676 Fails if there are no or more than one successors.
678 :param str pin_name: The output pin name.
679 :returns: The successor endpoint on success, ``None`` otherwise.
680 :rtype: hal_py.Endpoint or None
684 Get a single direct successor endpoint that is connected to the output pin specified by name.
685 Fails if there are no or more than one successors.
687 :param hal_py.GatePin pin: The output pin.
688 :returns: The successor endpoint on success, ``None`` otherwise.
689 :rtype: hal_py.Endpoint or None
Net * get_fan_in_net(const std::string &pin_name) const
void set_location_y(i32 y)
i32 get_location_x() const
bool add_boolean_function(const std::string &name, const BooleanFunction &func)
BooleanFunction get_boolean_function(const std::string &name) const
bool is_fan_out_net(const Net *net) const
const std::vector< Net * > & get_fan_in_nets() const
bool is_fan_in_net(const Net *net) const
std::vector< Gate * > get_unique_successors(const std::function< bool(const GatePin *pin, Endpoint *ep)> &filter=nullptr) const
const std::vector< Endpoint * > & get_fan_out_endpoints() const
i32 get_location_y() const
GateType * get_type() const
std::pair< i32, i32 > get_location() const
std::vector< Endpoint * > get_predecessors(const std::function< bool(const GatePin *pin, Endpoint *ep)> &filter=nullptr) const
Net * get_fan_out_net(const std::string &pin_name) const
std::vector< Gate * > get_unique_predecessors(const std::function< bool(const GatePin *pin, Endpoint *ep)> &filter=nullptr) const
std::vector< Endpoint * > get_successors(const std::function< bool(const GatePin *pin, Endpoint *ep)> &filter=nullptr) const
const std::string & get_name() const
Grouping * get_grouping() const
Endpoint * get_predecessor(const std::string &pin_name) const
bool has_location() const
Endpoint * get_fan_in_endpoint(const std::string &pin_name) const
void set_location(const std::pair< i32, i32 > &location)
Module * get_module() const
Endpoint * get_successor(const std::string &pin_name) const
bool has_boolean_function(const std::string &name) const
void set_name(const std::string &name)
std::vector< Module * > get_modules(const std::function< bool(Module *)> &filter=nullptr, bool recursive=true) const
const std::vector< Net * > & get_fan_out_nets() const
const std::vector< Endpoint * > & get_fan_in_endpoints() const
void set_location_x(i32 x)
Netlist * get_netlist() const
Endpoint * get_fan_out_endpoint(const std::string &pin_name) const
std::unordered_map< std::string, BooleanFunction > get_boolean_functions(bool only_custom_functions=false) const
std::unique_ptr< T, py::nodelete > RawPtrWrapper
void gate_init(py::module &m)
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)