OpenASIP  2.0
BusTracker.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 BusTracker.cc
26  *
27  * Definition of BusTracker class.
28  *
29  * @author Pekka J��skel�inen 2005 (pjaaskel-no.spam-cs.tut.fi)
30  * @author Henry Linjamäki 2017 (henry.linjamaki-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "BusTracker.hh"
35 #include "Application.hh"
36 #include "SimulationController.hh"
37 #include "SimulatorToolbox.hh"
39 #include "SimulatorFrontend.hh"
40 #include "MachineState.hh"
41 #include "Machine.hh"
42 #include "MathTools.hh"
43 #include "Conversion.hh"
44 
45 #include <algorithm>
46 #include <vector>
47 #include <string>
48 #include <iostream>
49 #include <iomanip>
50 #include <locale>
51 #include <functional>
52 
53 const std::string BusTracker::COLUMN_SEPARATOR = ",";
54 
55 /**
56  * Constructor.
57  *
58  * @param frontend The SimulationFrontend which is used to access simulation
59  * data.
60  * @param traceStream Output stream where the trace data is written to. Takes
61  * ownership of the stream.
62  */
64  SimulatorFrontend& frontend,
65  std::ostream* traceStream) :
66  Listener(), frontend_(frontend),ownsTraceStream_(true),
67  traceStream_(traceStream) {
68  // write the trace data at the end of simulation clock cycle
69  frontend.eventHandler().registerListener(
71 }
72 
73 /**
74  * Constructor.
75  *
76  * @param frontend The SimulationFrontend which is used to access simulation
77  * data.
78  * @param traceStream Output stream where the trace data is written to.
79  */
81  SimulatorFrontend& frontend,
82  std::ostream& traceStream)
83  : Listener(), frontend_(frontend),ownsTraceStream_(false),
84  traceStream_(&traceStream) {
85  frontend.eventHandler().registerListener(
87 }
88 
89 /**
90  * Destructor.
91  */
95  traceStream_->flush();
96  if (ownsTraceStream_) {
97  delete traceStream_;
98  }
99 }
100 
101 /**
102  * Writes bus trace data to the trace stream.
103  *
104  * If any error happens while writing the data, aborts program with
105  * an error message.
106  */
107 void
109 
112 
114 
115  for (int i = 0; i < navigator.count(); ++i) {
116  const std::string busName = navigator.item(i)->name();
117 
118  BusState& bus = frontend_.machineState(0).busState(busName);
119  int columnWidth = (bus.width()+3)/4;
120 
122  if (!bus.isSquashed()) {
123  *traceStream_ << bus.value().hexValue(true);
124  } else {
125  // Squashed values are displayed as zeros.
126  *traceStream_ << std::string(columnWidth, '0');
127  }
128  }
129  *traceStream_ << "\n";
130 }
BusState::width
int width() const
Definition: BusState.cc:96
BusTracker::~BusTracker
virtual ~BusTracker()
Definition: BusTracker.cc:92
SimulatorFrontend::machine
const TTAMachine::Machine & machine() const
Definition: SimulatorFrontend.cc:263
Listener
Definition: Listener.hh:40
BusState
Definition: BusState.hh:48
BusState::isSquashed
bool isSquashed() const
Definition: BusState.cc:88
TTAMachine::Machine::Navigator::count
int count() const
BusTracker::ownsTraceStream_
bool ownsTraceStream_
Definition: BusTracker.hh:70
BusTracker::BusTracker
BusTracker(SimulatorFrontend &frontend, std::ostream *traceStream)
Definition: BusTracker.cc:63
SimulationEventHandler.hh
RegisterState::value
virtual const SimValue & value() const
Definition: RegisterState.cc:92
SimulatorToolbox.hh
Informer::unregisterListener
virtual bool unregisterListener(int event, Listener *listener)
Definition: Informer.cc:104
MachineState::busState
BusState & busState(const std::string &name)
Definition: MachineState.cc:116
Conversion.hh
SimulationEventHandler::SE_CYCLE_END
@ SE_CYCLE_END
Generated before advancing the simulator clock at the end of a simulation cycle.
Definition: SimulationEventHandler.hh:50
Application.hh
Informer::registerListener
virtual bool registerListener(int event, Listener *listener)
Definition: Informer.cc:87
BusTracker.hh
Machine.hh
SimulatorFrontend.hh
SimValue::hexValue
TCEString hexValue(bool noHexIdentifier=false) const
Definition: SimValue.cc:1150
SimulatorFrontend::cycleCount
ClockCycleCount cycleCount() const
Definition: SimulatorFrontend.cc:1194
SimulatorFrontend::eventHandler
SimulationEventHandler & eventHandler()
Definition: SimulatorFrontend.cc:2260
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
BusTracker::traceStream_
std::ostream * traceStream_
Definition: BusTracker.hh:71
SimulatorFrontend::machineState
MachineState & machineState(int core=-1)
Definition: SimulatorFrontend.cc:2138
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
MachineState.hh
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
SimulationController.hh
MathTools.hh
BusTracker::handleEvent
virtual void handleEvent()
Definition: BusTracker.cc:108
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
BusTracker::COLUMN_SEPARATOR
static const std::string COLUMN_SEPARATOR
Definition: BusTracker.hh:67
BusTracker::frontend_
SimulatorFrontend & frontend_
the simulator frontend used to access simulation data
Definition: BusTracker.hh:69