HAL  v4.5.0-133-g64838ea8d
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
netlist_utils.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 namespace hal
33 {
34  class Gate;
35  class Net;
36 
42  namespace netlist_utils
43  {
55  [[deprecated("Will be removed in a future version, use SubgraphNetlistDecorator::get_subgraph_function instead.")]] CORE_API Result<BooleanFunction>
56  get_subgraph_function(const Net* net, const std::vector<const Gate*>& subgraph_gates, std::map<std::pair<u32, const GatePin*>, BooleanFunction>& cache);
57 
67  [[deprecated("Will be removed in a future version, use SubgraphNetlistDecorator::get_subgraph_function instead.")]] CORE_API Result<BooleanFunction>
68  get_subgraph_function(const Net* net, const std::vector<const Gate*>& subgraph_gates);
69 
77  [[deprecated("Will be removed in a future version, use Netlist::copy instead.")]] CORE_API std::unique_ptr<Netlist> copy_netlist(const Netlist* nl);
78 
87  [[deprecated("Will be removed in a future version, use boolean_influence::get_ff_dependency_matrix instead.")]] std::pair<std::map<u32, Gate*>, std::vector<std::vector<int>>>
89 
98  [[deprecated("Will be removed in a future version, use SubgraphNetlistDecorator::copy_subgraph_netlist instead.")]] CORE_API std::unique_ptr<Netlist>
99  get_partial_netlist(const Netlist* nl, const std::vector<const Gate*>& subgraph_gates);
100 
115  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_next_matching_gates_until_depth instead.")]] CORE_API std::vector<Gate*>
116  get_next_gates(const Gate* gate, bool get_successors, int depth = 0, const std::function<bool(const Gate*)>& filter = nullptr);
117 
132  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_next_matching_gates_until_depth instead.")]] CORE_API std::vector<Gate*>
133  get_next_gates(const Net* net, bool get_successors, int depth = 0, const std::function<bool(const Gate*)>& filter = nullptr);
134 
149  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_next_sequential_gates instead.")]] CORE_API std::vector<Gate*>
150  get_next_sequential_gates(const Gate* gate, bool get_successors, std::unordered_map<u32, std::vector<Gate*>>& cache);
151 
162  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_next_sequential_gates instead.")]] CORE_API std::vector<Gate*>
163  get_next_sequential_gates(const Gate* gate, bool get_successors);
164 
178  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_next_sequential_gates instead.")]] CORE_API std::vector<Gate*>
179  get_next_sequential_gates(const Net* net, bool get_successors, std::unordered_map<u32, std::vector<Gate*>>& cache);
180 
190  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_next_sequential_gates instead.")]] CORE_API std::vector<Gate*>
191  get_next_sequential_gates(const Net* net, bool get_successors);
192 
208  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_gates instead.")]] CORE_API std::vector<Gate*> get_path(const Gate* gate, bool get_successors, std::set<GateTypeProperty> stop_properties, std::unordered_map<u32, std::vector<Gate*>>& cache);
209 
221  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_gates instead.")]] CORE_API std::vector<Gate*> get_path(const Gate* gate, bool get_successors, std::set<GateTypeProperty> stop_properties);
222 
237  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_gates instead.")]] CORE_API std::vector<Gate*> get_path(const Net* net, bool get_successors, std::set<GateTypeProperty> stop_properties, std::unordered_map<u32, std::vector<Gate*>>& cache);
238 
249  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_gates instead.")]] CORE_API std::vector<Gate*> get_path(const Net* net, bool get_successors, std::set<GateTypeProperty> stop_properties);
250 
259  [[deprecated("Will be removed in a future version, iterate the pins and use Gate::get_fan_in_net or Gate::get_fan_out_net instead.")]] CORE_API std::vector<Net*> get_nets_at_pins(Gate* gate, std::vector<GatePin*> pins);
260 
270  [[deprecated("Will be removed in a future version, use NetlistPreprocessingPlugin::remove_buffers instead.")]] CORE_API Result<u32> remove_buffers(Netlist* netlist,
271  bool analyze_inputs = false);
272 
280  [[deprecated("Will be removed in a future version, use NetlistPreprocessingPlugin::remove_unused_lut_inputs instead.")]] CORE_API Result<u32> remove_unused_lut_endpoints(Netlist* netlist);
281 
292  // TODO move to SubgraphNetlistDecorator
293  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_common_inputs instead.")]] CORE_API std::vector<Net*> get_common_inputs(const std::vector<Gate*>& gates, u32 threshold = 0);
294 
306  [[deprecated("Will be removed in a future version, use NetlistModificationDecorator::replace_gate instead.")]] CORE_API Result<std::monostate>
307  replace_gate(Gate* gate, GateType* target_type, std::map<GatePin*, GatePin*> pin_map);
308 
320  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_shortest_path instead.")]] CORE_API std::vector<Gate*> get_shortest_path(Gate* start_gate, Gate* end_gate, bool search_both_directions = false);
321 
333  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_shortest_path instead.")]] CORE_API std::vector<Gate*> get_shortest_path(Gate* start_gate, Module* end_module, bool forward_direction);
334 
335 
347  [[deprecated("Will be removed in a future version, use NetlistTraversalDecorator::get_shortest_path instead.")]] CORE_API std::vector<std::vector<Gate*> > get_shortest_path(Module* start_module, Module* end_module);
348  } // namespace netlist_utils
349 } // namespace hal
#define CORE_API
Definition: arch_linux.h:28
Definition: gate.h:58
Definition: net.h:58
uint32_t u32
Definition: defines.h:41
Result< u32 > remove_unused_lut_endpoints(Netlist *netlist)
std::vector< Gate * > get_path(const Gate *gate, bool get_successors, std::set< GateTypeProperty > stop_properties, std::unordered_map< u32, std::vector< Gate * >> &cache)
std::vector< Gate * > get_next_gates(const Gate *gate, bool get_successors, int depth=0, const std::function< bool(const Gate *)> &filter=nullptr)
Result< BooleanFunction > get_subgraph_function(const Net *net, const std::vector< const Gate * > &subgraph_gates, std::map< std::pair< u32, const GatePin * >, BooleanFunction > &cache)
Result< u32 > remove_buffers(Netlist *netlist, bool analyze_inputs=false)
std::unique_ptr< Netlist > copy_netlist(const Netlist *nl)
std::vector< Gate * > get_next_sequential_gates(const Gate *gate, bool get_successors, std::unordered_map< u32, std::vector< Gate * >> &cache)
std::vector< Gate * > get_shortest_path(Gate *start_gate, Gate *end_gate, bool search_both_directions=false)
Result< std::monostate > replace_gate(Gate *gate, GateType *target_type, std::map< GatePin *, GatePin * > pin_map)
std::vector< Net * > get_nets_at_pins(Gate *gate, std::vector< GatePin * > pins)
std::vector< Net * > get_common_inputs(const std::vector< Gate * > &gates, u32 threshold=0)
std::pair< std::map< u32, Gate * >, std::vector< std::vector< int > > > get_ff_dependency_matrix(const Netlist *nl)
std::unique_ptr< Netlist > get_partial_netlist(const Netlist *nl, const std::vector< const Gate * > &subgraph_gates)
Definition: defines.h:45
std::vector< PinInformation > pins
Net * net