HAL
grouping.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
31 
32 #include <functional>
33 #include <unordered_map>
34 #include <vector>
35 
36 namespace hal
37 {
38  class Gate;
39  class Net;
40  class Module;
41 
51  {
52  public:
58  u32 get_id() const;
59 
65  void set_name(std::string name);
66 
72  std::string get_name() const;
73 
79  void set_color(utils::Color c);
80 
86  utils::Color get_color() const;
87 
93  utils::Color next_color();
94 
100  Netlist* get_netlist() const;
101 
102  /*
103  * ################################################################
104  * gate functions
105  * ################################################################
106  */
107 
117  bool assign_gate(Gate* gate, bool force = false);
118 
128  bool assign_gate_by_id(const u32 gate_id, bool force = false);
129 
135  const std::vector<Gate*>& get_gates() const;
136 
144  std::vector<Gate*> get_gates(const std::function<bool(Gate*)>& filter) const;
145 
153  std::vector<u32> get_gate_ids(const std::function<bool(Gate*)>& filter = nullptr) const;
154 
162  bool remove_gate(Gate* gate);
163 
171  bool remove_gate_by_id(const u32 gate_id);
172 
179  bool contains_gate(Gate* gate) const;
180 
187  bool contains_gate_by_id(const u32 gate_id) const;
188 
189  /*
190  * ################################################################
191  * net functions
192  * ################################################################
193  */
194 
204  bool assign_net(Net* net, bool force = false);
205 
215  bool assign_net_by_id(const u32 net_id, bool force = false);
216 
222  const std::vector<Net*>& get_nets() const;
223 
231  std::vector<Net*> get_nets(const std::function<bool(Net*)>& filter) const;
232 
240  std::vector<u32> get_net_ids(const std::function<bool(Net*)>& filter = nullptr) const;
241 
249  bool remove_net(Net* net);
250 
258  bool remove_net_by_id(const u32 net_id);
259 
266  bool contains_net(Net* net) const;
267 
274  bool contains_net_by_id(const u32 net_id) const;
275 
276  /*
277  * ################################################################
278  * module functions
279  * ################################################################
280  */
281 
291  bool assign_module(Module* module, bool force = false);
292 
302  bool assign_module_by_id(const u32 module_id, bool force = false);
303 
309  const std::vector<Module*>& get_modules() const;
310 
318  std::vector<Module*> get_modules(const std::function<bool(Module*)>& filter) const;
319 
327  std::vector<u32> get_module_ids(const std::function<bool(Module*)>& filter = nullptr) const;
328 
336  bool remove_module(Module* module);
337 
345  bool remove_module_by_id(const u32 module_id);
346 
353  bool contains_module(Module* module) const;
354 
361  bool contains_module_by_id(const u32 module_id) const;
362 
363  private:
365 
366  Grouping(NetlistInternalManager* internal_manager, EventHandler* event_handler, u32 id, std::string name);
367 
368  u32 m_id;
369  std::string m_name;
370  utils::Color m_color;
371  NetlistInternalManager* m_internal_manager;
372 
373  std::vector<Gate*> m_gates;
374  std::unordered_map<u32, Gate*> m_gates_map;
375  std::vector<Net*> m_nets;
376  std::unordered_map<u32, Net*> m_nets_map;
377  std::vector<Module*> m_modules;
378  std::unordered_map<u32, Module*> m_modules_map;
379 
380  EventHandler* m_event_handler;
381  };
382 } // namespace hal
#define NETLIST_API
Definition: arch_linux.h:30
Definition: gate.h:58
Definition: net.h:58
const Module * module(const Gate *g, const NodeBoxes &boxes)
quint32 u32
Net * net
std::string name