OpenASIP
2.0
src
applibs
Simulator
ProgCommand.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 ProgCommand.cc
26
*
27
* Implementation of ProgCommand class
28
*
29
* @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30
* @note rating: red
31
*/
32
33
#include "
ProgCommand.hh
"
34
#include "
Application.hh
"
35
#include "
FileSystem.hh
"
36
#include "
SimulatorFrontend.hh
"
37
#include "
SimulatorInterpreterContext.hh
"
38
#include "
SimulatorToolbox.hh
"
39
#include "
Exception.hh
"
40
#include "
SimulatorTextGenerator.hh
"
41
#include "
SimControlLanguageCommand.hh
"
42
43
/**
44
* Constructor.
45
*
46
* Sets the name of the command to the base class.
47
*/
48
ProgCommand::ProgCommand
() :
SimControlLanguageCommand
(
"prog"
) {
49
}
50
51
/**
52
* Destructor.
53
*
54
* Does nothing.
55
*/
56
ProgCommand::~ProgCommand
() {
57
}
58
59
/**
60
* Executes the "prog" command.
61
*
62
* Loads a new program file using the SimulatorFrontend.
63
*
64
* @param arguments Filename is given as argument to the command.
65
* @return True if loading the program was successful.
66
* @exception NumberFormatException Is never thrown by this command.
67
*
68
*/
69
bool
70
ProgCommand::execute
(
const
std::vector<DataObject>& arguments) {
71
assert
(
interpreter
() != NULL);
72
73
SimulatorTextGenerator
& textGen =
SimulatorToolbox::textGenerator
();
74
if
(arguments.size() < 2) {
75
DataObject
* errorMessage =
new
DataObject
();
76
errorMessage->
setString
(
77
textGen.
text
(
Texts::TXT_NO_FILENAME_DEFINED
).str());
78
interpreter
()->
setResult
(errorMessage);
79
return
false
;
80
}
81
82
if
(arguments.size() > 2) {
83
DataObject
* errorMessage =
new
DataObject
();
84
errorMessage->
setString
(
85
textGen.
text
(
Texts::TXT_ONLY_ONE_FILENAME_EXPECTED
).str());
86
interpreter
()->
setResult
(errorMessage);
87
return
false
;
88
}
89
90
SimulatorInterpreterContext
& interpreterContext =
91
dynamic_cast<
SimulatorInterpreterContext
&
>
(
interpreter
()->
context
());
92
93
SimulatorFrontend
&
simulatorFrontend
=
94
interpreterContext.
simulatorFrontend
();
95
96
try
{
97
const
std::string fileName =
98
FileSystem::expandTilde
(arguments.at(1).stringValue());
99
simulatorFrontend
.
loadProgram
(fileName);
100
}
catch
(
const
Exception
& e) {
101
DataObject
* errorMessage =
new
DataObject
();
102
errorMessage->
setString
(e.
errorMessage
());
103
interpreter
()->
setResult
(errorMessage);
104
return
false
;
105
}
106
107
if
(
simulatorFrontend
.
automaticFinishImpossible
())
108
outputStream
()
109
<< textGen.
text
(
Texts::TXT_AUTOMATIC_FINISH_IMPOSSIBLE
).str()
110
<< std::endl;
111
112
return
true
;
113
}
114
115
/**
116
* Returns the help text for this command.
117
*
118
* Help text is searched from SimulatorTextGenerator.
119
*
120
* @return The help text.
121
*/
122
std::string
123
ProgCommand::helpText
()
const
{
124
return
SimulatorToolbox::textGenerator
().
text
(
125
Texts::TXT_INTERP_HELP_PROG
).str();
126
}
127
SimulatorInterpreterContext
Definition:
SimulatorInterpreterContext.hh:45
SimControlLanguageCommand::outputStream
virtual std::ostream & outputStream()
Definition:
SimControlLanguageCommand.cc:351
FileSystem.hh
SimulatorInterpreterContext.hh
Exception.hh
DataObject
Definition:
DataObject.hh:50
SimulatorInterpreterContext::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition:
SimulatorInterpreterContext.cc:61
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition:
TextGenerator.cc:94
Texts::TXT_ONLY_ONE_FILENAME_EXPECTED
@ TXT_ONLY_ONE_FILENAME_EXPECTED
Definition:
TextGenerator.hh:62
ProgCommand::helpText
virtual std::string helpText() const
Definition:
ProgCommand.cc:123
assert
#define assert(condition)
Definition:
Application.hh:86
SimulatorToolbox.hh
SimulatorTextGenerator
Definition:
SimulatorTextGenerator.hh:41
ProgCommand.hh
Application.hh
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition:
SimulatorToolbox.cc:75
SimulatorTextGenerator.hh
SimulatorFrontend::loadProgram
virtual void loadProgram(const std::string &fileName)
Definition:
SimulatorFrontend.cc:299
Exception
Definition:
Exception.hh:54
FileSystem::expandTilde
static std::string expandTilde(const std::string &stringWithTilde)
Definition:
FileSystem.cc:217
SimulatorFrontend.hh
Exception::errorMessage
std::string errorMessage() const
Definition:
Exception.cc:123
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition:
ScriptInterpreter.cc:128
ProgCommand::~ProgCommand
virtual ~ProgCommand()
Definition:
ProgCommand.cc:56
Texts::TXT_AUTOMATIC_FINISH_IMPOSSIBLE
@ TXT_AUTOMATIC_FINISH_IMPOSSIBLE
Definition:
SimulatorTextGenerator.hh:203
Texts::TXT_NO_FILENAME_DEFINED
@ TXT_NO_FILENAME_DEFINED
Definition:
TextGenerator.hh:61
SimControlLanguageCommand
Definition:
SimControlLanguageCommand.hh:63
SimControlLanguageCommand.hh
DataObject::setString
virtual void setString(std::string value)
Definition:
DataObject.cc:130
SimControlLanguageCommand::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition:
SimControlLanguageCommand.cc:214
SimulatorFrontend
Definition:
SimulatorFrontend.hh:89
ScriptInterpreter::context
virtual InterpreterContext & context() const =0
Texts::TXT_INTERP_HELP_PROG
@ TXT_INTERP_HELP_PROG
Help text for command "prog" of the CLI.
Definition:
SimulatorTextGenerator.hh:59
ProgCommand::ProgCommand
ProgCommand()
Definition:
ProgCommand.cc:48
ProgCommand::execute
virtual bool execute(const std::vector< DataObject > &arguments)
Definition:
ProgCommand.cc:70
SimulatorFrontend::automaticFinishImpossible
bool automaticFinishImpossible() const
Definition:
SimulatorFrontend.cc:2230
Generated by
1.8.17