HAL
result.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 
31 #pragma once
32 
38 
39 namespace hal
40 {
41  class Gate;
42  class Net;
43  class Module;
44  class GateType;
45 
46  namespace dataflow
47  {
56  class Result
57  {
58  public:
59  Result(Netlist* nl, const Grouping& grouping);
60 
66  Netlist* get_netlist() const;
67 
73  const std::unordered_map<u32, std::unordered_set<Gate*>>& get_groups() const;
74 
80  std::vector<Gate*> get_gates() const;
81 
89 
96  hal::Result<u32> get_group_id_of_gate(const Gate* gate) const;
97 
106 
115 
123 
131 
139 
147 
155  hal::Result<std::monostate> write_dot(const std::filesystem::path& out_path, const std::unordered_set<u32>& group_ids = {}) const;
156 
164  hal::Result<std::monostate> write_txt(const std::filesystem::path& out_path, const std::unordered_set<u32>& group_ids = {}) const;
165 
174  hal::Result<std::unordered_map<u32, Module*>> create_modules(const std::unordered_set<u32>& group_ids = {}) const;
175 
186  hal::Result<std::unordered_map<u32, Module*>> create_modules(const std::map<const GateType*, std::string>& module_suffixes,
187  const std::map<std::pair<PinDirection, std::string>, std::string>& pin_prefixes,
188  const std::unordered_set<u32>& group_ids) const;
189 
200  hal::Result<std::unordered_map<u32, Module*>> create_modules(const std::map<GateTypeProperty, std::string>& module_suffixes,
201  const std::map<std::pair<PinDirection, std::string>, std::string>& pin_prefixes,
202  const std::unordered_set<u32>& group_ids) const;
203 
210  std::vector<std::vector<Gate*>> get_groups_as_list(const std::unordered_set<u32>& group_ids = {}) const;
211 
220  hal::Result<u32> merge_groups(const std::vector<u32>& group_ids);
221 
232  hal::Result<std::vector<u32>> split_group(u32 group_id, const std::vector<std::unordered_set<Gate*>>& new_groups);
233 
234  private:
238  Netlist* m_netlist;
239 
243  u32 m_last_id = 0;
244 
248  std::unordered_map<u32, std::unordered_set<Gate*>> m_gates_of_group;
249 
253  std::unordered_map<const Gate*, u32> m_parent_group_of_gate;
254 
258  std::unordered_map<const Gate*, std::unordered_map<PinType, std::unordered_set<Net*>>> m_gate_signals;
259 
263  std::unordered_map<const Gate*, std::unordered_set<Gate*>> m_gate_successors;
264 
268  std::unordered_map<const Gate*, std::unordered_set<Gate*>> m_gate_predecessors;
269 
273  std::unordered_map<u32, std::unordered_map<PinType, std::unordered_set<Net*>>> m_group_signals;
274 
278  std::unordered_map<u32, std::unordered_set<u32>> m_group_successors;
279 
283  std::unordered_map<u32, std::unordered_set<u32>> m_group_predecessors;
284  };
285  } // namespace dataflow
286 } // namespace hal
Definition: gate.h:58
Result of a dataflow analysis run.
Definition: result.h:57
hal::Result< u32 > merge_groups(const std::vector< u32 > &group_ids)
Merge multiple groups specified by ID.
Definition: result.cpp:634
hal::Result< std::unordered_set< Gate * > > get_gates_of_group(const u32 group_id) const
Get the gates of the specified group of sequential gates.
Definition: result.cpp:121
hal::Result< std::unordered_set< u32 > > get_group_predecessors(const u32 group_id) const
Get the predecessor groups of the group with the given ID.
Definition: result.cpp:218
hal::Result< std::vector< u32 > > split_group(u32 group_id, const std::vector< std::unordered_set< Gate * >> &new_groups)
Split a group into multiple smaller groups specified by sets of gates.
Definition: result.cpp:707
std::vector< std::vector< Gate * > > get_groups_as_list(const std::unordered_set< u32 > &group_ids={}) const
Get the groups of the dataflow analysis result as a list.
Definition: result.cpp:614
hal::Result< std::unordered_map< u32, Module * > > create_modules(const std::unordered_set< u32 > &group_ids={}) const
Create modules for the dataflow analysis result.
Definition: result.cpp:417
hal::Result< std::monostate > write_txt(const std::filesystem::path &out_path, const std::unordered_set< u32 > &group_ids={}) const
Write the groups resulting from dataflow analysis to a .txt file.
Definition: result.cpp:321
hal::Result< std::unordered_set< Net * > > get_group_control_nets(const u32 group_id, const PinType type) const
Get the control nets of the group with the given group ID that are connected to a pin of the specifie...
Definition: result.cpp:150
hal::Result< std::unordered_set< Gate * > > get_gate_successors(const Gate *gate) const
Get the sequential successor gates of the given sequential gate.
Definition: result.cpp:203
const std::unordered_map< u32, std::unordered_set< Gate * > > & get_groups() const
Get the groups of sequential gates resulting from dataflow analysis.
Definition: result.cpp:104
hal::Result< u32 > get_group_id_of_gate(const Gate *gate) const
Get the group ID of the group that contains the given gate.
Definition: result.cpp:133
hal::Result< std::unordered_set< Net * > > get_gate_control_nets(const Gate *gate, const PinType type) const
Get the control nets of the given gate that are connected to a pin of the specified type.
Definition: result.cpp:169
Result(Netlist *nl, const Grouping &grouping)
Definition: result.cpp:29
Netlist * get_netlist() const
Get the netlist on which dataflow analysis has been performed.
Definition: result.cpp:99
hal::Result< std::unordered_set< u32 > > get_group_successors(const u32 group_id) const
Get the successor groups of the group with the given ID.
Definition: result.cpp:188
hal::Result< std::unordered_set< Gate * > > get_gate_predecessors(const Gate *gate) const
Get the sequential predecessor gates of the given sequential gate.
Definition: result.cpp:233
std::vector< Gate * > get_gates() const
Get all gates contained in any of the groups groups.
Definition: result.cpp:109
hal::Result< std::monostate > write_dot(const std::filesystem::path &out_path, const std::unordered_set< u32 > &group_ids={}) const
Write the dataflow graph as a DOT graph to the specified location.
Definition: result.cpp:248
PinType
Definition: pin_type.h:36
quint32 u32
PinType type
This file contains the class that holds all information of a dataflow analysis grouping.
Grouping used during dataflow analysis.
Definition: grouping.h:55