OpenASIP 2.2
Loading...
Searching...
No Matches
ProximMachineStateWindow.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 ProximMachineStateWindow.cc
26 *
27 * Definition of ProximMachineStateWindow class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/wx.h>
34#include <wx/statline.h>
39#include "MachineCanvas.hh"
40#include "Machine.hh"
41#include "Proxim.hh"
44#include "Instruction.hh"
45#include "Move.hh"
46#include "WxConversion.hh"
47#include "Terminal.hh"
48#include "EditPart.hh"
49#include "Figure.hh"
50#include "Port.hh"
51#include "Bus.hh"
52#include "ProximToolbox.hh"
53#include "UtilizationStats.hh"
55#include "MachinePart.hh"
56#include "ProximConstants.hh"
57#include "ErrorDialog.hh"
58#include "FileSystem.hh"
59#include "Request.hh"
60#include "ComponentCommand.hh"
61#include "Program.hh"
62#include "OptionValue.hh"
63
64#if wxCHECK_VERSION(3, 0, 0)
65 #define wxSAVE wxFD_SAVE
66 #define wxOVERWRITE_PROMPT wxFD_OVERWRITE_PROMPT
67#endif
68
72 EVT_MENU(COMMAND_ZOOM_IN, ProximMachineStateWindow::onZoom)
73 EVT_MENU(COMMAND_ZOOM_OUT, ProximMachineStateWindow::onZoom)
74 EVT_MENU(COMMAND_TOGGLE_UNIT_INFO, ProximMachineStateWindow::onToggleUnitInfo)
75 EVT_MENU(COMMAND_TOGGLE_MOVES, ProximMachineStateWindow::onToggleMoves)
76 EVT_MENU(COMMAND_TOGGLE_UTILIZATIONS, ProximMachineStateWindow::onToggleUtilizations)
77 EVT_MENU(COMMAND_EXPORT, ProximMachineStateWindow::onExport)
78 EVT_UPDATE_UI_RANGE(COMMAND_TOGGLE_UNIT_INFO, COMMAND_TOGGLE_UTILIZATIONS, ProximMachineStateWindow::onUpdateUIEvent)
80
81using std::string;
82using namespace TTAMachine;
83using namespace TTAProgram;
84
85const int ProximMachineStateWindow::MINIMUM_PANE_WIDTH = 150;
86const int ProximMachineStateWindow::INITIAL_DETAILS_PANE_WIDTH = 200;
87
88/**
89 * Constructor.
90 *
91 * @param parent Parent window of the window.
92 * @param id Window identifier.
93 */
95 ProximMainFrame* parent, int id):
96 ProximSimulatorWindow(parent, id, wxDefaultPosition, wxSize(800,600)),
97 showMoves_(true), showUtilizations_(true),
98 detailsCtrl_(NULL), utilizationCtrl_(NULL) {
99
100 createContents();
101
102 SetSizeHints(400, 300);
103
104 simulator_ = wxGetApp().simulation()->frontend();
105
106 if (simulator_->isSimulationInitialized() ||
107 simulator_->isSimulationStopped() ||
108 simulator_->isSimulationRunning() ||
109 simulator_->hasSimulationEnded()) {
110
112 const_cast<Machine*>(&ProximToolbox::machine());
113
114 canvas_->setMachine(machine);
115
116 if (showUtilizations_) {
117 setUtilizationHighlights();
118 }
119
120 }
121}
122
123
124/**
125 * Destructor.
126 */
129
130
131/**
132 * Event handler which is called when a new program is loaded in the simulator.
133 */
134void
140
141
142/**
143 * Resets the machine displayed on the canvas when the machine is unloaded
144 * in the simulator.
145 */
146void
150
151
152
153/**
154 * Event handler for simulation stop.
155 *
156 * Refreshes the register values.
157 */
158void
160
161 // Store pointer to the selected machine part.
162 const MachinePart* selection = NULL;
163 if (canvas_->selection() != NULL) {
164 selection = canvas_->selection()->model();
165 }
166
168 clearDetails();
169
170 if (showMoves_) {
171 addMoves();
172 }
173 if (showUtilizations_) {
175 }
176
177 canvas_->Refresh();
178
179 // Reselect & display details of the previously selected machine part.
180 Request statusRequest(Request::DETAILS_REQUEST);
181 if (selection != NULL) {
182 EditPart * part = canvas_->findEditPart(selection);
183 if (part != NULL && part->canHandle(&statusRequest)) {
184 canvas_->select(part);
185 ComponentCommand* command = part->performRequest(&statusRequest);
186 command->Do();
187 delete command;
188 }
189 }
190}
191
192
193/**
194 * Creates the window contents.
195 *
196 * Code generated by wxWidgets.
197 */
198void
200
201 sizer_ = new wxBoxSizer(wxVERTICAL);
202
203 wxSplitterWindow* splitter = new wxSplitterWindow(
204 this, ID_SPLITTER, wxDefaultPosition, wxSize(800,600),
205 wxSP_BORDER|wxSP_3D|wxCLIP_CHILDREN);
206
207 wxPanel* left = new wxPanel(splitter, -1);
208 wxPanel* right = new wxPanel(splitter, -1);
209
210 // Splitter window left hand pane sizer.
211 wxFlexGridSizer* leftSizer = new wxFlexGridSizer(1, 0, 0);
212 leftSizer->AddGrowableCol(0);
213 leftSizer->AddGrowableRow(1);
214 leftSizer->AddGrowableRow(4);
215
216 wxStaticText* title = new wxStaticText(
218 wxDefaultPosition, wxDefaultSize, 0);
219
220 detailsCtrl_ = new wxTextCtrl(
221 left, ID_DETAILS, wxT(""), wxDefaultPosition, wxSize(80,40),
222 wxTE_MULTILINE|wxTE_READONLY|wxVSCROLL|wxHSCROLL);
223
224 wxStaticLine* line = new wxStaticLine(
225 left, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL);
226
227 wxStaticText* utilizationTitle = new wxStaticText(
230 wxDefaultSize, 0);
231
232 utilizationCtrl_ = new wxTextCtrl(
233 left, ID_UTILIZATION, wxT(""), wxDefaultPosition, wxSize(80,40),
234 wxTE_MULTILINE|wxTE_READONLY|wxVSCROLL|wxHSCROLL);
235
236 leftSizer->Add(title, 0, wxGROW|wxALL, 5);
237 leftSizer->Add(detailsCtrl_, 0, wxGROW|wxALL, 5);
238 leftSizer->Add(line, 0, wxGROW|wxALL, 5);
239 leftSizer->Add(utilizationTitle, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
240 leftSizer->Add(utilizationCtrl_, 0, wxGROW|wxALL, 5);
241 left->SetSizer(leftSizer);
242
243
244 // Splitter window right hand pane sizer.
245 wxFlexGridSizer* rightSizer = new wxFlexGridSizer(1, 0, 0);
246 rightSizer->AddGrowableCol(0);
247 rightSizer->AddGrowableRow(0);
249 statusbar_ = new wxStatusBar(right, -1);
250 rightSizer->Add(canvas_, 0, wxGROW|wxALL, 5);
251 rightSizer->Add(statusbar_, 0, wxGROW|wxALL, 5);
252 right->SetSizer(rightSizer);
253
254 // Set sizers and split the window.
255 splitter->SetMinimumPaneSize(MINIMUM_PANE_WIDTH);
256 splitter->SplitVertically(left, right);
257 splitter->SetSashPosition(INITIAL_DETAILS_PANE_WIDTH);
258
259 sizer_->Add(splitter, 1, wxGROW);
260 SetSizer(sizer_);
261
262 // Create tool for the canvas.
264 canvas_->setTool(canvasTool);
265}
266
267
268/**
269 * Sets the status line text.
270 *
271 * @param status Status text to set.
272 */
273void
275 wxString text = WxConversion::toWxString(status);
276 statusbar_->SetStatusText(text);
277}
278
279
280/**
281 * Handles zoom menu item events.
282 *
283 * @param event Menu event to handle.
284 */
285void
286ProximMachineStateWindow::onZoom(wxCommandEvent& event) {
287
288 // Zoom in.
289 if (event.GetId() == COMMAND_ZOOM_IN) {
290 canvas_->zoomIn();
291 }
292
293 // Zoom out.
294 if (event.GetId() == COMMAND_ZOOM_OUT) {
295 canvas_->zoomOut();
296 }
297}
298
299
300/**
301 * Sets machine part highlights based on part utilizations.
302 */
303void
305
307
308 Machine* machine = const_cast<Machine*>(&ProximToolbox::machine());
309
310 const UtilizationStats& stats =
312
314
315 // Highlight buses.
316 const Machine::BusNavigator& busNavigator = machine->busNavigator();
317 for (int i = 0; i < busNavigator.count(); i++) {
318 ClockCycleCount writes =
319 stats.busWrites(busNavigator.item(i)->name());
320 double utilization = static_cast<double>(writes) / cycles;
321 unsigned value = unsigned(utilization * 255);
322 canvas_->highlight(busNavigator.item(i), wxColour(value, 0, 0));
323 }
324
325 // Highlight sockets.
326 const Machine::SocketNavigator& socketNavigator =
328
329 for (int i = 0; i < socketNavigator.count(); i++) {
330 ClockCycleCount writes =
331 stats.socketWrites(socketNavigator.item(i)->name());
332 double utilization = static_cast<double>(writes) / cycles;
333 unsigned value = 255 - unsigned(utilization * 255);
334 wxColour colour = wxColour(255, value, value);
335 canvas_->highlight(socketNavigator.item(i), colour);
336 }
337
338 // Highlight function units.
339 const Machine::FunctionUnitNavigator& fuNavigator =
341
342 for (int i = 0; i < fuNavigator.count(); i++) {
343 ClockCycleCount writes =
344 stats.triggerCount(fuNavigator.item(i)->name());
345 double utilization = static_cast<double>(writes) / cycles;
346 unsigned value = 255 - unsigned(utilization * 255);
347 wxColour colour = wxColour(255, value, value);
348 canvas_->highlight(fuNavigator.item(i), colour);
349 }
350
351}
352
353
354/**
355 * Adds active moves to be drawn on the canvas.
356 */
357void
359
361
362 const TTAProgram::Instruction& instruction =
363 simulator_->program().instructionAt(address);
364
366 for (int i = 0; i < instruction.moveCount(); i++) {
367
368 // Check that the move wasn't squashed by a guard.
369 const ExecutableInstruction& lastInstruction =
371
372 if (lastInstruction.moveSquashed(i)) {
373 continue;
374 }
375
376 // Move not squashed, add move to be drawn on the canvas.
377 TTAProgram::Move& move = instruction.move(i);
378 const Bus* bus = &move.bus();
379 const Port* source = NULL;
380 const Port* target = NULL;
381 if (move.source().isFUPort() || move.source().isGPR()) {
382 source = &move.source().port();
383 }
384 if (move.destination().isFUPort() || move.destination().isGPR()) {
385 target = &move.destination().port();
386 }
387 canvas_->addMove(bus, source, target);
388 }
389
390}
391
392/**
393 * Toggles the unit info string display on and off.
394 */
395void
405
406
407/**
408 * Toggles the move display on and off.
409 */
410void
413 if (showMoves_) {
414 addMoves();
415 } else {
417 }
418 canvas_->Refresh();
419}
420
421/**
422 * Toggles the utilization display on and off.
423 */
424void
426
428
430 if (showUtilizations_ && frontend != NULL) {
432 } else {
434 }
435 canvas_->Refresh();
436}
437
438
439/**
440 * Event handler for meni item UI update events.
441 *
442 * @param event Update event to handle.
443 */
444void
446
447 if (event.GetId() == COMMAND_TOGGLE_MOVES) {
448 event.Check(showMoves_);
449 } else if (event.GetId() == COMMAND_TOGGLE_UTILIZATIONS) {
450 event.Check(showUtilizations_);
451 } else if (event.GetId() == COMMAND_TOGGLE_UNIT_INFO) {
452 OptionValue& showInfo = canvas_->options().optionValue(
454 event.Check(showInfo.isFlagOn());
455 } else {
456 event.Skip();
457 }
458}
459
460
461/**
462 * Appends text to the component utilization widget.
463 *
464 * @param text Text to append.
465 */
466void
468 wxString data = WxConversion::toWxString(text);
469 utilizationCtrl_->AppendText(data);
470}
471
472
473/**
474 * Appends text to the component details widget.
475 *
476 * @param text Text to append.
477 */
478void
480 wxString data = WxConversion::toWxString(text);
481 detailsCtrl_->AppendText(data);
482}
483
484/**
485 * Clears data in the component details pane.
486 */
487void
492
493
494/**
495 * Displays a dialog for saving machine figure in a file.
496 */
497void
499
500 wxString message = _T("Export processor figure.");
501 wxString defaultDir = _T(".");
502 wxString defaultFile= _T("");
503#if wxCHECK_VERSION(3, 0, 0)
504 wxString fileTypes = _T("Scalable Vector Graphics (.svg)|*.svg|");
505#else
506 wxString fileTypes = _T("Encapsulated Postscript (.eps)|*.eps;*.epsi|");
507#endif
508 fileTypes.Append(_T("Portable Network Graphics (.png)|*.png"));
509
510 wxFileDialog dialog(
511 this, message, defaultDir, defaultFile, fileTypes,
512 wxSAVE | wxOVERWRITE_PROMPT);
513
514 if (dialog.ShowModal() == wxID_CANCEL) {
515 return;
516 }
517
518 std::string filename = WxConversion::toString(dialog.GetPath());
519 std::string extension = FileSystem::fileExtension(filename);
520 std::string creator = "TTA Processor Simulator (Proxim)";
521 std::string title = "Processor Simulation";
522
523#if wxCHECK_VERSION(3, 0, 0)
524 if (extension == ".svg") {
525 if (!canvas_->saveSVG(filename)) {
526#else
527 if (extension == ".eps" || extension == ".epsi") {
528 if (!canvas_->saveEPS(filename, title, creator)) {
529#endif
530 wxString message = _T("Error saving file '");
531 message.Append(dialog.GetPath());
532 message.Append(_T("'."));
533 ErrorDialog errorDialog(this, message);
534 errorDialog.ShowModal();
535 }
536 } else if (extension == ".png") {
537 if (!canvas_->savePNG(filename)) {
538 wxString message = _T("Error saving file '");
539 message.Append(dialog.GetPath());
540 message.Append(_T("'."));
541 ErrorDialog errorDialog(this, message);
542 errorDialog.ShowModal();
543 }
544 } else {
545 wxString message = _T("File type with extension '");
546 message.Append(WxConversion::toWxString(extension));
547 message.Append(_T("' is not supported."));
548 ErrorDialog dialog(this, message);
549 dialog.ShowModal();
550 }
551}
UInt32 InstructionAddress
Definition BaseType.hh:175
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine * machine
the architecture definition of the estimated processor
CycleCount ClockCycleCount
Alias for ClockCycleCount.
#define EVT_SIMULATOR_PROGRAM_LOADED(id, fn)
#define EVT_SIMULATOR_STOP(id, fn)
virtual bool Do()=0
bool canHandle(Request *request) const
Definition EditPart.cc:316
ComponentCommand * performRequest(Request *request) const
Definition EditPart.cc:297
TTAMachine::MachinePart * model() const
bool moveSquashed(std::size_t moveIndex) const
static std::string fileExtension(const std::string &fileName)
static const std::string SHOW_UNIT_INFO_STRING
Option name for the unit info string visibility flag.
bool savePNG(const std::string &filename)
void highlight(TTAMachine::MachinePart *model, const wxColour &colour)
EditPart * selection()
void setTool(MachineCanvasTool *tool)
void select(EditPart *part)
void addMove(const TTAMachine::Bus *bus, const TTAMachine::Port *source, const TTAMachine::Port *target)
bool saveEPS(const std::string &filename, const std::string &title, const std::string &creator="")
EditPart * findEditPart(int x, int y)
MachineCanvasOptions & options()
void setMachine(TTAMachine::Machine *machine)
virtual void setBoolValue(bool)
virtual bool isFlagOn() const
OptionValue & optionValue(const string &name, int index=0)
Definition Options.cc:115
static const wxString MACH_WIN_DETAILS_TITLE
Execution count title for the machine state window.
static const wxString MACH_WIN_UTILIZATION_TITLE
Execution count title for the machine state window.
wxBoxSizer * sizer_
Toplevel sizer for the window widgets.
wxTextCtrl * detailsCtrl_
Utilziation window where to display utilization data of the components.
void appendDetails(std::string text)
void onUpdateUIEvent(wxUpdateUIEvent &event)
void onToggleUnitInfo(wxCommandEvent &event)
void onProgramLoaded(const SimulatorEvent &event)
bool showMoves_
Tells if the moves are displayed or not.
bool showUtilizations_
Tells if the machine part utilizations are displayed or not.
static const int MINIMUM_PANE_WIDTH
Minimum width for the splitter window panes.
void setStatusText(std::string status)
static const int INITIAL_DETAILS_PANE_WIDTH
Initial width for the component detail pane.
void onSimulationStop(const SimulatorEvent &event)
wxStatusBar * statusbar_
Statusbar of the window.
void onZoom(wxCommandEvent &event)
MachineCanvas * canvas_
Machine visualization canvas.
void onToggleMoves(wxCommandEvent &event)
void onExport(wxCommandEvent &event)
SimulatorFrontend * simulator_
Simulator instance which contains the registers to display.
void appendUtilizationData(std::string text)
void onToggleUtilizations(wxCommandEvent &event)
static const TTAMachine::Machine & machine()
static TracedSimulatorFrontend * frontend()
@ DETAILS_REQUEST
Detailed info request.
Definition Request.hh:53
const TTAMachine::Machine & machine() const
const UtilizationStats & utilizationStatistics(int core=-1)
ClockCycleCount cycleCount() const
const ExecutableInstruction & lastExecInstruction() const
virtual InstructionAddress lastExecutedInstruction(int coreId=-1) const
const TTAProgram::Program & program() const
ComponentType * item(int index) const
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
virtual SocketNavigator socketNavigator() const
Definition Machine.cc:368
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
Move & move(int i) const
Terminal & source() const
Definition Move.cc:302
Terminal & destination() const
Definition Move.cc:323
const TTAMachine::Bus & bus() const
Definition Move.cc:373
Instruction & instructionAt(InstructionAddress address) const
Definition Program.cc:374
virtual bool isGPR() const
Definition Terminal.cc:107
virtual const TTAMachine::Port & port() const
Definition Terminal.cc:378
virtual bool isFUPort() const
Definition Terminal.cc:118
ClockCycleCount busWrites(const std::string &busName) const
ClockCycleCount triggerCount(const std::string &fuName) const
ClockCycleCount socketWrites(const std::string &socketName) const
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)