orca-sim
Simulator.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * This file is part of project ORCA. More information on the project
3  * can be found at the following repositories at GitHub's website.
4  *
5  * http://https://github.com/andersondomingues/orca-sim
6  * http://https://github.com/andersondomingues/orca-software
7  * http://https://github.com/andersondomingues/orca-mpsoc
8  * http://https://github.com/andersondomingues/orca-tools
9  *
10  * Copyright (C) 2018-2020 Anderson Domingues, <ti.andersondomingues@gmail.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 ******************************************************************************/
26 #ifndef ORCASIM_MODELING_INCLUDE_SIMULATOR_HPP_
27 #define ORCASIM_MODELING_INCLUDE_SIMULATOR_HPP_
28 
29 #include <vector>
30 #include <string>
31 
32 #include "TimedModel.hpp"
33 #include "UntimedModel.hpp"
34 #include "Engine.hpp"
35 #include "Signal.hpp"
36 #include "SimulationTime.hpp"
37 
43 
44 
45 namespace orcasim::modeling {
46 
47 static void sig_handler(int _); // interruption handler
48 
50  RUNNING, // application is running
51  INTERRUPTED, // app have been interrupted once
52  ABORTED // app have been interrupted twice, aborting
53 };
54 
55 class Simulator {
56  private:
57  std::chrono::high_resolution_clock::time_point t1, t2; // time measurement
58  std::vector<std::string> _params; // argc+argv
59 
60  Engine _engine; // the simulation engine
61 
63 
65 
66  public:
67  static void SetInterruptionStatus(SimulatorInterruptionStatus status);
68  static SimulatorInterruptionStatus GetInterruptionStatus();
69 
70  Simulator(int argc, char** argv);
71  Simulator();
72 
73  void virtual Startup() = 0; // model instantiation
74  void virtual Schedule() = 0;
75  void virtual Simulate(); // simulation
76  void virtual Report() = 0; // statistics
77 
78  void Register(TimedModel* m);
79  void Register(TimedModel* m, SimulationTime t);
80 
81  int GetExitStatus();
82  void SetExitStatus(int status);
83 
84  std::string GetParam(int index);
85 };
86 
87 } // namespace orcasim::modeling
88 #endif // ORCASIM_MODELING_INCLUDE_SIMULATOR_HPP_
The Signal class models a generic bus of width equals to the sizeof(T)
Definition: Signal.hpp:45
This class models a TimedModel.
Definition: TimedModel.hpp:42
static void sig_handler(int _)
std::chrono::high_resolution_clock::time_point t2
Definition: Simulator.hpp:57
uint32_t SimulationTime
This class implements an event queue to schedule and execute hardware modules.
Definition: Engine.hpp:46
Untimed models represent hardware models whose clock period is irrelevant for the simulation...
std::vector< std::string > _params
Definition: Simulator.hpp:58
static volatile SimulatorInterruptionStatus _interruption_status
Definition: Simulator.hpp:64