HAL
grouping.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
6  {
7  py::class_<Grouping, RawPtrWrapper<Grouping>> py_grouping(m, "Grouping", R"(
8  A grouping is an unstructured collection of gates, nets, and modules that do not need to be connected in any way.
9  It is designed to act as a container to temporarily store related entities during netlist exploration.
10  In contrast to a module, it does not allow for hierarchization.
11  Each gate, net, or module within the netlist may only be assigned to a single grouping.
12  )");
13 
14  py_grouping.def_property_readonly("id", &Grouping::get_id, R"(
15  The unique ID of the grouping.
16 
17  :type: int
18  )");
19 
20  py_grouping.def("get_id", &Grouping::get_id, R"(
21  Get the unique ID of the grouping.
22 
23  :returns: The unique id.
24  :rtype: int
25  )");
26 
27  py_grouping.def_property("name", &Grouping::get_name, &Grouping::set_name, R"(
28  The name of the grouping.
29 
30  :type: str
31  )");
32 
33  py_grouping.def("get_name", &Grouping::get_name, R"(
34  Get the name of the grouping.
35 
36  :returns: The name.
37  :rtype: str
38  )");
39 
40  py_grouping.def("set_name", &Grouping::set_name, py::arg("name"), R"(
41  Set the name of the grouping.
42 
43  :param str name: The new name.
44  )");
45 
46  py_grouping.def_property_readonly(
47  "netlist", [](Grouping* grouping) { return RawPtrWrapper<Netlist>(grouping->get_netlist()); }, R"(
48  The netlist this grouping is associated with.
49 
50  :type: hal_py.Netlist
51  )");
52 
53  py_grouping.def(
54  "get_netlist", [](Grouping* grouping) { return RawPtrWrapper<Netlist>(grouping->get_netlist()); }, R"(
55  Get the netlist this grouping is associated with.
56 
57  :returns: The netlist.
58  :rtype: hal_py.Netlist
59  )");
60 
61  py_grouping.def("assign_gate", &Grouping::assign_gate, py::arg("gate"), py::arg("force") = false, R"(
62  Assign a gate to the grouping.
63  Fails if the gate is already contained within another grouping.
64  If force is set and the gate is contained in another grouping, it is removed from the previous grouping to be assigned to this one.
65 
66  :param hal_py.Gate gate: The gate to assign.
67  :param bool force: Overwrite previous assignment.
68  :returns: True on success, false otherwise.
69  :rtype: bool
70  )");
71 
72  py_grouping.def("assign_gate_by_id", &Grouping::assign_gate_by_id, py::arg("gate_id"), py::arg("force") = false, R"(
73  Assign a gate to the grouping by ID.
74  Fails if the gate is already contained within another grouping.
75  If force is set and the gate is contained in another grouping, it is removed from the previous grouping to be assigned to this one.
76 
77  :param int gate_id: The ID of the gate to assign.
78  :param bool force: Overwrite previous assignment.
79  :returns: True on success, false otherwise.
80  :rtype: bool
81  )");
82 
83  py_grouping.def_property_readonly("gates", py::overload_cast<>(&Grouping::get_gates, py::const_), R"(
84  All gates contained within the grouping.
85 
86  :type: list[hal_py.Gate]
87  )");
88 
89  py_grouping.def("get_gates", py::overload_cast<>(&Grouping::get_gates, py::const_), R"(
90  Get all gates contained within the grouping.
91 
92  :returns: A list of gates.
93  :rtype: list[hal_py.Gate]
94  )");
95 
96  py_grouping.def("get_gates", py::overload_cast<const std::function<bool(Gate*)>&>(&Grouping::get_gates, py::const_), py::arg("filter"), R"(
97  Get all gates contained within the grouping.
98  The filter is evaluated on every candidate such that the result only contains those matching the specified condition.
99 
100  :param lambda filter: Filter function to be evaluated on each gate.
101  :returns: A list of gates.
102  :rtype: list[hal_py.Gate]
103  )");
104 
105  py_grouping.def_property_readonly(
106  "gate_ids", [](Grouping* grouping) { return grouping->get_gate_ids(); }, R"(
107  The IDs of all gates contained within the grouping.
108 
109  :type: list[int]
110  )");
111 
112  py_grouping.def("get_gate_ids", &Grouping::get_gate_ids, py::arg("filter") = nullptr, R"(
113  Get the IDs of all gates contained within the grouping.
114  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
115 
116  :param lambda filter: Filter function to be evaluated on each gate.
117  :returns: A list of gate IDs.
118  :rtype: list[int]
119  )");
120 
121  py_grouping.def("remove_gate", &Grouping::remove_gate, py::arg("gate"), R"(
122  Remove a gate from the grouping.
123  Fails if the gate is not contained within the grouping.
124 
125  :param hal_py.Gate gate: The gate to remove.
126  :returns: True on success, false otherwise.
127  :rtype: bool
128  )");
129 
130  py_grouping.def("remove_gate_by_id", &Grouping::remove_gate_by_id, py::arg("gate_id"), R"(
131  Remove a gate from the grouping by ID.
132  Fails if the gate is not contained within the grouping.
133 
134  :param int gate_id: The ID of the gate to remove.
135  :returns: True on success, false otherwise.
136  :rtype: bool
137  )");
138 
139  py_grouping.def("contains_gate", &Grouping::contains_gate, py::arg("gate"), R"(
140  Check whether a gate is in the grouping.
141 
142  :param hal_py.Gate gate: The gate to check for.
143  :returns: True on success, false otherwise.
144  :rtype: bool
145  )");
146 
147  py_grouping.def("contains_gate_by_id", &Grouping::contains_gate_by_id, py::arg("gate_id"), R"(
148  Check whether a gate is in the grouping by ID.
149 
150  :param int gate_id: The ID of the gate to check for.
151  :returns: True on success, false otherwise.
152  :rtype: bool
153  )");
154 
155  py_grouping.def("assign_net", &Grouping::assign_net, py::arg("net"), py::arg("force") = false, R"(
156  Assign a net to the grouping.
157  Fails if the net is already contained within another grouping.
158  If force is set and the net is contained in another grouping, it is removed from the previous grouping to be assigned to this one.
159 
160  :param hal_py.Net net: The net to assign.
161  :param bool force: Overwrite previous assignment.
162  :returns: True on success, false otherwise.
163  :rtype: bool
164  )");
165 
166  py_grouping.def("assign_net_by_id", &Grouping::assign_net_by_id, py::arg("net_id"), py::arg("force") = false, R"(
167  Assign a net to the grouping by ID.
168  Fails if the net is already contained within another grouping.
169  If force is set and the net is contained in another grouping, it is removed from the previous grouping to be assigned to this one.
170 
171  :param int net_id: The ID of the net to assign.
172  :param bool force: Overwrite previous assignment.
173  :returns: True on success, false otherwise.
174  :rtype: bool
175  )");
176 
177  py_grouping.def_property_readonly("nets", py::overload_cast<>(&Grouping::get_nets, py::const_), R"(
178  All nets contained within the grouping.
179 
180  :type: list[hal_py.Net]
181  )");
182 
183  py_grouping.def("get_nets", py::overload_cast<>(&Grouping::get_nets, py::const_), R"(
184  Get all nets contained within the grouping.
185 
186  :returns: A list of nets.
187  :rtype: list[hal_py.Net]
188  )");
189 
190  py_grouping.def("get_nets", py::overload_cast<const std::function<bool(Net*)>&>(&Grouping::get_nets, py::const_), py::arg("filter"), R"(
191  Get all nets contained within the grouping.
192  The filter is evaluated on every candidate such that the result only contains those matching the specified condition.
193 
194  :param lambda filter: Filter function to be evaluated on each net.
195  :returns: A list of nets.
196  :rtype: list[hal_py.Net]
197  )");
198 
199  py_grouping.def_property_readonly(
200  "net_ids", [](Grouping* grouping) { return grouping->get_net_ids(); }, R"(
201  The IDs of all nets contained within the grouping.
202 
203  :type: list[int]
204  )");
205 
206  py_grouping.def("get_net_ids", &Grouping::get_net_ids, py::arg("filter") = nullptr, R"(
207  Get the IDs of all nets contained within the grouping.
208  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
209 
210  :param lambda filter: Filter function to be evaluated on each net.
211  :returns: A list of net IDs.
212  :rtype: list[int]
213  )");
214 
215  py_grouping.def("remove_net", &Grouping::remove_net, py::arg("net"), R"(
216  Remove a net from the grouping.
217  Fails if the net is not contained within the grouping.
218 
219  :param hal_py.Net net: The net to remove.
220  :returns: True on success, false otherwise.
221  :rtype: bool
222  )");
223 
224  py_grouping.def("remove_net_by_id", &Grouping::remove_net_by_id, py::arg("net_id"), R"(
225  Remove a net from the grouping by ID.
226  Fails if the net is not contained within the grouping.
227 
228  :param int net_id: The ID of the net to remove.
229  :returns: True on success, false otherwise.
230  :rtype: bool
231  )");
232 
233  py_grouping.def("contains_net", &Grouping::contains_net, py::arg("net"), R"(
234  Check whether a net is in the grouping.
235 
236  :param hal_py.Net net: The net to check for.
237  :returns: True on success, false otherwise.
238  :rtype: bool
239  )");
240 
241  py_grouping.def("contains_net_by_id", &Grouping::contains_net_by_id, py::arg("net_id"), R"(
242  Check whether a net is in the grouping by ID.
243 
244  :param int net_id: The ID of the net to check for.
245  :returns: True on success, false otherwise.
246  :rtype: bool
247  )");
248 
249  py_grouping.def("assign_module", &Grouping::assign_module, py::arg("module"), py::arg("force") = false, R"(
250  Assign a module to the grouping.
251  Fails if the module is already contained within another grouping.
252  If force is set and the module is contained in another grouping, it is removed from the previous grouping to be assigned to this one.
253 
254  :param hal_py.Gate module: The module to assign.
255  :param bool force: Overwrite previous assignment.
256  :returns: True on success, false otherwise.
257  :rtype: bool
258  )");
259 
260  py_grouping.def("assign_module_by_id", &Grouping::assign_module_by_id, py::arg("module_id"), py::arg("force") = false, R"(
261  Assign a module to the grouping by ID.
262  Fails if the module is already contained within another grouping.
263  If force is set and the module is contained in another grouping, it is removed from the previous grouping to be assigned to this one.
264 
265  :param int module_id: The ID of the module to assign.
266  :param bool force: Overwrite previous assignment.
267  :returns: True on success, false otherwise.
268  :rtype: bool
269  )");
270 
271  py_grouping.def_property_readonly("modules", py::overload_cast<>(&Grouping::get_modules, py::const_), R"(
272  All modules contained within the grouping.
273 
274  :type: list[hal_py.Module]
275  )");
276 
277  py_grouping.def("get_modules", py::overload_cast<>(&Grouping::get_modules, py::const_), R"(
278  Get all modules contained within the grouping.
279 
280  :returns: A list of modules.
281  :rtype: list[hal_py.Module]
282  )");
283 
284  py_grouping.def("get_modules", py::overload_cast<const std::function<bool(Module*)>&>(&Grouping::get_modules, py::const_), py::arg("filter"), R"(
285  Get all modules contained within the grouping.
286  The filter is evaluated on every candidate such that the result only contains those matching the specified condition.
287 
288  :param lambda filter: Filter function to be evaluated on each module.
289  :returns: A list of modules.
290  :rtype: list[hal_py.Module]
291  )");
292 
293  py_grouping.def_property_readonly(
294  "module_ids", [](Grouping* grouping) { return grouping->get_module_ids(); }, R"(
295  The IDs of all modules contained within the grouping.
296  :type: list[int]
297  )");
298 
299  py_grouping.def("get_module_ids", &Grouping::get_module_ids, py::arg("filter") = nullptr, R"(
300  Get the IDs of all modules contained within the grouping.
301  The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
302 
303  :param lambda filter: Filter function to be evaluated on each module.
304  :returns: A list of module IDs.
305  :rtype: list[int]
306  )");
307 
308  py_grouping.def("remove_module", &Grouping::remove_module, py::arg("module"), R"(
309  Remove a module from the grouping.
310  Fails if the module is not contained within the grouping.
311 
312  :param hal_py.Gate module: The module to remove.
313  :returns: True on success, false otherwise.
314  :rtype: bool
315  )");
316 
317  py_grouping.def("remove_module_by_id", &Grouping::remove_gate_by_id, py::arg("module_id"), R"(
318  Remove a module from the grouping by ID.
319  Fails if the module is not contained within the grouping.
320 
321  :param int module_id: The ID of the module to remove.
322  :returns: True on success, false otherwise.
323  :rtype: bool
324  )");
325 
326  py_grouping.def("contains_module", &Grouping::contains_module, py::arg("module"), R"(
327  Check whether a module is in the grouping.
328 
329  :param hal_py.Gate module: The module to check for.
330  :returns: True on success, false otherwise.
331  :rtype: bool
332  )");
333 
334  py_grouping.def("contains_module_by_id", &Grouping::contains_module_by_id, py::arg("module_id"), R"(
335  Check whether a module is in the grouping by ID.
336 
337  :param int module_id: The ID of the module to check for.
338  :returns: True on success, false otherwise.
339  :rtype: bool
340  )");
341  }
342 } // namespace hal
Definition: gate.h:58
std::vector< u32 > get_gate_ids(const std::function< bool(Gate *)> &filter=nullptr) const
Definition: grouping.cpp:113
const std::vector< Gate * > & get_gates() const
Definition: grouping.cpp:85
bool remove_gate_by_id(const u32 gate_id)
Definition: grouping.cpp:130
bool contains_module_by_id(const u32 module_id) const
Definition: grouping.cpp:325
bool assign_module(Module *module, bool force=false)
Definition: grouping.cpp:243
bool contains_net_by_id(const u32 net_id) const
Definition: grouping.cpp:238
std::vector< u32 > get_module_ids(const std::function< bool(Module *)> &filter=nullptr) const
Definition: grouping.cpp:287
bool remove_net(Net *net)
Definition: grouping.cpp:212
Netlist * get_netlist() const
Definition: grouping.cpp:64
bool contains_net(Net *net) const
Definition: grouping.cpp:228
std::vector< u32 > get_net_ids(const std::function< bool(Net *)> &filter=nullptr) const
Definition: grouping.cpp:200
bool remove_net_by_id(const u32 net_id)
Definition: grouping.cpp:217
bool assign_gate(Gate *gate, bool force=false)
Definition: grouping.cpp:69
bool assign_module_by_id(const u32 module_id, bool force=false)
Definition: grouping.cpp:248
std::string get_name() const
Definition: grouping.cpp:42
bool remove_gate(Gate *gate)
Definition: grouping.cpp:125
void set_name(std::string name)
Definition: grouping.cpp:27
const std::vector< Net * > & get_nets() const
Definition: grouping.cpp:172
u32 get_id() const
Definition: grouping.cpp:22
bool contains_module(Module *module) const
Definition: grouping.cpp:315
const std::vector< Module * > & get_modules() const
Definition: grouping.cpp:259
bool remove_module(Module *module)
Definition: grouping.cpp:299
bool contains_gate_by_id(const u32 gate_id) const
Definition: grouping.cpp:151
bool contains_gate(Gate *gate) const
Definition: grouping.cpp:141
bool assign_net_by_id(const u32 net_id, bool force=false)
Definition: grouping.cpp:161
bool assign_gate_by_id(const u32 gate_id, bool force=false)
Definition: grouping.cpp:74
bool assign_net(Net *net, bool force=false)
Definition: grouping.cpp:156
Definition: net.h:58
void grouping_init(py::module &m)
Definition: grouping.cpp:5
std::unique_ptr< T, py::nodelete > RawPtrWrapper
const Module * module(const Gate *g, const NodeBoxes &boxes)