OpenASIP  2.0
Watch.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 Watch.cc
26  *
27  * Definition of Watch class.
28  *
29  * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "Watch.hh"
34 #include "ConditionScript.hh"
35 #include "ExpressionScript.hh"
36 #include "SimulatorConstants.hh"
37 #include "BaseType.hh"
38 #include "Application.hh"
39 #include "SimulatorFrontend.hh"
40 #include "Conversion.hh"
41 
42 /**
43  * Constructor.
44  *
45  * @param frontend Used to fetch the simulation clock.
46  * @param expression The expression watched.
47  */
49  const SimulatorFrontend& frontend,
50  const ExpressionScript& expression) :
51  StopPoint(), expression_(expression), frontend_(frontend),
52  isTriggered_(false), lastCheckedCycle_(0) {
53 }
54 
55 /**
56  * Destructor.
57  */
59 }
60 
61 /**
62  * Copy method for dynamically bound copies.
63  */
64 StopPoint*
65 Watch::copy() const {
66  StopPoint* aCopy = new Watch(frontend_, expression_);
67  if (conditional_) {
68  assert(condition_ != NULL);
69  ConditionScript* conditionCopy = condition_->copy();
70  assert(conditionCopy != NULL);
71  aCopy->setCondition(*conditionCopy);
72  } else {
73  aCopy->removeCondition();
74  }
75  aCopy->setEnabled(enabled_);
79  return aCopy;
80 }
81 
82 /**
83  * Returns the expression.
84  *
85  * @return The expression.
86  */
87 const ExpressionScript&
89  return expression_;
90 }
91 
92 /**
93  * Sets the expression the watch is watching.
94  *
95  * @param expression The new expression.
96  */
97 void
100 }
101 
102 /**
103  * Returns true in case this watch is triggered.
104  *
105  * Returns true in case the expression has changed in current simulation cycle.
106  *
107  * @return The status of the watch.
108  */
109 bool
112  // simulation clock has changed since the last expression check,
113  // let's see if the watch expression value has changed
114  try {
116  } catch (const Exception&) {
117  // for example simulation might not be initialized in every
118  // check so the script throws, we'll assume that no triggering
119  // should happen at that case
120  isTriggered_ = false;
121  }
123  }
124  return isTriggered_;
125 }
126 
127 /**
128  * Prints the description string of the stop point.
129  *
130  * Each subclass overrides this method to construct a descripting string of
131  * itself.
132  */
133 std::string
135  return std::string("watch for expression '") + expression_.script().at(0) +
136  "' " + StopPoint::description();
137 }
138 
StopPoint::conditional_
bool conditional_
Tells whether the breakpoint is conditional or not.
Definition: StopPoint.hh:91
Script::script
virtual std::vector< std::string > script() const
Definition: Script.cc:106
StopPoint::setEnabled
virtual void setEnabled(bool flag)
Definition: StopPoint.cc:63
BaseType.hh
StopPoint::setIgnoreCount
virtual void setIgnoreCount(unsigned int count)
Definition: StopPoint.cc:182
StopPoint::setDisabledAfterTriggered
virtual void setDisabledAfterTriggered(bool flag)
Definition: StopPoint.cc:85
Watch::frontend_
const SimulatorFrontend & frontend_
The simulator frontend which is used to fetch the current PC.
Definition: Watch.hh:68
ConditionScript::copy
virtual ConditionScript * copy() const
Definition: ConditionScript.cc:99
StopPoint::enabled_
bool enabled_
Tells whether the breakpoint is enabled or disabled.
Definition: StopPoint.hh:84
ExpressionScript
Definition: ExpressionScript.hh:44
StopPoint::condition_
ConditionScript * condition_
The condition which is used to determine whether the breakpoint should be fired or not.
Definition: StopPoint.hh:94
ConditionScript.hh
Watch::expression
virtual const ExpressionScript & expression() const
Definition: Watch.cc:88
SimulatorConstants.hh
ConditionScript
Definition: ConditionScript.hh:45
assert
#define assert(condition)
Definition: Application.hh:86
Watch::~Watch
virtual ~Watch()
Definition: Watch.cc:58
Watch::description
virtual std::string description() const
Definition: Watch.cc:134
StopPoint
Definition: StopPoint.hh:53
Conversion.hh
Watch::expression_
ExpressionScript expression_
The expression that is watched.
Definition: Watch.hh:66
Application.hh
Exception
Definition: Exception.hh:54
Watch::Watch
Watch(const SimulatorFrontend &frontend, const ExpressionScript &expression)
Definition: Watch.cc:48
SimulatorFrontend.hh
Watch::copy
virtual StopPoint * copy() const
Definition: Watch.cc:65
StopPoint::deletedAfterTriggered_
bool deletedAfterTriggered_
Tells if the breakpoint is deleted after it is triggered the next time.
Definition: StopPoint.hh:89
Watch::isTriggered_
bool isTriggered_
Flag which tells whether the watch was triggered in current simulation cycle.
Definition: Watch.hh:71
SimulatorFrontend::cycleCount
ClockCycleCount cycleCount() const
Definition: SimulatorFrontend.cc:1194
StopPoint::disabledAfterTriggered_
bool disabledAfterTriggered_
Tells if the breakpoint is disabled after it is triggered the next time.
Definition: StopPoint.hh:87
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
Watch.hh
Watch::setExpression
virtual void setExpression(const ExpressionScript &expression)
Definition: Watch.cc:98
Watch::lastCheckedCycle_
ClockCycleCount lastCheckedCycle_
The simulation clock cycle in which the expression was checked the last time.
Definition: Watch.hh:74
StopPoint::removeCondition
virtual void removeCondition()
Definition: StopPoint.cc:142
StopPoint::ignoreCount_
unsigned int ignoreCount_
The number of times the condition is to be ignored before enabling the breakpoint.
Definition: StopPoint.hh:97
StopPoint::description
virtual std::string description() const =0
Definition: StopPoint.cc:239
StopPoint::setDeletedAfterTriggered
virtual void setDeletedAfterTriggered(bool flag)
Definition: StopPoint.cc:107
ExpressionScript::resultChanged
bool resultChanged()
Definition: ExpressionScript.cc:75
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
StopPoint::setCondition
virtual void setCondition(const ConditionScript &condition)
Definition: StopPoint.cc:131
ExpressionScript.hh
Watch::isTriggered
virtual bool isTriggered() const
Definition: Watch.cc:110