HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
gate_library.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"
30 
31 #include <map>
32 #include <set>
33 #include <string>
34 #include <vector>
35 
36 namespace hal
37 {
44  {
45  public:
52  GateLibrary(const std::filesystem::path& path, const std::string& name);
53  ~GateLibrary() = default;
54 
60  std::string get_name() const;
61 
67  std::filesystem::path get_path() const;
68 
75  void set_path(const std::filesystem::path& modified_path);
76 
83  void set_name(const std::string& modified_name);
84 
90  void set_gate_location_data_category(const std::string& category);
91 
97  const std::string& get_gate_location_data_category() const;
104  void set_gate_location_data_identifiers(const std::string& x_coordinate, const std::string& y_coordinate);
105 
111  const std::pair<std::string, std::string>& get_gate_location_data_identifiers() const;
112 
121  GateType* create_gate_type(const std::string& name, std::set<GateTypeProperty> properties = {GateTypeProperty::combinational}, std::unique_ptr<GateTypeComponent> component = nullptr);
122 
123  // TODO pybind
133  GateType* replace_gate_type(u32 id, const std::string& name, std::set<GateTypeProperty> properties = {GateTypeProperty::combinational}, std::unique_ptr<GateTypeComponent> component = nullptr);
134 
141  bool contains_gate_type(GateType* gate_type) const;
142 
149  bool contains_gate_type_by_name(const std::string& name) const;
150 
157  GateType* get_gate_type_by_name(const std::string& name) const;
158 
166  std::unordered_map<std::string, GateType*> get_gate_types(const std::function<bool(const GateType*)>& filter = nullptr) const;
167 
174  bool mark_vcc_gate_type(GateType* gate_type);
175 
181  std::unordered_map<std::string, GateType*> get_vcc_gate_types() const;
182 
189  bool mark_gnd_gate_type(GateType* gate_type);
190 
196  std::unordered_map<std::string, GateType*> get_gnd_gate_types() const;
197 
203  void add_include(const std::string& include);
204 
210  std::vector<std::string> get_includes() const;
211 
212  void remove_gate_type(const std::string& name);
213 
214  private:
215  std::string m_name;
216  std::filesystem::path m_path;
217 
218  std::string m_gate_location_data_category = "generic";
219  std::pair<std::string, std::string> m_gate_location_data_identifiers = {"X_COORDINATE", "Y_COORDINATE"};
220 
221  u32 m_next_gate_type_id;
222 
223  std::vector<std::unique_ptr<GateType>> m_gate_types;
224  std::unordered_map<std::string, GateType*> m_gate_type_map;
225  std::unordered_map<std::string, GateType*> m_vcc_gate_types;
226  std::unordered_map<std::string, GateType*> m_gnd_gate_types;
227 
228  std::vector<std::string> m_includes;
229 
230  GateLibrary(const GateLibrary&) = delete;
231  GateLibrary& operator=(const GateLibrary&) = delete;
232 
233  u32 get_unique_gate_type_id();
234  };
235 } // namespace hal
#define NETLIST_API
Definition: arch_linux.h:30
~GateLibrary()=default
uint32_t u32
Definition: defines.h:41
std::vector< Gate * > get_path(const Gate *gate, bool get_successors, std::set< GateTypeProperty > stop_properties, std::unordered_map< u32, std::vector< Gate * >> &cache)
Definition: defines.h:45
std::string name