HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
simulation_thread.cpp
Go to the documentation of this file.
5 #include <QProcess>
6 #include <QThread>
7 #include <vector>
8 
9 namespace hal {
10 
12  : QThread(controller), mSimulationInput(simInput), mEngine(engine), mLogChannel(controller->get_name()), mSimulTime(0),
13  mSaleaeDirectoryFilename(controller->get_saleae_directory_filename())
14  {
16  }
17 
18  void SimulationThread::terminateThread(bool success, const char* failedStep)
19  {
20  if (!success)
21  {
22  mEngine->failed();
23  if (failedStep)
24  log_warning(mLogChannel, "simulation engine error during {}.", failedStep);
25  }
26  Q_EMIT threadFinished(success);
27  }
28 
30  {
31  mSimulTime = 0;
32  SaleaeParser sp(mSaleaeDirectoryFilename);
33 
34  for (const Net* net : mSimulationInput->get_input_nets())
35  {
36  void* registerObj = (void*) net;
37  sp.register_callback(net,[this](const void* obj, uint64_t t, int val) {
38  if (t != mSimulTime)
39  {
40  mSimulationInputNetEvent.set_simulation_duration(t - mSimulTime);
41  if (!mEngine->inputEvent(mSimulationInputNetEvent))
42  {
43  mEngine->failed();
44  return;
45  }
46  mSimulTime = t;
47  mSimulationInputNetEvent.clear();
48  }
49  mSimulationInputNetEvent.insert(std::make_pair(static_cast<const Net*>(obj),static_cast<BooleanFunction::Value>(val)));
50  }, registerObj);
51  }
52 
53  while (sp.next_event())
54  {
55  if (mEngine->state()==SimulationEngine::Failed)
56  return terminateThread(false, "run");
57  }
58 
59  terminateThread(mEngine->finalize(), "finalize");
60  }
61 }
Value
represents the type of the node
Definition: net.h:58
The SaleaeParser class is an engine which allows to parse any number of SALEAE files into a sequence ...
Definition: saleae_parser.h:74
bool next_event()
Call to parser to deliver next event via registered callbacks (see above).
bool register_callback(const std::string &name, uint32_t id, std::function< void(void *, uint64_t, int)> callback, void *obj)
Registers callback which gets executed upon next_event()
virtual bool inputEvent(const SimulationInputNetEvent &netEv)=0
const std::unordered_set< const Net * > & get_input_nets() const
void threadFinished(bool success)
SimulationThread(NetlistSimulatorController *controller, const SimulationInput *simInput, SimulationEngineEventDriven *engine)
#define log_warning(channel,...)
Definition: log.h:76
Definition: defines.h:45
Net * net
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)