OpenASIP 2.2
Loading...
Searching...
No Matches
TTASimTandem.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file TTASimTandem.cc
26 *
27 * Implementation of a simulator that runs both compiled simulation and
28 * the interpretive (debugging) simulation in parallel and compares the
29 * execution to detect differences in the simulations, which indicate there's
30 * a missimulation bug in one or both of the engines.
31 *
32 * @author Pekka Jääskeläinen 2009 (pjaaskel-no.spam-cs.tut.fi)
33 * @note rating: red
34 */
35
36#include <iostream>
37#include <algorithm>
38#include <boost/format.hpp>
39#include "Application.hh"
40#include "Machine.hh"
41#include "Program.hh"
42#include "SimulatorFrontend.hh"
43#include "RegisterFile.hh"
44#include "SimValue.hh"
45#include "POMDisassembler.hh"
46#include "DisassemblyFUPort.hh"
47#include "Instruction.hh"
48#include "Procedure.hh"
49
50/**
51 * Simulates the given program+machine in "tandem" with the two
52 * simulation engines.
53 */
54void
58
59 // initialize both simulation engines
61 interp.loadMachine(machine);
62 interp.loadProgram(program);
63
65
66 // leave the compile simulation engine files at /tmp
68
69 compiled.loadMachine(machine);
70 compiled.loadProgram(program);
71 // reduce startup time by using dynamic compilation of the simulation
72 // engine
73 compiled.setStaticCompilation(false);
74
75
78
79 ClockCycleCount simulatedCycles = 0;
80 while (!compiled.hasSimulationEnded()) {
81 ClockCycleCount stepping;
82 try {
83 compiled.step(1);
84
85 // the compiled simulator compiled BB at a time so we need to
86 // ask it how many cycle to advance the cycle level interp. engine
87 // to get to the same position in the simulation
88 stepping =
89 compiled.cycleCount() - simulatedCycles;
90
91 interp.step(stepping);
92 simulatedCycles += stepping;
93 } catch (const Exception& e) {
94 std::cerr << "Simulation error: " << e.errorMessage() << std::endl;
95 return;
96
97 }
98
99 if (!compiled.compareState(interp, &std::cerr))
100 return;
101
102 // print out the cycle count after simulating at least 1M cycles
103 if (simulatedCycles / 1000000 > (simulatedCycles - stepping) / 1000000)
104 std::cout
105 << "simulated " << simulatedCycles << " cycles" << std::endl;
106 }
107
108 std::cout
109 << "stop reasons:" << std::endl
110 << "* compiled engine:" << std::endl;
111 for (unsigned i = 0; i < compiled.stopReasonCount(); ++i) {
112 std::cout << "** " << compiled.stopReason(i) << std::endl;
113 }
114 std::cout
115 << "* interp. engine:" << std::endl;
116 for (unsigned i = 0; i < interp.stopReasonCount(); ++i) {
117 std::cout << "** " << interp.stopReason(i) << std::endl;
118 }
119
120}
121
122int
123main(int argc, char* argv[]) {
124
126
127 if (argc < 3) {
128 std::cerr << "usage: ttasim-tandem machine.adf program.tpef";
129
130 }
131
132 try {
138
139 delete machine; machine = NULL;
140 delete program; program = NULL;
141 } catch (const Exception& e) {
142 std::cerr << e.errorMessage() << std::endl;
143 return EXIT_FAILURE;
144 }
145 return EXIT_SUCCESS;
146}
#define assert(condition)
TTAMachine::Machine * machine
the architecture definition of the estimated processor
find Finds info of the inner loops in the program
CycleCount ClockCycleCount
Alias for ClockCycleCount.
int main(int argc, char *argv[])
void tandemSimulate(TTAMachine::Machine &machine, TTAProgram::Program &program)
static void initialize()
std::string errorMessage() const
Definition Exception.cc:123
bool hasSimulationEnded() const
bool compareState(SimulatorFrontend &other, std::ostream *differences=NULL)
@ SIM_COMPILED
Compiled, faster simulation.
@ SIM_NORMAL
Default, interpreted simulation (debugging engine).
virtual void loadMachine(const std::string &fileName)
ClockCycleCount cycleCount() const
bool isSimulationInitialized() const
unsigned int stopReasonCount() const
StopReason stopReason(unsigned int index) const
void setStaticCompilation(bool value)
void setCompiledSimulationLeaveDirty(bool dirty)
virtual void loadProgram(const std::string &fileName)
virtual void step(double count=1)
static Machine * loadFromADF(const std::string &adfFileName)
Definition Machine.cc:899
static Program * loadFromTPEF(const std::string &tpefFileName, const TTAMachine::Machine &theMachine)
Definition Program.cc:1112