HAL
net.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 
28 #include "hal_core/defines.h"
34 
35 #include <functional>
36 #include <map>
37 #include <memory>
38 #include <set>
39 #include <string>
40 #include <tuple>
41 #include <vector>
42 
43 namespace hal
44 {
45  /* forward declaration */
46  class Netlist;
47  class Gate;
48  class Grouping;
49  class NetlistInternalManager;
50  class Endpoint;
51 
57  class NETLIST_API Net : public DataContainer
58  {
59  public:
66  bool operator==(const Net& other) const;
67 
74  bool operator!=(const Net& other) const;
75 
81  ssize_t get_hash() const;
82 
88  u32 get_id() const;
89 
95  Netlist* get_netlist() const;
96 
102  const std::string& get_name() const;
103 
109  void set_name(const std::string& name);
110 
117  Grouping* get_grouping() const;
118 
119  /*
120  * src specific functions
121  */
122 
131  Endpoint* add_source(Gate* gate, const std::string& pin_name);
132 
141  Endpoint* add_source(Gate* gate, GatePin* pin);
142 
152  bool remove_source(Gate* gate, const std::string& pin_name);
153 
163  bool remove_source(Gate* gate, const GatePin* pin);
164 
172  bool remove_source(Endpoint* ep);
173 
180  bool is_a_source(const Gate* gate) const;
181 
190  bool is_a_source(const Gate* gate, const std::string& pin_name) const;
191 
201  bool is_a_source(const Gate* gate, const GatePin* pin) const;
202 
209  bool is_a_source(const Endpoint* ep) const;
210 
218  u32 get_num_of_sources(const std::function<bool(Endpoint* ep)>& filter = nullptr) const;
219 
227  std::vector<Endpoint*> get_sources(const std::function<bool(Endpoint* ep)>& filter = nullptr) const;
228 
229  /*
230  * dst specific functions
231  */
232 
241  Endpoint* add_destination(Gate* gate, const std::string& pin_name);
242 
251  Endpoint* add_destination(Gate* gate, GatePin* pin);
252 
262  bool remove_destination(Gate* gate, const std::string& pin_name);
263 
273  bool remove_destination(Gate* gate, const GatePin* pin);
274 
282  bool remove_destination(Endpoint* ep);
283 
290  bool is_a_destination(const Gate* gate) const;
291 
300  bool is_a_destination(const Gate* gate, const std::string& pin_name) const;
301 
311  bool is_a_destination(const Gate* gate, const GatePin* pin) const;
312 
319  bool is_a_destination(const Endpoint* ep) const;
320 
328  u32 get_num_of_destinations(const std::function<bool(Endpoint* ep)>& filter = nullptr) const;
329 
337  std::vector<Endpoint*> get_destinations(const std::function<bool(Endpoint* ep)>& filter = nullptr) const;
338 
344  bool is_unrouted() const;
345 
351  bool is_gnd_net() const;
352 
358  bool is_vcc_net() const;
359 
365  bool mark_global_input_net();
366 
372  bool mark_global_output_net();
373 
379  bool unmark_global_input_net();
380 
386  bool unmark_global_output_net();
387 
393  bool is_global_input_net() const;
394 
400  bool is_global_output_net() const;
401 
402  private:
404  explicit Net(NetlistInternalManager* internal_manager, EventHandler* event_handler, const u32 id, const std::string& name = "");
405 
406  Net(const Net&) = delete;
407  Net(Net&&) = delete;
408  Net& operator=(const Net&) = delete;
409  Net& operator=(Net&&) = delete;
410 
411  NetlistInternalManager* m_internal_manager;
412 
413  /* stores the id of the net */
414  u32 m_id;
415 
416  /* stores the name of the net */
417  std::string m_name;
418 
419  /* grouping */
420  Grouping* m_grouping = nullptr;
421 
422  /* stores the dst gate and pin id of the dst gate */
423  std::vector<std::unique_ptr<Endpoint>> m_destinations;
424  std::vector<std::unique_ptr<Endpoint>> m_sources;
425  std::vector<Endpoint*> m_destinations_raw;
426  std::vector<Endpoint*> m_sources_raw;
427 
428  EventHandler* m_event_handler;
429  };
430 } // namespace hal
#define NETLIST_API
Definition: arch_linux.h:30
Definition: gate.h:58
Definition: net.h:58
quint32 u32
std::string name