HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
hal::SimulationEngine Class Referenceabstract

#include </home/runner/work/hal/hal/plugins/simulator/netlist_simulator_controller/include/netlist_simulator_controller/simulation_engine.h>

Inheritance diagram for hal::SimulationEngine:
Inheritance graph
Collaboration diagram for hal::SimulationEngine:
Collaboration graph

Public Types

enum  State { Failed = -1 , Done = 0 , Running = 1 , Preparing = 2 }
 

Public Member Functions

 SimulationEngine (const std::string &nam)
 
virtual ~SimulationEngine ()
 
std::string name () const
 
State state () const
 
int get_state () const
 
std::string get_working_directory () const
 
void set_working_directory (const std::string &workDir)
 
bool clock_events_required () const
 
bool can_share_memory () const
 
bool install_saleae_parser (std::string dirname) const
 
virtual bool setSimulationInput (SimulationInput *simInput)=0
 
virtual void setResultFilename (const std::string filename)
 
std::string get_result_filename () const
 
virtual bool run (NetlistSimulatorController *controller, SimulationLogReceiver *logReceiver=nullptr)=0
 
virtual bool finalize ()
 
virtual void failed ()
 
virtual void set_engine_property (const std::string &key, const std::string &value)
 
virtual std::string get_engine_property (const std::string &key)
 
virtual const std::unordered_map< std::string, std::string > & get_engine_properties () const
 
virtual SimulationInputget_simulation_input () const
 

Protected Attributes

bool mRequireClockEvents
 
bool mCanShareMemory
 
std::string mResultFilename
 
State mState
 
std::unordered_map< std::string, std::string > mProperties
 
SimulationInputmSimulationInput
 
std::string mWorkDir
 

Detailed Description

The base class for all simulation engines, which holds the name, working directory, and properties of an engine.

Definition at line 45 of file simulation_engine.h.

Member Enumeration Documentation

◆ State

Enumerator
Failed 
Done 
Running 
Preparing 

Definition at line 50 of file simulation_engine.h.

Constructor & Destructor Documentation

◆ SimulationEngine()

hal::SimulationEngine::SimulationEngine ( const std::string &  nam)

Definition at line 16 of file simulation_engine.cpp.

◆ ~SimulationEngine()

virtual hal::SimulationEngine::~SimulationEngine ( )
inlinevirtual

Definition at line 69 of file simulation_engine.h.

Member Function Documentation

◆ can_share_memory()

bool hal::SimulationEngine::can_share_memory ( ) const
inline

Tells the caller whether engine can share simulation results directly from memory. If not the caller will most likely ask to have a VCD result file created.

Returns
true if results can be read from memory, false otherwise.

Definition at line 124 of file simulation_engine.h.

References mCanShareMemory.

◆ clock_events_required()

bool hal::SimulationEngine::clock_events_required ( ) const
inline

Request clock change as regular net input event

Returns
true if clock events are required by engine, false otherwise

Definition at line 114 of file simulation_engine.h.

References mRequireClockEvents.

Referenced by hal::NetlistSimulatorController::run_simulation().

◆ failed()

void hal::SimulationEngine::failed ( )
virtual

Can be overwritten by derived class

Signals the engine that an essential step failed and execution is going to be aborted. Engine might want to do some final clean up.

Definition at line 37 of file simulation_engine.cpp.

References Failed, and mState.

Referenced by hal::SimulationThread::run().

◆ finalize()

bool hal::SimulationEngine::finalize ( )
virtual

Can be overwritten by derived class

Signals the engine that it is time for final steps (.e.g. writing VCD file) after simulation is done - that is: SimulationEngineEventDriven: all input events have been processed SimulationEngineScripted: all comands executed successfully

Returns
true if successful, false otherwise.

Reimplemented in hal::verilator::VerilatorEngine, and hal::DummyEngine.

Definition at line 31 of file simulation_engine.cpp.

References Done, and mState.

Referenced by hal::SimulationThread::run().

◆ get_engine_properties()

virtual const std::unordered_map<std::string,std::string>& hal::SimulationEngine::get_engine_properties ( ) const
inlinevirtual

Get all propertiess

Returns

Definition at line 216 of file simulation_engine.h.

References mProperties.

Referenced by hal::NetlistSimulatorController::persist().

◆ get_engine_property()

std::string hal::SimulationEngine::get_engine_property ( const std::string &  key)
virtual

Get property which can be evaluated by engine

Parameters
keyproperty name
Returns
the property value, an empty string if the property is not set

Definition at line 69 of file simulation_engine.cpp.

References mProperties.

Referenced by hal::SimulationProcess::run(), hal::NetlistSimulatorController::run_simulation(), and hal::verilator::VerilatorEngine::setSimulationInput().

◆ get_result_filename()

std::string hal::SimulationEngine::get_result_filename ( ) const
inline

Getter for file name of results as VCD

Returns
the file name

Definition at line 158 of file simulation_engine.h.

References mResultFilename.

◆ get_simulation_input()

