OpenASIP  2.0
SimulatorCmdLineOptions.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 SimulatorCmdLineOptions.cc
26  *
27  * Declaration of SimulatorCmdLineOptions.
28  *
29  * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30  * @author Viljami Korhonen 2007 (viljami.korhonen-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include <iostream>
35 
36 #include "SimulatorToolbox.hh"
38 #include "SimulatorConstants.hh"
39 #include "CmdLineOptions.hh"
41 
42 /// Long switch string for setting the debug mode.
43 const std::string SWL_DEBUG_MODE = "debugmode";
44 /// Short switch string for setting the debug mode.
45 const std::string SWS_DEBUG_MODE = "d";
46 
47 /// Long switch string for giving a script to be executed.
48 const std::string SWL_EXECUTE_SCRIPT = "execute-script";
49 /// Short switch string for giving a script to be executed.
50 const std::string SWS_EXECUTE_SCRIPT= "e";
51 
52 /// Long switch string for giving a machine file.
53 const std::string SWL_MACHINE_TO_LOAD = "adf";
54 /// Short switch string for giving a machine file.
55 const std::string SWS_MACHINE_TO_LOAD= "a";
56 
57 /// Long switch string for giving the program file
58 const std::string SWL_PROGRAM_TO_LOAD = "program";
59 /// Short switch string for giving the program file
60 const std::string SWS_PROGRAM_TO_LOAD= "p";
61 
62 /// Long switch string for the fast simulation
63 const std::string SWL_FAST_SIM = "quick";
64 /// Short switch string for the fast simulation
65 const std::string SWS_FAST_SIM= "q";
66 
67 /// Long switch string for the custom remote debugger target
68 const std::string SWL_CUSTOM_DBG = "custom";
69 /// Short switch string for the custom remote debugger target
70 const std::string SWS_CUSTOM_DBG = "c";
71 
72 /// Long switch string for the TCE builtin remote debugger target
73 const std::string SWL_REMOTE_DBG = "remote";
74 /// Short switch string for the TCE builtin remote debugger target
75 const std::string SWS_REMOTE_DBG = "r";
76 
77 /**
78  * Constructor.
79  *
80  * @todo Use textgenerator in the help texts.
81  */
83  addOption(
85  SWL_DEBUG_MODE, "starts simulator in debugging mode (default), "
86  "use --no-debugmode to disable",
88  addOption(
90  SWL_EXECUTE_SCRIPT, "executes the given string as a script in the "
91  "simulator control language script interpreter, "
92  "e.g. -e \"stepi 10000\" executes simulation for 10000 cycles",
94 
95  addOption(
97  SWL_MACHINE_TO_LOAD, "sets the machine file (.adf) to be loaded.",
99 
100  addOption(
102  SWL_PROGRAM_TO_LOAD, "sets the program file to be loaded.",
104 
105  addOption(
107  SWL_FAST_SIM, "uses the fast simulation engine.",
108  SWS_FAST_SIM));
109 
110  addOption(
112  SWL_REMOTE_DBG, "connect to a remote debugging interface on an FPGA or ASIC.",
113  SWS_REMOTE_DBG));
114 
115  addOption(
117  SWL_CUSTOM_DBG, "connect to a custom remote debugger (if implemented).",
118  SWS_CUSTOM_DBG));
119 }
120 
121 /**
122  * Destructor.
123  */
125 }
126 
127 /**
128  * Prints the version of the program.
129  */
130 void
132  std::cout << SIM_CLI_TITLE << " " << Application::TCEVersionString()
133  << std::endl;
134 }
135 
136 /**
137  * Prints the help menu of the program.
138  *
139  * @todo Implement using SimulatorTextGenerator.
140  */
141 void
143  printVersion();
144  std::cout << std::endl << SimulatorToolbox::textGenerator().text(
145  Texts::TXT_CMD_LINE_HELP).str() << std::endl;
147 }
148 
149 
150 /**
151  * Returns true if Simulator should be started in debugging mode.
152  *
153  * If no value is given in the parsed command line, default one is returned.
154  *
155  * @return True if Simulator should be started in debugging mode.
156  */
157 bool
159  if (!optionGiven(SWL_DEBUG_MODE)) {
160  return true;
161  }
163 }
164 
165 /**
166  * Returns the script to be executed in the interpreter.
167  *
168  * Returns an empty string, if none defined.
169  *
170  * @return Script string.
171  */
172 std::string
175  return "";
176  }
178 }
179 
180 /**
181  * Returns the filename of the given machine (.adf)
182  *
183  * @return the filename of the given machine (.adf)
184  */
185 std::string
188 }
189 
190 /**
191  * Returns the filename of the given program
192  *
193  * @return the filename of the given program
194  */
195 std::string
198 }
199 
200 /**
201  * Check what sort of simulation user asked for on the command line.
202  *
203  * If no value is given in the parsed command line the "normal" simulation,
204  * i.e. the interpreted, non-compiled, version is returned.
205  *
206  * @return type of TTA backend user wants
207  */
210 
211  bool wantCompiled = false;
212  bool wantRemote = false;
213  bool wantCustom = false;
214 
215  wantCompiled |= optionGiven(SWL_FAST_SIM);
216  wantCompiled &= findOption(SWL_FAST_SIM)->isFlagOn();
217 
218  wantRemote |= optionGiven(SWL_REMOTE_DBG);
219  wantRemote &= findOption(SWL_REMOTE_DBG)->isFlagOn();
220 
221  wantCustom |= optionGiven(SWL_CUSTOM_DBG);
222  wantCustom &= findOption(SWL_CUSTOM_DBG)->isFlagOn();
223 
224  // TODO: no check for if user requests simultaneously several
225  // versions of TTA backend. Start with the most picky one,
226  // user probably notices it erroring out.
227  if (wantCustom) return SimulatorFrontend::SIM_CUSTOM;
228  if (wantRemote) return SimulatorFrontend::SIM_REMOTE;
229  if (wantCompiled) return SimulatorFrontend::SIM_COMPILED;
231 }
232 
SWL_EXECUTE_SCRIPT
const std::string SWL_EXECUTE_SCRIPT
Long switch string for giving a script to be executed.
Definition: SimulatorCmdLineOptions.cc:48
SimulatorFrontend::SIM_REMOTE
@ SIM_REMOTE
Remote debugger, not a simulator at all.
Definition: SimulatorFrontend.hh:104
SimulatorCmdLineOptions::machineFile
std::string machineFile()
Definition: SimulatorCmdLineOptions.cc:186
SimulatorFrontend::SIM_COMPILED
@ SIM_COMPILED
Compiled, faster simulation.
Definition: SimulatorFrontend.hh:103
SWS_PROGRAM_TO_LOAD
const std::string SWS_PROGRAM_TO_LOAD
Short switch string for giving the program file.
Definition: SimulatorCmdLineOptions.cc:60
SWL_CUSTOM_DBG
const std::string SWL_CUSTOM_DBG
Long switch string for the custom remote debugger target.
Definition: SimulatorCmdLineOptions.cc:68
SWL_MACHINE_TO_LOAD
const std::string SWL_MACHINE_TO_LOAD
Long switch string for giving a machine file.
Definition: SimulatorCmdLineOptions.cc:53
CmdLineOptions.hh
SimulatorCmdLineOptions::backendType
SimulatorFrontend::SimulationType backendType()
Definition: SimulatorCmdLineOptions.cc:209
SWS_MACHINE_TO_LOAD
const std::string SWS_MACHINE_TO_LOAD
Short switch string for giving a machine file.
Definition: SimulatorCmdLineOptions.cc:55
Texts::TXT_CMD_LINE_HELP
@ TXT_CMD_LINE_HELP
Definition: SimulatorTextGenerator.hh:111
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
SimulatorCmdLineOptions::printVersion
virtual void printVersion() const
Definition: SimulatorCmdLineOptions.cc:131
SIM_CLI_TITLE
#define SIM_CLI_TITLE
The full title name of the CLI application.
Definition: SimulatorConstants.hh:54
SimulatorCmdLineOptions::programFile
std::string programFile()
Definition: SimulatorCmdLineOptions.cc:196
SimulatorCmdLineOptions::scriptString
std::string scriptString()
Definition: SimulatorCmdLineOptions.cc:173
SWL_FAST_SIM
const std::string SWL_FAST_SIM
Long switch string for the fast simulation.
Definition: SimulatorCmdLineOptions.cc:63
CmdLineOptionParser::isFlagOn
virtual bool isFlagOn() const
Definition: CmdLineOptionParser.cc:126
SWS_REMOTE_DBG
const std::string SWS_REMOTE_DBG
Short switch string for the TCE builtin remote debugger target.
Definition: SimulatorCmdLineOptions.cc:75
CmdLineOptions::optionGiven
bool optionGiven(std::string key) const
Definition: CmdLineOptions.cc:320
SimulatorConstants.hh
SimulatorFrontend::SimulationType
SimulationType
Which type of simulation this SimulatorFrontend controls or connects to.
Definition: SimulatorFrontend.hh:101
SWL_DEBUG_MODE
const std::string SWL_DEBUG_MODE
Long switch string for setting the debug mode.
Definition: SimulatorCmdLineOptions.cc:43
SimulatorToolbox.hh
CmdLineParser::addOption
void addOption(CmdLineOptionParser *opt)
SimulatorCmdLineOptions.hh
CmdLineOptions
Definition: CmdLineOptions.hh:54
SimulatorCmdLineOptions::~SimulatorCmdLineOptions
virtual ~SimulatorCmdLineOptions()
Definition: SimulatorCmdLineOptions.cc:124
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition: SimulatorToolbox.cc:75
BoolCmdLineOptionParser
Definition: CmdLineOptionParser.hh:278
SimulatorTextGenerator.hh
CmdLineOptions::printHelp
virtual void printHelp() const
Definition: CmdLineOptions.cc:262
SimulatorFrontend::SIM_CUSTOM
@ SIM_CUSTOM
User-implemented remote HW debugger.
Definition: SimulatorFrontend.hh:105
CmdLineOptionParser::String
virtual std::string String(int index=0) const
Definition: CmdLineOptionParser.cc:102
SWS_FAST_SIM
const std::string SWS_FAST_SIM
Short switch string for the fast simulation.
Definition: SimulatorCmdLineOptions.cc:65
SWS_EXECUTE_SCRIPT
const std::string SWS_EXECUTE_SCRIPT
Short switch string for giving a script to be executed.
Definition: SimulatorCmdLineOptions.cc:50
SWL_PROGRAM_TO_LOAD
const std::string SWL_PROGRAM_TO_LOAD
Long switch string for giving the program file.
Definition: SimulatorCmdLineOptions.cc:58
CmdLineParser::findOption
CmdLineOptionParser * findOption(std::string name) const
Definition: CmdLineParser.cc:160
SWS_CUSTOM_DBG
const std::string SWS_CUSTOM_DBG
Short switch string for the custom remote debugger target.
Definition: SimulatorCmdLineOptions.cc:70
SimulatorCmdLineOptions::debugMode
bool debugMode()
Definition: SimulatorCmdLineOptions.cc:158
Application::TCEVersionString
static std::string TCEVersionString()
Definition: Application.cc:510
SimulatorCmdLineOptions::SimulatorCmdLineOptions
SimulatorCmdLineOptions()
Definition: SimulatorCmdLineOptions.cc:82
SimulatorCmdLineOptions::printHelp
virtual void printHelp() const
Definition: SimulatorCmdLineOptions.cc:142
StringCmdLineOptionParser
Definition: CmdLineOptionParser.hh:180
SWS_DEBUG_MODE
const std::string SWS_DEBUG_MODE
Short switch string for setting the debug mode.
Definition: SimulatorCmdLineOptions.cc:45
SWL_REMOTE_DBG
const std::string SWL_REMOTE_DBG
Long switch string for the TCE builtin remote debugger target.
Definition: SimulatorCmdLineOptions.cc:73
SimulatorFrontend::SIM_NORMAL
@ SIM_NORMAL
Default, interpreted simulation (debugging engine).
Definition: SimulatorFrontend.hh:102