HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
simulation_input.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 <vector>
29 #include <unordered_set>
30 #include <unordered_map>
31 #include "hal_core/defines.h"
36 
37 namespace hal {
38  class Gate;
39  class Net;
40 
44  class SimulationInputNetEvent : public std::unordered_map<const Net*,BooleanFunction::Value>
45  {
46  u64 mSimulationDuration;
47  public:
48  u64 get_simulation_duration() const { return mSimulationDuration; }
49  void set_simulation_duration(u64 t) { mSimulationDuration = t; }
50  };
51 
56 
57  public:
59 
63  struct Clock
64  {
65  const Net* clock_net;
68  u64 period() const { return switch_time * 2; }
69  };
70 
74  struct NetGroup
75  {
77  const Gate* gate;
80  bool ascending;
81  NetGroup() : direction(Undefined), gate(nullptr), module_pin_group(nullptr), gate_pin_group(nullptr), ascending(false) {;}
82  std::vector<const Net*> get_nets() const;
83  std::string get_name() const;
84  bool is_input() const { return direction == InputOnly; }
85  bool is_output() const { return direction == OutputOnly; }
86  };
87 
88  private:
89  std::unordered_set<const Gate*> mSimulationSet;
90  std::vector<Clock> m_clocks;
91  std::vector<NetGroup> m_netgroups;
92 
93  std::unordered_set<const Net*> m_input_nets;
94  std::vector<const Net*> m_output_nets;
95  std::vector<const Net*> m_partial_nets;
96 
97  bool mNoClockUsed;
98 
99  void compute_input_nets();
100  void compute_output_nets();
101  void compute_partial_nets();
102 
103  public:
104  SimulationInput() : mNoClockUsed(false) {;}
105 
110  bool is_ready() const;
111 
116  bool has_gates() const;
117 
123  bool contains_gate(const Gate* g) const;
124 
129  const std::unordered_set<const Gate*>& get_gates() const;
130 
135  const std::vector<Clock>& get_clocks() const { return m_clocks; }
136 
142  bool is_clock(const Net* n) const;
143 
147  void set_no_clock_used();
148 
153  bool is_no_clock_used() const;
154 
160  bool is_input_net(const Net* n) const;
161 
166  void add_clock(const Clock& clk);
167 
174  void add_gates(const std::vector<Gate*>& gates);
175 
179  void clear();
180 
186  const std::unordered_set<const Net*>& get_input_nets() const;
187 
193  const std::vector<const Net*>& get_output_nets() const;
194 
200  const std::vector<const Net*>& get_partial_netlist_nets() const;
201 
206  void dump(std::string filename = std::string()) const;
207 
213  void compute_net_groups();
214 
219  const std::vector<NetGroup>& get_net_groups() const { return m_netgroups; }
220  };
221 }
Definition: gate.h:58
Definition: net.h:58
const std::vector< NetGroup > & get_net_groups() const
const std::vector< const Net * > & get_partial_netlist_nets() const
const std::vector< Clock > & get_clocks() const
const std::vector< const Net * > & get_output_nets() const
void dump(std::string filename=std::string()) const
bool is_input_net(const Net *n) const
bool is_clock(const Net *n) const
const std::unordered_set< const Net * > & get_input_nets() const
void add_gates(const std::vector< Gate * > &gates)
bool contains_gate(const Gate *g) const
const std::unordered_set< const Gate * > & get_gates() const
void add_clock(const Clock &clk)
uint64_t u64
Definition: defines.h:42
Definition: defines.h:45
PinGroup< GatePin > * gate_pin_group
PinGroup< ModulePin > * module_pin_group
std::vector< const Net * > get_nets() const