OpenASIP 2.2
Loading...
Searching...
No Matches
Proxim.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2017 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 Proxim.cc
26 *
27 * Implementation of Proxim class.
28 *
29 * @author Veli-Pekka J��skel�inen 2005 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34#include <cstdlib>
35#include <iostream>
36#include <wx/cmdline.h>
37#include <wx/imagpng.h>
38#include "Proxim.hh"
39#include "Application.hh"
40#include "Exception.hh"
42#include "ProximMainFrame.hh"
44#include "GUIOptions.hh"
45#include "Environment.hh"
47#include "ProximConstants.hh"
48#include "FileSystem.hh"
49#include "WxConversion.hh"
50#include "ProximToolbox.hh"
51#include "ErrorDialog.hh"
52#include "tce_config.h"
53#include "ObjectState.hh"
54
55IMPLEMENT_APP(Proxim)
56
57using std::cerr;
58using std::endl;
59using std::string;
60
61const std::string Proxim::CONFIG_FILE_NAME = "Proxim.conf";
62const std::string Proxim::SCHEMA_FILE_NAME = "confschema.xsd";
63
64/**
65 * The constructor.
66 */
68 wxApp(), mainFrame_(NULL), commandRegistry_(NULL), simulation_(NULL),
69 options_(NULL) {
70}
71
72
73/**
74 * The Destructor.
75 */
79
80
81
82/**
83 * Initializes the application.
84 *
85 * Creates command registry, application main frame and a simulation thread.
86 * The main frame console linereader is set as the linereader for the
87 * simulator thread.
88 *
89 * @return True, if the application was succesfully initialized.
90 */
91bool
93
95
96 const wxCmdLineEntryDesc cmdLineDesc[] = {
97
98#if wxCHECK_VERSION(3,0,0)
99 { wxCMD_LINE_PARAM, NULL, NULL, "input file",
100#else
101 { wxCMD_LINE_PARAM, NULL, NULL, _T("input file"),
102#endif
103
104 wxCMD_LINE_VAL_STRING,
105 (wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL) },
106 { wxCMD_LINE_NONE, NULL, NULL, NULL, wxCMD_LINE_VAL_NONE, 0 }
107 };
108
109 wxCmdLineParser parser(cmdLineDesc);
110 parser.SetCmdLine(argc, argv);
111 parser.Parse();
112
113 std::string machineToLoad = "";
114 std::string programToLoad = "";
115
116 if (parser.GetParamCount() == 1) {
117 programToLoad = WxConversion::toString(parser.GetParam(0));
118 } else if (parser.GetParamCount() == 2) {
119 machineToLoad = WxConversion::toString(parser.GetParam(0));
120 programToLoad = WxConversion::toString(parser.GetParam(1));
121 } else if (parser.GetParamCount() > 2) {
122 std::cout << ProximConstants::PROXIM_TITLE << " "
123 << Application::TCEVersionString() << std::endl;
124 std::cout << "Usage: proxim [program file]" << endl;
125 std::cout << " proxim [machine file] [program file]" << endl;
126
127 return false;
128 }
129
130
131 // load image handler for pngs
132 wxImage::AddHandler(new wxPNGHandler);
133
136 options_ = new GUIOptions("proxim-configuration");
137
138 loadOptions();
139
141 _T("TTA Processor Simulator"), wxDefaultPosition, wxSize(800, 600));
142
143 simulation_->Create();
145 simulation_->Run();
146
147 mainFrame_->Show(true);
148 SetTopWindow(mainFrame_);
149
151
152 if (machineToLoad != "") {
153 interpreter->interpret(
154 ProximConstants::SCL_LOAD_MACHINE + " " + machineToLoad);
155 if (interpreter->result().size() > 0) {
156 wxString message = _T("Error loading machine file '");
157 message.Append(WxConversion::toWxString(machineToLoad));
158 message.Append(_T("'.\n"));
159 message.Append(WxConversion::toWxString(interpreter->result()));
160 ErrorDialog dialog(mainFrame_, message);
161 dialog.ShowModal();
162 return true;
163 }
164 }
165
166 if (programToLoad != "") {
167 interpreter->interpret(
168 ProximConstants::SCL_LOAD_PROGRAM + " " + programToLoad);
169 if (interpreter->result().size() > 0) {
170 wxString message = _T("Error loading program file '");
171 message.Append(WxConversion::toWxString(programToLoad));
172 message.Append(_T("'.\n"));
173 message.Append(WxConversion::toWxString(interpreter->result()));
174 ErrorDialog dialog(mainFrame_, message);
175 dialog.ShowModal();
176 }
177 }
178 return true;
179}
180
181
182/**
183 * Deletes the simulation thread when the application exits.
184 *
185 * @return Exit code.
186 */
187int
189 simulation_->Delete();
190 simulation_->Wait();
191 delete simulation_;
192 return EXIT_SUCCESS;
193}
194
195
196/**
197 * Returns pointer to the simulation thread.
198 *
199 * @return Pointer to the simulation thread.
200 */
203 return simulation_;
204}
205
206
207/**
208 * Returns reference to the application command registry.
209 *
210 * The command registry stores all commands available for execution
211 * in the main fram menubar and toolbar.
212 *
213 * @return Reference to the application command registry.
214 */
219
220/**
221 * Loads GUIOptions for Proxim from the configuration file.
222 *
223 * If the configuration file is erroneous or not found, default options
224 * will be used.
225 */
226void
228
229 if (options_ != NULL) {
230 delete options_;
231 }
232
233 bool optionsOK = false;
234
235 string configFile = Environment::confPath(CONFIG_FILE_NAME);
236
237 string schemaFile = Environment::dataDirPath("Proxim") +
239
241 reader.setSourceFile(configFile);
242 reader.setSchemaFile(schemaFile);
243 reader.setUseSchema(true);
244
245 try {
246 ObjectState* optionsState = reader.readState();
247 options_ = new GUIOptions(optionsState);
248 delete optionsState;
250 options_->setFileName(configFile);
251 optionsOK = true;
252 } catch (Exception& e) {
253 cerr << "Error loading config file " << configFile << ":" << endl
254 << e.errorMessage() << endl
255 << "Default options will be used." << endl;
256 }
257
258 if (!optionsOK) {
260 } else {
262 }
263}
264
265/**
266 * Creates a default set of options if the configuration file is erroneous
267 * or not found.
268 */
269void
271
272 ToolbarButton* buttonMachine = new ToolbarButton(
274
275 ToolbarButton* buttonProgram = new ToolbarButton(
277
278 ToolbarButton* buttonRun = new ToolbarButton(
280
281 ToolbarButton* buttonResume = new ToolbarButton(
283
284 ToolbarButton* buttonKill = new ToolbarButton(
286
287 ToolbarButton* buttonStepi = new ToolbarButton(
289
290 ToolbarButton* buttonNexti = new ToolbarButton(
292
293 // F2 -> run
295 ProximConstants::COMMAND_NAME_RUN, 2, false, false, 0);
296
297 // F4 -> kill
299 ProximConstants::COMMAND_NAME_KILL, 4, false, false, 0);
300
301 // F5 -> stepi
302 KeyboardShortcut* scStepi = new KeyboardShortcut(
303 ProximConstants::COMMAND_NAME_STEPI, 5, false, false, 0);
304
305 // F6 -> nexti
306 KeyboardShortcut* scNexti = new KeyboardShortcut(
307 ProximConstants::COMMAND_NAME_NEXTI, 6, false, false, 0);
308
309 // F9 -> resume
310 KeyboardShortcut* scResume = new KeyboardShortcut(
311 ProximConstants::COMMAND_NAME_RESUME, 9, false, false, 0);
312
313 // Ctrl + F -> find operation in assembly code window
315 ProximConstants::COMMAND_NAME_FIND, 0, true, false, int('F'));
316
319
320 options_->setFileName(fileName);
321
322 options_->addToolbarButton(buttonMachine);
323 options_->addToolbarButton(buttonProgram);
324 options_->addToolbarButton(buttonRun);
325 options_->addToolbarButton(buttonResume);
326 options_->addToolbarButton(buttonKill);
327 options_->addToolbarButton(buttonStepi);
328 options_->addToolbarButton(buttonNexti);
332
336 options_->addKeyboardShortcut(scResume);
339}
340
341/**
342 * Returns references to the application options.
343 *
344 * @return GUIOptions of the application.
345 */
348 return *options_;
349}
static std::string TCEVersionString()
static void initialize()
static TCEString userConfPath(const std::string &fileName)
static std::string dataDirPath(const std::string &prog)
static TCEString confPath(const std::string &fileName)
std::string errorMessage() const
Definition Exception.cc:123
static const std::string DIRECTORY_SEPARATOR
void addKeyboardShortcut(KeyboardShortcut *shortcut)
void setToolbarVisibility(bool visible)
void addToolbarButton(ToolbarButton *button)
void addSeparator(int position)
virtual void validate() const
void clearModified()
@ TEXT
Buttons contains only text.
Definition GUIOptions.hh:65
void setFileName(const std::string &fileName)
void setToolbarLayout(ToolbarLayout layout)
static const std::string SCL_LOAD_PROGRAM
Command for loading a new program in the simulator.
static const std::string COMMAND_NAME_RESUME
Name of the resume command.
static const std::string COMMAND_NAME_RUN
Name of the run command.
static const std::string COMMAND_NAME_OPEN_PROGRAM
Name of the open program command.
static const std::string COMMAND_NAME_NEXTI
Name of the next instruction command.
static const std::string COMMAND_NAME_KILL
Name of the kill command.
static const std::string CONFIGURATION_NAME
Configuration file top-level element name.
static const std::string SCL_LOAD_MACHINE
Command for loading a new machine in the simulator.
static const std::string COMMAND_NAME_STEPI
Name of the step instruction command.
static const std::string COMMAND_NAME_FIND
Name of the find command.
static const std::string PROXIM_TITLE
Application title.
static const std::string COMMAND_NAME_OPEN_MACHINE
Name of the open machine command.
void initialize(ProximMainFrame *gui)
SimulatorInterpreter * interpreter()
static const std::string CONFIG_FILE_NAME
Name of the config file.
Definition Proxim.hh:77
CommandRegistry * commandRegistry_
The application command registry.
Definition Proxim.hh:70
virtual int OnExit()
Definition Proxim.cc:188
GUIOptions * options_
Options defining toolbar, keyboard shortcuts etc.
Definition Proxim.hh:74
GUIOptions & options()
Definition Proxim.cc:347
virtual bool OnInit()
Definition Proxim.cc:92
ProximSimulationThread * simulation_
The simulation thread running the simulator backend.
Definition Proxim.hh:72
void createDefaultOptions()
Definition Proxim.cc:270
ProximSimulationThread * simulation()
Definition Proxim.cc:202
CommandRegistry & commandRegistry()
Definition Proxim.cc:216
ProximMainFrame * mainFrame_
The application main frame.
Definition Proxim.hh:68
virtual ~Proxim()
Definition Proxim.cc:76
void loadOptions()
Definition Proxim.cc:227
Proxim()
Definition Proxim.cc:67
static const std::string SCHEMA_FILE_NAME
Name of the xml-schema file.
Definition Proxim.hh:79
virtual std::string result()
virtual bool interpret(const std::string &commandLine)
static char ** toCStringArray(size_t elements, wxChar **source)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)
void setUseSchema(bool useSchema)
void setSchemaFile(const std::string &fileName)
void setSourceFile(const std::string &fileName)