HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
simulation_engine.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 #include "hal_core/defines.h"
31 
32 #include <string>
33 #include <unordered_map>
34 #include <vector>
35 #include <filesystem>
36 
37 namespace hal
38 {
39  class NetlistSimulatorController;
40  class SimulationLogReceiver;
41 
46  {
47  std::string mName;
48 
49  public:
50  enum State
51  {
52  Failed = -1,
53  Done = 0,
54  Running = 1,
55  Preparing = 2
56  };
57 
58  protected:
61  std::string mResultFilename;
63  std::unordered_map<std::string, std::string> mProperties;
65  std::string mWorkDir;
66 
67  public:
68  SimulationEngine(const std::string& nam);
69  virtual ~SimulationEngine() {;}
70 
75  std::string name() const
76  {
77  return mName;
78  }
79 
84  State state() const
85  {
86  return mState;
87  }
88 
93  int get_state() const
94  {
95  return mState;
96  }
97 
102  std::string get_working_directory() const;
103 
108  void set_working_directory(const std::string& workDir);
109 
115  {
116  return mRequireClockEvents;
117  }
118 
124  bool can_share_memory() const
125  {
126  return mCanShareMemory;
127  }
128 
134  bool install_saleae_parser(std::string dirname) const;
135 
143  virtual bool setSimulationInput(SimulationInput* simInput) = 0;
144 
149  virtual void setResultFilename(const std::string filename)
150  {
151  mResultFilename = filename;
152  };
153 
158  std::string get_result_filename() const
159  {
160  return mResultFilename;
161  }
162 
173  virtual bool run(NetlistSimulatorController* controller, SimulationLogReceiver* logReceiver=nullptr) = 0;
174 
185  virtual bool finalize();
186 
193  virtual void failed();
194 
201  virtual void set_engine_property(const std::string& key, const std::string& value);
202 
203 
210  virtual std::string get_engine_property(const std::string& key);
211 
216  virtual const std::unordered_map<std::string,std::string>& get_engine_properties() const { return mProperties; }
217 
223  };
224 
229  {
230  bool run(NetlistSimulatorController* controller, SimulationLogReceiver* logReceiver=nullptr) override;
231  bool setSimulationInput(SimulationInput* simInput) override;
232 
233  public:
234  SimulationEngineEventDriven(const std::string& nam);
235 
243  virtual bool inputEvent(const SimulationInputNetEvent& netEv) = 0;
244 
251  virtual std::vector<WaveEvent> get_simulation_events(u32 netId) const;
252  };
253 
258  {
259  virtual bool run(NetlistSimulatorController* controller, SimulationLogReceiver *logReceiver=nullptr) override;
260 
261  public:
262  SimulationEngineScripted(const std::string& nam) : SimulationEngine(nam)
263  {
264  ;
265  }
266 
274  virtual int numberCommandLines() const = 0;
275 
283  virtual std::vector<std::string> commandLine(int lineIndex) const = 0;
284  };
285 
290  {
291  protected:
292  std::string mName;
293 
294  public:
295  SimulationEngineFactory(const std::string& nam);
297  {
298  ;
299  }
300  virtual SimulationEngine* createEngine() const = 0;
301  std::string name() const
302  {
303  return mName;
304  }
305  };
306 
310  class SimulationEngineFactories : public std::vector<SimulationEngineFactory*>
311  {
313  {
314  ;
315  }
316  static SimulationEngineFactories* inst;
317 
318  public:
320 
321  std::vector<std::string> factoryNames() const;
322  SimulationEngineFactory* factoryByName(const std::string nam) const;
323  void deleteFactory(const std::string nam);
324  };
325 } // namespace hal
virtual std::vector< WaveEvent > get_simulation_events(u32 netId) const
SimulationEngineEventDriven(const std::string &nam)
virtual bool inputEvent(const SimulationInputNetEvent &netEv)=0
void deleteFactory(const std::string nam)
std::vector< std::string > factoryNames() const
static SimulationEngineFactories * instance()
SimulationEngineFactory * factoryByName(const std::string nam) const
SimulationEngineFactory(const std::string &nam)
virtual SimulationEngine * createEngine() const =0
virtual SimulationInput * get_simulation_input() const
virtual bool run(NetlistSimulatorController *controller, SimulationLogReceiver *logReceiver=nullptr)=0
SimulationEngine(const std::string &nam)
bool clock_events_required() const
std::string get_working_directory() const
std::string name() const
virtual void set_engine_property(const std::string &key, const std::string &value)
virtual std::string get_engine_property(const std::string &key)
SimulationInput * mSimulationInput
virtual void setResultFilename(const std::string filename)
bool install_saleae_parser(std::string dirname) const
std::unordered_map< std::string, std::string > mProperties
virtual bool setSimulationInput(SimulationInput *simInput)=0
std::string get_result_filename() const
void set_working_directory(const std::string &workDir)
virtual const std::unordered_map< std::string, std::string > & get_engine_properties() const
virtual int numberCommandLines() const =0
virtual std::vector< std::string > commandLine(int lineIndex) const =0
SimulationEngineScripted(const std::string &nam)
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45