HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
netlist_internal_manager.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"
31 
32 #include <map>
33 #include <vector>
34 
35 namespace hal
36 {
37  // forward declaration
38  class Netlist;
39  class Gate;
40  class GateType;
41  class Net;
42  class Module;
43  class Endpoint;
44  class Grouping;
45  class BooleanFunction;
46 
54  {
55  friend class Netlist;
56  friend class Module;
57  friend class Net;
58  friend class Gate;
59  friend class Grouping;
60 
61  private:
62  Netlist* m_netlist;
63  EventHandler* m_event_handler;
64 
65  explicit NetlistInternalManager(Netlist* nl, EventHandler* eh);
66  ~NetlistInternalManager() = default;
67 
68  // netlist functions
70 
71  // gate functions
72  Gate* create_gate(u32 id, GateType* gt, const std::string& name, i32 x, i32 y);
73  bool delete_gate(Gate* gate);
74  bool is_gate_type_invalid(GateType* gt) const;
75 
76  // net functions
77  Net* create_net(u32 id, const std::string& name);
78  bool delete_net(Net* net);
79  Endpoint* net_add_source(Net* net, Gate* gate, GatePin* pin);
80  bool net_remove_source(Net* net, Endpoint* ep);
81  Endpoint* net_add_destination(Net* net, Gate* gate, GatePin* pin);
82  bool net_remove_destination(Net* net, Endpoint* ep);
83 
84  // module functions
85  Module* create_module(u32 id, Module* parent, const std::string& name);
86  bool delete_module(Module* module);
87  bool module_assign_gate(Module* m, Gate* g);
88  bool module_assign_gates(Module* module, const std::vector<Gate*>& gates);
89  bool module_check_net(Module* module, Net* net, bool recursive = false);
90 
91  // grouping functions
92  Grouping* create_grouping(u32 id, const std::string name);
93  bool delete_grouping(Grouping* grouping);
94  bool grouping_assign_gate(Grouping* grouping, Gate* gate, bool force = false);
95  bool grouping_remove_gate(Grouping* grouping, Gate* gate);
96  bool grouping_assign_net(Grouping* grouping, Net* net, bool force = false);
97  bool grouping_remove_net(Grouping* grouping, Net* net);
98  bool grouping_assign_module(Grouping* grouping, Module* module, bool force = false);
99  bool grouping_remove_module(Grouping* grouping, Module* module);
100 
101  // caches
102  void clear_caches();
103  mutable std::map<std::pair<std::vector<GatePin*>, u64>, BooleanFunction> m_lut_function_cache;
104  bool m_net_checks_enabled = true;
105  };
106 } // namespace hal
#define NETLIST_API
Definition: arch_linux.h:30
Definition: gate.h:58
Definition: net.h:58
uint64_t u64
Definition: defines.h:42
uint32_t u32
Definition: defines.h:41
int32_t i32
Definition: defines.h:36
const Module * module(const Gate *g, const NodeBoxes &boxes)
std::unique_ptr< Netlist > copy_netlist(const Netlist *nl)
Definition: defines.h:45
Net * net
std::string name