OpenASIP 2.2
Loading...
Searching...
No Matches
StopPointManager.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 StopPointManager.cc
26 *
27 * Definition of StopPointManager class.
28 *
29 * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34#include <vector>
35#include <map>
36
37#include "Exception.hh"
38#include "StopPointManager.hh"
41#include "MapTools.hh"
42#include "Application.hh"
43
44using std::string;
45using std::vector;
46using std::map;
47using std::make_pair;
48
49
50/**
51 * Constructor.
52 *
53 * @param controller The simulation controller the stop points should use to
54 * stop the simulation.
55 */
57 TTASimulationController& controller,
58 SimulationEventHandler& eventHandler) :
59 handleCount_(0), lastStopCycle_(0), controller_(controller),
60 eventHandler_(eventHandler) {
61}
62
63
64/**
65 * Destructor.
66 */
70
71
72/**
73 * Function that adds a new stop point.
74 *
75 * Copies the given stop point.
76 *
77 * @param stopPoint The stop point to be added.
78 * @return Handle for the added stop point.
79 */
80unsigned int
82
83 StopPoint* toAdd = stopPoint.copy();
84
86
87 stopPoints_.insert(make_pair(handleCount_, toAdd));
88 handles_.push_back(handleCount_);
89
90 toAdd->setEnabled(true);
91
92 if (stopPoints_.size() == 1) {
93 // this is the first added stop point, enable event
94 // listening
97 }
98 return handleCount_;
99}
100
101
102/**
103 * Remove a stop point by the given handle.
104 *
105 * @param handle The handle of the stop point to be removed.
106 */
107void
109 StopPoint* stopPoint = findStopPoint(handle);
110
111 StopPointIndex::iterator findResult = stopPoints_.find(handle);
112 stopPoints_.erase(findResult);
113
114 for (HandleContainer::iterator i = handles_.begin(); i != handles_.end();
115 i++) {
116 if ((*i) == handle) {
117 handles_.erase(i);
118 break;
119 }
120 }
121
122 delete stopPoint;
123 stopPoint = NULL;
124
125 if (stopPoints_.size() == 0) {
126 // this was the last stop point, disable event listening
129 }
130}
131
132/**
133 * Removes all stop points.
134 */
135void
137 while (handles_.size() > 0) {
139 }
140}
141
142
143/**
144 * Enables the stop point by the given handle.
145 *
146 * @param handle The handle to identify the stop point.
147 */
148void
149StopPointManager::enable(unsigned int handle) {
150 findStopPoint(handle)->setEnabled(true);
151}
152
153/**
154 * Enables all stop points.
155 */
156void
158 for (unsigned int i = 0; i < handles_.size(); i++) {
159 enable(handles_.at(i));
160 }
161}
162
163
164/**
165 * Enables the stop point by the given handle and sets it to be deleted
166 * after being triggered.
167 *
168 * @param handle The handle for the stop point.
169 * @throw InstanceNotFound if the given handle cannot be found.
170 */
171void
173 StopPoint* stopPoint = findStopPoint(handle);
174
175 stopPoint->setEnabled(true);
176 stopPoint->setDeletedAfterTriggered(true);
177}
178
179/**
180 * Enables the stop point by the given handle and sets it to be disabled
181 * after being triggered.
182 *
183 * @param handle The handle for the stop point.
184 * @throw InstanceNotFound if the given handle cannot be found.
185 */
186void
188 StopPoint* stopPoint = findStopPoint(handle);
189
190 stopPoint->setEnabled(true);
191 stopPoint->setDisabledAfterTriggered(true);
192}
193
194/**
195 * Disables the stop point by the given handle.
196 *
197 * @param handle The handle for the stop point.
198 */
199void
200StopPointManager::disable(unsigned int handle) {
201 findStopPoint(handle)->setEnabled(false);
202}
203
204/**
205 * Disables all stop oints.
206 */
207void
209 for (unsigned int i = 0; i < handles_.size(); i++) {
210 disable(handles_.at(i));
211 }
212}
213
214
215/**
216 * Returns the handle of the stop point by the given index.
217 *
218 * The index is not a direct index to the container used to store stop points,
219 * but more just a way to go through all of the stop points in the manager.
220 * A stop point may not have the same index every call.
221 *
222 * All of the stop points can be accessed by going through the stop points
223 * with the indices between 0 and stopPointCount - 1, inclusive. The
224 * stop points are in no particular order.
225 *
226 * @param index The index.
227 * @return A Copy of the stop point by the given index.
228 * @throw OutOfRange If there is no stop point by the given index.
229 */
230unsigned int
232 if (index < stopPointCount()) {
233 return handles_.at(index);
234 } else {
235 /// @todo textgenerator, to be displayed in the UI.
236 string msg = "No stop point found by the given index.";
237 throw OutOfRange(__FILE__, __LINE__, __func__, msg);
238 }
239}
240/**
241 * Returns the stop point with the given handle.
242 *
243 * @param handle The handle.
244 * @return Stop point with the given handle,
245 * @throw InstanceNotFound If there is no stop point with the given handle.
246 */
247const StopPoint&
249 StopPointIndex::const_iterator containerEnd = stopPoints_.end();
250 StopPointIndex::const_iterator findResult = stopPoints_.find(handle);
251
252 if (findResult == containerEnd) {
253 /// @todo textgenerator, to be displayed in the UI.
254 std::string msg = "No stop point found by the given handle.";
255 throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
256 } else {
257 return *findResult->second;
258 }
259}
260
261/**
262 * Returns the current number of stop points in the manager.
263 *
264 * Can be used to access all stop points in the manager.
265 *
266 * @return The number of stop points in the manager.
267 */
268unsigned int
270 return handles_.size();
271}
272
273
274/**
275 * Sets the number of times the stop point by the given handle should not
276 * be triggered when the condition is met.
277 *
278 * @param handle The handle for the stop point.
279 * @param count The number of times the stop point should be ignored.
280 * @exception InstanceNotFound If no stop point with given handle is found.
281 */
282void
283StopPointManager::setIgnore(unsigned int handle, unsigned int count) {
284 findStopPoint(handle)->setIgnoreCount(count);
285}
286
287/**
288 * Sets the condition of triggering for the stop point by the given handle.
289 *
290 * @param handle The handle for the stop point.
291 * @param condition The condition to be used to determine if the stop point
292 * should be fired.
293 * @exception InstanceNotFound If no stop point with given handle is found.
294 */
295void
297 unsigned int handle, const ConditionScript& condition) {
298 findStopPoint(handle)->setCondition(condition);
299}
300
301/**
302 * Removes the condition of triggering of the stop point by the given handle.
303 *
304 * @param handle The handle for the stop point.
305 * @exception InstanceNotFound If no stop point with given handle is found.
306 */
307void
310}
311
312/**
313 * Tries to find a stop point by the given handle. If no such stop point is
314 * found, throws an exception.
315 *
316 * @param handle The handle for the stop point.
317 * @exception InstanceNotFound If no stop point with given handle is found.
318 */
321 StopPointIndex::iterator containerEnd = stopPoints_.end();
322 StopPointIndex::iterator findResult = stopPoints_.find(handle);
323
324 if (findResult == containerEnd) {
325 /// @todo textgenerator, to be displayed in the UI.
326 string msg = "No stop point found by the given handle.";
327 throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
328 } else {
329 return findResult->second;
330 }
331}
332
333/**
334 * Returns the handle of a stop causing stop point with given index in the
335 * container of stop causing stop points.
336 *
337 * Stop causing stop point is a stop point that caused the latest stop of
338 * simulator.
339 *
340 * @param index Index of the stop point in the container.
341 * @return the handle of the stop point.
342 * @exception OutOfRange
343 */
344unsigned int
345StopPointManager::stopCausingStopPoint(unsigned int index) const {
346 unsigned int count = 0;
347 for (StopPointIndex::const_iterator i = stopPoints_.begin();
348 i != stopPoints_.end(); ++i) {
349 if ((*i).second->isTriggered()) {
350 if (count == index)
351 return (*i).first;
352 ++count;
353 }
354 }
355 throw OutOfRange(
356 __FILE__, __LINE__, __func__, "Stop point index out of range.");
357}
358
359/**
360 * Returns the count of stop causing stop points.
361 *
362 * Stop causing stop point is a stop point that caused the latest stop of
363 * simulator.
364 *
365 * @return the count of stop points.
366 */
367unsigned int
370 return 0;
371 }
372 std::size_t count = 0;
373 for (StopPointIndex::const_iterator i = stopPoints_.begin();
374 i != stopPoints_.end(); ++i) {
375 if ((*i).second->isTriggered())
376 ++count;
377 }
378 return count;
379}
380
381
382/**
383 * Stops simulation if there is at least one stop point requesting it.
384 *
385 * Receives SE_NEW_INSTRUCTION events.
386 */
387void
389
390 // find all the stop points watching the new instruction address
391 StopPointIndex::iterator i = stopPoints_.begin();
392 HandleContainer toBeDeletedStopPoints;
393 while (i != stopPoints_.end()) {
394
395 StopPoint& stopPoint = *(*i).second;
396 const int handle = (*i).first;
397 if (stopPoint.isEnabled() && stopPoint.isTriggered()) {
398 // we found a stop point that is triggered at this clock cycle
399
400 if (stopPoint.ignoreCount() == 0 && stopPoint.isConditionOK()) {
401
404 if (stopPoint.isDisabledAfterTriggered()) {
405 stopPoint.setEnabled(false);
406 }
407
408 if (stopPoint.isDeletedAfterTriggered()) {
409 toBeDeletedStopPoints.push_back(handle);
410 }
411
412 } else if (stopPoint.isConditionOK()) {
413 // decrease the ignore count only if the (possible) condition
414 // of the breakpoint is also true
415 stopPoint.decreaseIgnoreCount();
416 }
417 }
418 ++i;
419 }
420
421 // delete stop points that wanted to be deleted after triggered
422 for (size_t i = 0; i < toBeDeletedStopPoints.size(); ++i) {
423 deleteStopPoint(toBeDeletedStopPoints[i]);
424 }
425}
426
#define __func__
@ SRE_BREAKPOINT
Stopped because of at least one breakpoint.
virtual bool unregisterListener(int event, Listener *listener)
Definition Informer.cc:104
virtual bool registerListener(int event, Listener *listener)
Definition Informer.cc:87
static void deleteAllValues(MapType &aMap)
@ SE_NEW_INSTRUCTION
Generated before executing a new instructon.
StopPointIndex stopPoints_
The stop points.
std::vector< unsigned int > HandleContainer
The handle storage.
void disable(unsigned int handle)
unsigned int handleCount_
Represents the next free handle.
void enableOnceAndDisable(unsigned int handle)
TTASimulationController & controller_
The simulation controller to use to stop the simulation.
virtual ~StopPointManager()
unsigned int stopPointCount()
void enable(unsigned int handle)
unsigned int stopCausingStopPointCount() const
ClockCycleCount lastStopCycle_
The clock cycle in which simulation was stopped last.
StopPointManager(TTASimulationController &controller, SimulationEventHandler &eventHandler)
void enableOnceAndDelete(unsigned int handle)
unsigned int stopCausingStopPoint(unsigned int index) const
void removeCondition(unsigned int handle)
void deleteStopPoint(unsigned int handle)
SimulationEventHandler & eventHandler_
The event handler to use to register stop points to.
unsigned int add(const StopPoint &stopPoint)
HandleContainer handles_
The stop point handles.
StopPoint * findStopPoint(unsigned int handle)
void setCondition(unsigned int handle, const ConditionScript &condition)
const StopPoint & stopPointWithHandleConst(unsigned int handle) const
void setIgnore(unsigned int handle, unsigned int count)
unsigned int stopPointHandle(unsigned int index)
virtual StopPoint * copy() const =0
virtual bool isDisabledAfterTriggered() const
Definition StopPoint.cc:97
virtual bool isTriggered() const =0
virtual void removeCondition()
Definition StopPoint.cc:142
virtual bool isEnabled() const
Definition StopPoint.cc:73
virtual void setDeletedAfterTriggered(bool flag)
Definition StopPoint.cc:107
virtual bool isConditionOK()
Definition StopPoint.cc:215
virtual void setEnabled(bool flag)
Definition StopPoint.cc:63
virtual void decreaseIgnoreCount()
Definition StopPoint.cc:201
virtual void setCondition(const ConditionScript &condition)
Definition StopPoint.cc:131
virtual bool isDeletedAfterTriggered() const
Definition StopPoint.cc:119
virtual unsigned int ignoreCount() const
Definition StopPoint.cc:193
virtual void setDisabledAfterTriggered(bool flag)
Definition StopPoint.cc:85
virtual void setIgnoreCount(unsigned int count)
Definition StopPoint.cc:182
virtual void prepareToStop(StopReason reason)
virtual ClockCycleCount clockCount() const