OpenASIP
2.0
src
applibs
Simulator
ConditionCommand.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 ConditionCommand.cc
26
*
27
* Implementation of ConditionCommand class
28
*
29
* @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30
* @note rating: red
31
*/
32
33
#include "
ConditionCommand.hh
"
34
#include "
Application.hh
"
35
#include "
FileSystem.hh
"
36
#include "
SimulatorFrontend.hh
"
37
#include "
SimulatorInterpreterContext.hh
"
38
#include "
Exception.hh
"
39
#include "
SimulatorToolbox.hh
"
40
#include "
SimulatorTextGenerator.hh
"
41
#include "
SimValue.hh
"
42
#include "
StopPointManager.hh
"
43
#include "
TclConditionScript.hh
"
44
45
#include <iostream>
46
47
/**
48
* Constructor.
49
*
50
* Sets the name of the command to the base class.
51
*/
52
ConditionCommand::ConditionCommand
() :
53
SimControlLanguageCommand
(
"condition"
) {
54
}
55
56
/**
57
* Destructor.
58
*
59
* Does nothing.
60
*/
61
ConditionCommand::~ConditionCommand
() {
62
}
63
64
/**
65
* Executes the "condition" command.
66
*
67
* Modifies conditions of breakpoints.
68
*
69
* @param arguments The handle of the breakpoint of which condition to modify.
70
* @return True in case simulation is initialized and arguments are ok.
71
* @exception NumberFormatException Is never thrown by this command.
72
* @todo Use the count for the step.
73
*/
74
bool
75
ConditionCommand::execute
(
const
std::vector<DataObject>& arguments) {
76
if
(!
checkArgumentCount
(arguments.size() - 1, 1, 1)) {
77
return
false
;
78
}
79
80
if
(!
checkSimulationStopped
()) {
81
if
(!
checkSimulationInitialized
()) {
82
return
false
;
83
}
84
}
85
86
if
(arguments.size() == 2) {
87
if
(!
checkIntegerArgument
(arguments[1])) {
88
return
false
;
89
}
90
const
int
breakpointHandle = arguments[1].integerValue();
91
try
{
92
StopPointManager
& stopPointManager =
93
simulatorFrontend
().
stopPointManager
();
94
stopPointManager.
stopPointWithHandleConst
(breakpointHandle);
95
96
TclConditionScript
condition(NULL,
""
);
97
if
(!
askConditionFromUser
(condition)) {
98
return
false
;
99
}
100
assert
(condition.
script
().size() > 0);
101
if
(condition.
script
().at(0) ==
"1"
) {
102
stopPointManager.
removeCondition
(breakpointHandle);
103
}
else
{
104
stopPointManager.
setCondition
(breakpointHandle, condition);
105
}
106
printBreakpointInfo
(breakpointHandle);
107
}
catch
(
const
InstanceNotFound
&) {
108
interpreter
()->
setError
(
109
SimulatorToolbox::textGenerator
().text(
110
Texts::TXT_BREAKPOINT_NOT_FOUND
).str());
111
return
false
;
112
}
113
114
115
}
116
return
true
;
117
}
118
119
/**
120
* Returns the help text for this command.
121
*
122
* Help text is searched from SimulatorTextGenerator.
123
*
124
* @return The help text.
125
* @todo Use SimulatorTextGenerator to get the help text.
126
*/
127
std::string
128
ConditionCommand::helpText
()
const
{
129
return
SimulatorToolbox::textGenerator
().
text
(
130
Texts::TXT_INTERP_HELP_CONDITION
).str();
131
}
StopPointManager.hh
CustomCommand::checkArgumentCount
bool checkArgumentCount(int argumentCount, int minimum, int maximum)
Definition:
CustomCommand.cc:82
TclConditionScript.hh
Texts::TXT_BREAKPOINT_NOT_FOUND
@ TXT_BREAKPOINT_NOT_FOUND
Definition:
SimulatorTextGenerator.hh:186
FileSystem.hh
SimControlLanguageCommand::checkSimulationStopped
bool checkSimulationStopped()
Definition:
SimControlLanguageCommand.cc:135
SimulatorInterpreterContext.hh
Exception.hh
TclConditionScript
Definition:
TclConditionScript.hh:50
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition:
TextGenerator.cc:94
ConditionCommand::helpText
virtual std::string helpText() const
Definition:
ConditionCommand.cc:128
ConditionCommand::execute
virtual bool execute(const std::vector< DataObject > &arguments)
Definition:
ConditionCommand.cc:75
StopPointManager::setCondition
void setCondition(unsigned int handle, const ConditionScript &condition)
Definition:
StopPointManager.cc:296
Texts::TXT_INTERP_HELP_CONDITION
@ TXT_INTERP_HELP_CONDITION
Help text for command "condition" of the CLI.
Definition:
SimulatorTextGenerator.hh:91
assert
#define assert(condition)
Definition:
Application.hh:86
CustomCommand::checkIntegerArgument
bool checkIntegerArgument(const DataObject &argument)
Definition:
CustomCommand.cc:110
ConditionCommand::~ConditionCommand
virtual ~ConditionCommand()
Definition:
ConditionCommand.cc:61
SimulatorToolbox.hh
StopPointManager::stopPointWithHandleConst
const StopPoint & stopPointWithHandleConst(unsigned int handle) const
Definition:
StopPointManager.cc:248
SimControlLanguageCommand::askConditionFromUser
bool askConditionFromUser(TclConditionScript &target)
Definition:
SimControlLanguageCommand.cc:513
StopPointManager
Definition:
StopPointManager.hh:50
Application.hh
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition:
SimulatorToolbox.cc:75
SimulatorTextGenerator.hh
ConditionCommand::ConditionCommand
ConditionCommand()
Definition:
ConditionCommand.cc:52
SimControlLanguageCommand::checkSimulationInitialized
bool checkSimulationInitialized()
Definition:
SimControlLanguageCommand.cc:88
SimulatorFrontend.hh
TclConditionScript::script
virtual std::vector< std::string > script() const
Definition:
TclConditionScript.cc:70
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ConditionCommand.hh
StopPointManager::removeCondition
void removeCondition(unsigned int handle)
Definition:
StopPointManager.cc:308
SimValue.hh
ScriptInterpreter::setError
virtual void setError(bool state)
Definition:
ScriptInterpreter.cc:205
SimControlLanguageCommand
Definition:
SimControlLanguageCommand.hh:63
SimControlLanguageCommand::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition:
SimControlLanguageCommand.cc:214
SimulatorFrontend::stopPointManager
StopPointManager & stopPointManager()
Definition:
SimulatorFrontend.cc:2108
InstanceNotFound
Definition:
Exception.hh:304
SimControlLanguageCommand::printBreakpointInfo
virtual bool printBreakpointInfo(unsigned int breakpointHandle)
Definition:
SimControlLanguageCommand.cc:678
Generated by
1.8.17