virtual SimulationInput* hal::SimulationEngine::get_simulation_input ( ) const
inlinevirtual

Get simulation input

Returns
Pointer to input instance

Reimplemented in hal::NetlistSimulator.

Definition at line 222 of file simulation_engine.h.

References mSimulationInput.

◆ get_state()

int hal::SimulationEngine::get_state ( ) const
inline

State of the engine as integer

Returns
possible state values are Preparing = 2, Running = 1, Done = 0, Failed = -1

Definition at line 93 of file simulation_engine.h.

References mState.

Referenced by hal::PYBIND11_PLUGIN().

◆ get_working_directory()

std::string hal::SimulationEngine::get_working_directory ( ) const

The working directory. Directory is temporary and will be removed when controller gets deleted

Returns
directory path

Definition at line 21 of file simulation_engine.cpp.

References mWorkDir.

Referenced by hal::PYBIND11_PLUGIN(), hal::DummyEngine::setSimulationInput(), hal::verilator::VerilatorEngine::setSimulationInput(), and hal::SimulationProcess::SimulationProcess().

◆ install_saleae_parser()

bool hal::SimulationEngine::install_saleae_parser ( std::string  dirname) const

Copy header and source files so that saleae parser can be compiled into project

Parameters
[in]dirname- Target directory to copy files into.
Returns
true if files copied successfully, false otherwise

Definition at line 42 of file simulation_engine.cpp.

References QDir::absoluteFilePath(), QDir::exists(), hal::ff, QFileInfo::fileName(), QString::fromStdString(), QFile::open(), QIODevice::ReadOnly, QIODevice::write(), and QIODevice::WriteOnly.

◆ name()

std::string hal::SimulationEngine::name ( ) const
inline

Getter for enging name

Returns
name as std::string

Definition at line 75 of file simulation_engine.h.

Referenced by hal::NetlistSimulatorController::create_simulation_engine(), hal::NetlistSimulatorController::persist(), and hal::PYBIND11_PLUGIN().

◆ run()

virtual bool hal::SimulationEngine::run ( NetlistSimulatorController controller,
SimulationLogReceiver logReceiver = nullptr 
)
pure virtual

Must be implemented by derived class

Will be called by controller to start simulation.

Derived classes SimulationEngineEventDriven and SimulationEngineScripted will implement their own run handlers to start either a separate process or a thread

Returns
true if successful, false otherwise.

Referenced by hal::NetlistSimulatorController::run_simulation().

◆ set_engine_property()

void hal::SimulationEngine::set_engine_property ( const std::string &  key,
const std::string &  value 
)
virtual

Set property which can be evaluated by engine

Parameters
keyproperty name
valueproperty value

Definition at line 64 of file simulation_engine.cpp.

References mProperties.

Referenced by hal::NetlistSimulatorController::NetlistSimulatorController(), hal::PYBIND11_PLUGIN(), and hal::NetlistSimulatorController::run_simulation().

◆ set_working_directory()

void hal::SimulationEngine::set_working_directory ( const std::string &  workDir)

Set the working directory. Method should be called by controller only after creating engine instance.

Parameters
[in]workDirThe working directory (should be controller tmp directory)

Definition at line 26 of file simulation_engine.cpp.

References mWorkDir.

Referenced by hal::NetlistSimulatorController::create_simulation_engine().

◆ setResultFilename()

virtual void hal::SimulationEngine::setResultFilename ( const std::string  filename)
inlinevirtual

Set the name of VCD result file. If set engine is requested to produce such a file upon finalize

Parameters
[in]filename- Name of the file to be created.

Definition at line 149 of file simulation_engine.h.

References mResultFilename.

◆ setSimulationInput()

virtual bool hal::SimulationEngine::setSimulationInput ( SimulationInput simInput)
pure virtual

Must be implemented by derived class

Will be called by controller to pass all relevant information to setup the simulation

Parameters
[in]simInputthe input
Returns
true if engine could be prepared successfully with given input, false otherwise.

Implemented in hal::verilator::VerilatorEngine, and hal::DummyEngine.

Referenced by hal::NetlistSimulatorController::run_simulation().

◆ state()

State hal::SimulationEngine::state ( ) const
inline

State of the engine

Returns
possible state values are Preparing, Running, Done, Failed

Definition at line 84 of file simulation_engine.h.

References mState.

Referenced by hal::SimulationThread::run().

Member Data Documentation

◆ mCanShareMemory

bool hal::SimulationEngine::mCanShareMemory
protected

◆ mProperties

std::unordered_map<std::string, std::string> hal::SimulationEngine::mProperties
protected

◆ mRequireClockEvents

bool hal::SimulationEngine::mRequireClockEvents
protected

◆ mResultFilename

std::string hal::SimulationEngine::mResultFilename
protected

◆ mSimulationInput

◆ mState

State hal::SimulationEngine::mState
protected

◆ mWorkDir

std::string hal::SimulationEngine::mWorkDir
protected

Definition at line 65 of file simulation_engine.h.

Referenced by get_working_directory(), and set_working_directory().


The documentation for this class was generated from the following files: