HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
net.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
6  {
7  py::class_<Net, DataContainer, RawPtrWrapper<Net>> py_net(m, "Net", R"(Net class containing information about a net including its source and destination.)");
8 
9  py_net.def(py::self == py::self, R"(
10  Check whether two nets are equal.
11 
12  :returns: ``True`` if both nets are equal, ``False`` otherwise.
13  :rtype: bool
14  )");
15 
16  py_net.def(py::self != py::self, R"(
17  Check whether two nets are unequal.
18 
19  :returns: ``True`` if both nets are unequal, ``False`` otherwise.
20  :rtype: bool
21  )");
22 
23  py_net.def("__hash__", &Net::get_hash, R"(
24  Python requires hash for set and dict container.
25 
26  :returns: The hash.
27  :rtype: Py_hash_t
28  )");
29 
30  py_net.def_property_readonly("id", &Net::get_id, R"(
31  The unique id of the net.
32 
33  :type: int
34  )");
35 
36  py_net.def("get_id", &Net::get_id, R"(
37  Get the unique id of the net.
38 
39  :returns: The unique id.
40  :rtype: int
41  )");
42 
43  py_net.def_property_readonly("netlist", [](Net* net) { return RawPtrWrapper<Netlist>(net->get_netlist()); }, R"(
44  The netlist this net is associated with.
45 
46  :type: hal_py.Netlist
47  )");
48 
49  py_net.def("get_netlist", [](Net* net) { return RawPtrWrapper<Netlist>(net->get_netlist()); }, R"(
50  Get the netlist this net is associated with.
51 
52  :returns: The netlist.
53  :rtype: hal_py.Netlist
54  )");
55 
56  py_net.def_property("name", &Net::get_name, &Net::set_name, R"(
57  The name of the net.
58 
59  :type: str
60  )");
61 
62  py_net.def("get_name", &Net::get_name, R"(
63  Get the name of the net.
64 
65  :returns: The name.
66  :rtype: str
67  )");
68 
69  py_net.def("set_name", &Net::set_name, py::arg("name"), R"(
70  Set the name of the net.
71 
72  :param str name: The new name.
73  )");
74 
75  py_net.def("get_grouping", &Net::get_grouping, R"(
76  Get the grouping in which this net is contained.
77  If no grouping contains this gate, ``None`` is returned.
78 
79  :returns: The grouping.
80  :rtype: hal_py.Grouping
81  )");
82 
83  py_net.def("add_source", py::overload_cast<Gate*, const std::string&>(&Net::add_source), py::arg("gate"), py::arg("pin_name"), R"(
84  Add a source endpoint to the net.
85  The endpoint is specified by a tuple of a gate and the name of an output pin of that gate.
86 
87  :param hal_py.Gate gate: The gate.
88  :param str pin_name: The name of an output pin of the gate.
89  :returns: The endpoint on success, ``None`` otherwise.
90  :rtype: hal_py.Endpoint or None
91  )");
92 
93  py_net.def("add_source", py::overload_cast<Gate*, GatePin*>(&Net::add_source), py::arg("gate"), py::arg("pin"), R"(
94  Add a source endpoint to the net.
95  The endpoint is specified by a tuple of a gate and an output pin of that gate.
96 
97  :param hal_py.Gate gate: The gate.
98  :param hal_py.GatePin pin: The output pin of the gate.
99  :returns: The endpoint on success, ``None`` otherwise.
100  :rtype: hal_py.Endpoint or None
101  )");
102 
103  py_net.def("remove_source", py::overload_cast<Gate*, const std::string&>(&Net::remove_source), py::arg("gate"), py::arg("pin_name"), R"(
104  Remove a source endpoint from the net.
105  The endpoint is specified by a tuple of a gate and the name of an output pin of that gate.
106 
107  :param hal_py.Gate gate: The gate.
108  :param str pin_name: The name of an output pin of the gate.
109  :returns: ``True`` on success, ``False`` otherwise.
110  :rtype: bool
111  )");
112 
113  py_net.def("remove_source", py::overload_cast<Gate*, const GatePin*>(&Net::remove_source), py::arg("gate"), py::arg("pin"), R"(
114  Remove a source endpoint from the net.
115  The endpoint is specified by a tuple of a gate and an output pin of that gate.
116 
117  :param hal_py.Gate gate: The gate.
118  :param hal_py.GatePin pin: The output pin of the gate.
119  :returns: ``True`` on success, ``False`` otherwise.
120  :rtype: bool
121  )");
122 
123  py_net.def("remove_source", py::overload_cast<Endpoint*>(&Net::remove_source), py::arg("ep"), R"(
124  Remove a source endpoint from the net.
125 
126  :param hal_py.Endpoint ep: The endpoint.
127  :returns: ``True`` on success, ``False`` otherwise.
128  :rtype: bool
129  )");
130 
131  py_net.def("is_a_source", py::overload_cast<const Gate*>(&Net::is_a_source, py::const_), py::arg("gate"), R"(
132  Check whether a gate is a source of the net independent of the pin.
133 
134  :param hal_py.Gate gate: The gate.
135  :returns: ``True`` if the gate is a source of the net, ``False`` otherwise.
136  :rtype: bool
137  )");
138 
139  py_net.def("is_a_source", py::overload_cast<const Gate*, const std::string&>(&Net::is_a_source, py::const_), py::arg("gate"), py::arg("pin_name"), R"(
140  Check whether an endpoint is a source of the net.
141  The endpoint is specified by a tuple of a gate and the name of an output pin of that gate.
142 
143  :param hal_py.Gate gate: The gate.
144  :param str pin_name: The name of an output pin of the gate.
145  :returns: ``True`` if the endpoint is a source of the net, ``False`` otherwise.
146  :rtype: bool
147  )");
148 
149  py_net.def("is_a_source", py::overload_cast<const Gate*, const GatePin*>(&Net::is_a_source, py::const_), py::arg("gate"), py::arg("pin"), R"(
150  Check whether an endpoint is a source of the net.
151  The endpoint is specified by a tuple of a gate and the name of an output pin of that gate.
152 
153  :param hal_py.Gate gate: The gate.
154  :param hal_py.GatePin pin: The output pin of the gate.
155  :returns: ``True`` if the endpoint is a source of the net, ``False`` otherwise.
156  :rtype: bool
157  )");
158 
159  py_net.def("is_a_source", py::overload_cast<const Endpoint*>(&Net::is_a_source, py::const_), py::arg("ep"), R"(
160  Check whether an endpoint is a source of the net.
161 
162  :param hal_py.Endpoint ep: The endpoint.
163  :returns: ``True`` if the endpoint is a source of the net, ``False`` otherwise.
164  :rtype: bool
165  )");
166 
167  py_net.def_property_readonly("num_of_sources", [](Net* n) { return n->get_num_of_sources(); }, R"(
168  The number of sources of the net.
169 
170  :type: int
171  )");
172 
173  py_net.def("get_num_of_sources", &Net::get_num_of_sources, py::arg("filter") = nullptr, R"(
174  Get the number of sources of the net.
175  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
176 
177  :param lambda filter: An optional filter.
178  :returns: The number of sources.
179  :rtype: int
180  )");
181 
182  py_net.def_property_readonly("sources", [](Net* n) { return n->get_sources(); }, R"(
183  A list of sources of the net.
184 
185  :type: list[hal_py.Endpoint]
186  )");
187 
188  py_net.def("get_sources", &Net::get_sources, py::arg("filter") = nullptr, R"(
189  Get a list of sources of the net.
190  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
191 
192  :param lambda filter: An optional filter.
193  :returns: A list of source endpoints.
194  :rtype: list[hal_py.Endpoint]
195  )");
196 
197  py_net.def("add_destination", py::overload_cast<Gate*, const std::string&>(&Net::add_destination), py::arg("gate"), py::arg("pin_name"), R"(
198  Add a destination endpoint to the net.
199  The endpoint is specified by a tuple of a gate and the name of an input pin of that gate.
200 
201  :param hal_py.Gate gate: The gate.
202  :param str pin_name: The name of an input pin of the gate.
203  :returns: The endpoint on success, ``None`` otherwise.
204  :rtype: hal_py.Endpoint or None
205  )");
206 
207  py_net.def("add_destination", py::overload_cast<Gate*, GatePin*>(&Net::add_destination), py::arg("gate"), py::arg("pin"), R"(
208  Add a destination endpoint to the net.
209  The endpoint is specified by a tuple of a gate and an input pin of that gate.
210 
211  :param hal_py.Gate gate: The gate.
212  :param hal_py.GatePin pin: The input pin of the gate.
213  :returns: The endpoint on success, ``None`` otherwise.
214  :rtype: hal_py.Endpoint or None
215  )");
216 
217  py_net.def("remove_destination", py::overload_cast<Gate*, const std::string&>(&Net::remove_destination), py::arg("gate"), py::arg("pin_name"), R"(
218  Remove a destination endpoint from the net.
219  The endpoint is specified by a tuple of a gate and the name of an input pin of that gate.
220 
221  :param hal_py.Gate gate: The gate.
222  :param str pin_name: The name of an input pin of the gate.
223  :returns: ``True`` on success, ``False`` otherwise.
224  :rtype: bool
225  )");
226 
227  py_net.def("remove_destination", py::overload_cast<Gate*, const GatePin*>(&Net::remove_destination), py::arg("gate"), py::arg("pin"), R"(
228  Remove a destination endpoint from the net.
229  The endpoint is specified by a tuple of a gate and the name of an input pin of that gate.
230 
231  :param hal_py.Gate gate: The gate.
232  :param hal_py.GatePin pin: The input pin of the gate.
233  :returns: ``True`` on success, ``False`` otherwise.
234  :rtype: bool
235  )");
236 
237  py_net.def("remove_destination", py::overload_cast<Endpoint*>(&Net::remove_destination), py::arg("ep"), R"(
238  Remove a destination endpoint from the net.
239 
240  :param hal_py.Endpoint ep: The endpoint.
241  :returns: ``True`` on success, ``False`` otherwise.
242  :rtype: bool
243  )");
244 
245  py_net.def("is_a_destination", py::overload_cast<const Gate*>(&Net::is_a_destination, py::const_), py::arg("gate"), R"(
246  Check whether a gate is a destination of the net independent of the pin.
247 
248  :param hal_py.Gate gate: The gate.
249  :returns: ``True`` if the gate is a destination of the net, ``False`` otherwise.
250  :rtype: bool
251  )");
252 
253  py_net.def("is_a_destination", py::overload_cast<const Gate*, const std::string&>(&Net::is_a_destination, py::const_), py::arg("gate"), py::arg("pin_name"), R"(
254  Check whether an endpoint is a destination of the net.
255  The endpoint is specified by a tuple of a gate and the name of an input pin of that gate.
256 
257  :param hal_py.Gate gate: The gate.
258  :param str pin_name: The name of an input pin of the gate.
259  :returns: ``True`` if the endpoint is a destination of the net, ``False`` otherwise.
260  :rtype: bool
261  )");
262 
263  py_net.def("is_a_destination", py::overload_cast<const Gate*, const GatePin*>(&Net::is_a_destination, py::const_), py::arg("gate"), py::arg("pin"), R"(
264  Check whether an endpoint is a destination of the net.
265  The endpoint is specified by a tuple of a gate and an input pin of that gate.
266 
267  :param hal_py.Gate gate: The gate.
268  :param hal_py.GatePin pin: The input pin of the gate.
269  :returns: ``True`` if the endpoint is a destination of the net, ``False`` otherwise.
270  :rtype: bool
271  )");
272 
273  py_net.def("is_a_destination", py::overload_cast<const Endpoint*>(&Net::is_a_destination, py::const_), py::arg("ep"), R"(
274  Check whether an endpoint is a destination of the net.
275 
276  :param hal_py.Endpoint ep: The endpoint.
277  :returns: ``True`` if the endpoint is a destination of the net, ``False`` otherwise.
278  :rtype: bool
279  )");
280 
281  py_net.def_property_readonly("num_of_destinations", [](Net* n) { return n->get_num_of_destinations(); }, R"(
282  The number of destinations of the net.
283 
284  :type: int
285  )");
286 
287  py_net.def("get_num_of_destinations", &Net::get_num_of_destinations, py::arg("filter") = nullptr, R"(
288  Get the number of destinations of the net.
289  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
290 
291  :param filter: An optional filter.
292  :returns: The number of destinations.
293  :rtype: int
294  )");
295 
296  py_net.def_property_readonly("destinations", [](Net* n) { return n->get_destinations(); }, R"(
297  A list of destinations of the net.
298 
299  :type: list[hal_py.Endpoint]
300  )");
301 
302  py_net.def("get_destinations", &Net::get_destinations, py::arg("filter") = nullptr, R"(
303  Get a vector of destinations of the net.
304  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
305 
306  :param filter: An optional filter.
307  :returns: A list of destination endpoints.
308  :rtype: list[hal_py.Endpoint]
309  )");
310 
311  py_net.def("is_unrouted", &Net::is_unrouted, R"(
312  Check whether the net is unrouted, i.e., it has no source or no destination.
313 
314  :returns: ``True`` if the net is unrouted, ``False`` otherwise.
315  :rtype: bool
316  )");
317 
318  py_net.def("is_gnd_net", &Net::is_gnd_net, R"(
319  Check whether the net is connected to GND.
320 
321  :returns: ``True`` if the net is connected to GND, ``False`` otherwise.
322  :rtype: bool
323  )");
324 
325  py_net.def("is_vcc_net", &Net::is_vcc_net, R"(
326  Check whether the net is connected to VCC.
327 
328  :returns: ``True`` if the net is connected to VCC, ``False`` otherwise.
329  :rtype: bool
330  )");
331 
332  py_net.def("mark_global_input_net", &Net::mark_global_input_net, R"(
333  Mark this net as a global input net.
334 
335  :returns: ``True`` on success, ``False`` otherwise.
336  :rtype: bool
337  )");
338 
339  py_net.def("mark_global_output_net", &Net::mark_global_output_net, R"(
340  Mark this net as a global output net.
341 
342  :returns: ``True`` on success, ``False`` otherwise.
343  :rtype: bool
344  )");
345 
346  py_net.def("unmark_global_input_net", &Net::unmark_global_input_net, R"(
347  Unmark this net as a global input net.
348 
349  :returns: ``True`` on success, ``False`` otherwise.
350  :rtype: bool
351  )");
352 
353  py_net.def("unmark_global_output_net", &Net::unmark_global_output_net, R"(
354  Unmark this net as a global output net.
355 
356  :returns: ``True`` on success, ``False`` otherwise.
357  :rtype: bool
358  )");
359 
360  py_net.def("is_global_input_net", &Net::is_global_input_net, R"(
361  Checks whether this net is a global input net.
362 
363  :returns: ``True`` if the net is a global input net, ``False`` otherwise.
364  :rtype: bool
365  )");
366 
367  py_net.def("is_global_output_net", &Net::is_global_output_net, R"(
368  Checks whether this net is a global output net.
369 
370  :returns: ``True`` if the net is a global output net, ``False`` otherwise.
371  :rtype: bool
372  )");
373  }
374 } // namespace hal
Definition: net.h:58
u32 get_num_of_sources(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
Definition: net.cpp:258
u32 get_id() const
Definition: net.cpp:88
Netlist * get_netlist() const
Definition: net.cpp:93
Endpoint * add_destination(Gate *gate, const std::string &pin_name)
Definition: net.cpp:300
bool remove_source(Gate *gate, const std::string &pin_name)
Definition: net.cpp:169
void set_name(const std::string &name)
Definition: net.cpp:103
bool mark_global_input_net()
Definition: net.cpp:484
Endpoint * add_source(Gate *gate, const std::string &pin_name)
Definition: net.cpp:127
const std::string & get_name() const
Definition: net.cpp:98
bool unmark_global_output_net()
Definition: net.cpp:499
bool is_unrouted() const
Definition: net.cpp:469
bool unmark_global_input_net()
Definition: net.cpp:494
bool mark_global_output_net()
Definition: net.cpp:489
bool is_a_source(const Gate *gate) const
Definition: net.cpp:199
Grouping * get_grouping() const
Definition: net.cpp:117
bool is_global_output_net() const
Definition: net.cpp:509
ssize_t get_hash() const
Definition: net.cpp:83
u32 get_num_of_destinations(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
Definition: net.cpp:432
std::vector< Endpoint * > get_destinations(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
Definition: net.cpp:450
bool is_a_destination(const Gate *gate) const
Definition: net.cpp:373
bool is_global_input_net() const
Definition: net.cpp:504
bool remove_destination(Gate *gate, const std::string &pin_name)
Definition: net.cpp:343
bool is_vcc_net() const
Definition: net.cpp:479
std::vector< Endpoint * > get_sources(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
Definition: net.cpp:276
bool is_gnd_net() const
Definition: net.cpp:474
void net_init(py::module &m)
Definition: net.cpp:5
std::unique_ptr< T, py::nodelete > RawPtrWrapper
const Module * module(const Gate *g, const NodeBoxes &boxes)
Definition: defines.h:45
Net * net