OpenASIP  2.0
ProximDisassemblyWindow.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 ProximDisassemblyWindow.cc
26  *
27  * Definition of ProximDisassemblyWindow class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 
34 #include <string>
35 
37 #include "POMDisassembler.hh"
38 #include "WxConversion.hh"
40 #include "Proxim.hh"
43 #include "StopPointManager.hh"
44 #include "Breakpoint.hh"
45 #include "StopPoint.hh"
46 #include "ProximConstants.hh"
47 #include "AssocTools.hh"
48 #include "Conversion.hh"
49 #include "NullInstruction.hh"
50 #include "ProximToolbox.hh"
52 #include "ProximToolbox.hh"
54 
55 using namespace TTAProgram;
56 
62  EVT_GRID_CELL_RIGHT_CLICK(ProximDisassemblyWindow::onRightClick)
63  EVT_MENU(MENU_ID_SET_BP, ProximDisassemblyWindow::onSetBreakpoint)
64  EVT_MENU(MENU_ID_SET_TEMP_BP, ProximDisassemblyWindow::onSetTempBp)
65  EVT_MENU(MENU_ID_RUN_UNTIL, ProximDisassemblyWindow::onRunUntil)
67  ProximDisassemblyWindow::onMappedMenuCommand)
69 
70 using std::string;
71 
72 const unsigned ProximDisassemblyWindow::INFO_COLUMN_WIDTH = 30;
73 const unsigned ProximDisassemblyWindow::ADDRESS_COLUMN_WIDTH = 60;
74 const unsigned ProximDisassemblyWindow::BP_COLUMN_WIDTH = 80;
75 const unsigned ProximDisassemblyWindow::DISASSEMBLY_COLUMN_WIDTH = 400;
76 
77 
78 /**
79  * Constructor.
80  *
81  * @param parent Parent window of the window.
82  * @param id Window identifier.
83  */
85  ProximMainFrame* parent, int id):
86  ProximSimulatorWindow(parent, id),
87  codeGrid_(NULL),
88  codeTable_(NULL) {
89 
90  initialize();
91 }
92 
93 
94 /**
95  * Destructor.
96  */
98 }
99 
100 
101 /**
102  * Creates the window contents.
103  */
104 void
106 
107  wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
108  SetSizer(sizer);
109 }
110 
111 
112 /**
113  * Resets the grid. This function has to be called if a new program
114  * is loaded to the window.
115  */
116 void
118 
119  wxSizer* sizer = GetSizer();
120 
121  if (codeGrid_ != NULL) {
122  sizer->Detach(codeGrid_);
123  sizer->Layout();
124  codeGrid_->Destroy();
125  }
126 
127  codeGrid_ = new wxGrid(this, -1, wxDefaultPosition, wxDefaultSize);
128  codeGrid_->SetTable(codeTable_);
129 
130  codeGrid_->EnableEditing(false);
131  codeGrid_->DisableCellEditControl();
132  codeGrid_->SetSelectionMode(wxGrid::wxGridSelectRows);
133  codeGrid_->DisableDragGridSize();
134  codeGrid_->DisableDragRowSize();
135  codeGrid_->EnableGridLines(false);
136  codeGrid_->SetDefaultColSize(200);
137 
138  codeGrid_->SetColSize(0, 100);
139  codeGrid_->SetColSize(1, 80);
140 
141  codeGrid_->SetDefaultCellFont(*wxSMALL_FONT);
142  codeGrid_->SetGridCursor(0, 0);
143 
144  sizer->Add(codeGrid_, 1, wxGROW);
145 
146  Layout();
147 }
148 
149 
150 
151 /**
152  * Called when the simulator program, machine and memory models are deleted.
153  */
154 void
156 
157  wxSizer* sizer = GetSizer();
158 
159  if (codeGrid_ != NULL) {
160  sizer->Detach(codeGrid_);
161  sizer->Layout();
162  codeGrid_->Destroy();
163  codeGrid_ = NULL;
164  }
165 
166  if (codeTable_ != NULL) {
167  delete codeTable_;
168  codeTable_ = NULL;
169  }
170 }
171 
172 
173 /**
174  * Loads a program model to the window.
175  *
176  * @param program Program to load.
177  */
178 void
180  assert(codeTable_ == NULL);
181  codeTable_ = new ProximDisassemblyGridTable();
182 
183  codeTable_->loadProgram(program);
184  resetGrid();
185  codeTable_->setCurrentInstruction(0);
186  codeTable_->showPCArrow();
187  StopPointManager& bpManager =
189  codeTable_->setStopPointManager(bpManager);
190 }
191 
192 
193 /**
194  * Updates disassembly window when a program is loaded to the
195  * simulator.
196  */
197 void
199  loadProgram(ProximToolbox::program());
200 }
201 
202 
203 /**
204  * Handles RMB clicks on the disassembly window.
205  *
206  * A context menu is displayed at the cursor location.
207  */
208 void
210 
211  codeGrid_->SelectRow(event.GetRow());
212 
213  wxMenu* contextMenu = new wxMenu();
214  Word address = codeTable_->addressOfRow(event.GetRow());
215  contextMenu->Append(MENU_ID_SET_BP, _T("Set breakpoint"));
216  contextMenu->Append(
217  MENU_ID_SET_TEMP_BP, _T("Set temporary breakpoint"));
218 
219  contextMenu->AppendSeparator();
220  contextMenu->Append(MENU_ID_RUN_UNTIL, _T("Run until"));
221  contextMenu->AppendSeparator();
222 
223  menuCommand_.clear();
224 
225  StopPointManager& bpManager =
227 
228  // Create submenu for each breakpoint at the selected line.
229  unsigned itemID = MENU_ID_FIRST_MAPPED;
230  for (unsigned i = 0; i < bpManager.stopPointCount(); i++) {
231 
232  unsigned handle = bpManager.stopPointHandle(i);
233  const Breakpoint* bp = dynamic_cast<const Breakpoint*>(
234  &bpManager.stopPointWithHandleConst(handle));
235 
236  if (bp != NULL) {
237  unsigned bpAddress = bp->address();
238  if (bpAddress == address) {
239 
240  wxMenu* bpSubMenu = new wxMenu();
241  string handleStr = Conversion::toString(handle);
242 
243  // Info menuitem.
244  menuCommand_[itemID] = "info breakpoints " + handleStr;
245  wxString infoLabel = _T("info");
246  bpSubMenu->Append(itemID, infoLabel);
247  itemID++;
248 
249 
250  // Delete menuitem.
251  menuCommand_[itemID] = "deletebp " + handleStr;
252  wxString deleteLabel = _T("delete");
253  bpSubMenu->Append(itemID, deleteLabel);
254  itemID++;
255 
256  // Enable/disable menuitem.
257  if (bp->isEnabled()) {
258  menuCommand_[itemID] =
259  "disablebp " + handleStr;
260  wxString disableLabel = _T("disable");
261  bpSubMenu->Append(itemID, disableLabel);
262  } else {
263  menuCommand_[itemID] =
264  "enablebp " + handleStr;
265  wxString enableLabel = _T("enable");
266  bpSubMenu->Append(itemID, enableLabel);
267  }
268  itemID++;
269  wxString menuLabel =
270  _T("breakpoint ") + WxConversion::toWxString(handle);
271 
272  contextMenu->Append(0, menuLabel, bpSubMenu);
273  }
274  }
275  }
276 
277  PopupMenu(contextMenu, event.GetPosition());
278 }
279 
280 
281 
282 /**
283  * Handles the event of adding new breakpoint with the context menu.
284  */
285 void
287  unsigned address =
288  codeTable_->addressOfRow(codeGrid_->GetSelectedRows().Item(0));
289  string command = ProximConstants::SCL_SET_BREAKPOINT + " " +
290  Conversion::toString(address);
291 
292  wxGetApp().simulation()->lineReader().input(command);
293 }
294 
295 
296 /**
297  * Handles the event of adding new temporary breakpoint with the context menu.
298  */
299 void
301  unsigned address =
302  codeTable_->addressOfRow(codeGrid_->GetSelectedRows().Item(0));
303  string command = ProximConstants::SCL_SET_TEMP_BP + " " +
304  Conversion::toString(address);
305 
306  wxGetApp().simulation()->lineReader().input(command);
307 }
308 
309 
310 /**
311  * Handles the context menu "run until" clicks.
312  */
313 void
315  unsigned address =
316  codeTable_->addressOfRow(codeGrid_->GetSelectedRows().Item(0));
317  string command = ProximConstants::SCL_RUN_UNTIL + " " +
318  Conversion::toString(address);
319 
320  wxGetApp().simulation()->lineReader().input(command);
321 }
322 
323 /**
324  * Updates the arrow displaying the current instruction when the simulation
325  * stops.
326  */
327 void
329  Word pc = wxGetApp().simulation()->frontend()->programCounter();
330  if (codeTable_->moveCellAttrProvider() != NULL) {
331  codeTable_->moveCellAttrProvider()->update();
332  }
333  codeTable_->setCurrentInstruction(pc);
334  codeGrid_->SelectRow(pc);
335  codeGrid_->MakeCellVisible(pc, 1);
336  codeGrid_->ForceRefresh();
337 }
338 
339 /**
340  * Updates the disassembly window when a command is executed.
341  *
342 
343  * @param event Event of a command execution.
344  */
345 void
347  if (codeGrid_ != NULL) {
348  codeGrid_->ForceRefresh();
349  }
350  event.Skip();
351 }
352 
353 /**
354  * Selects the instruction at given address.
355  *
356  * @param address Address of the isntruction to show.
357  */
358 void
360  unsigned row = codeTable_->rowOfAddress(address);
361  codeGrid_->SelectRow(row);
362  codeGrid_->MakeCellVisible(row, 0);
363 
364 }
365 
366 
367 /**
368  * Event handler for breakpoint submenus of the context menu.
369  *
370  * @param event Menu event to handle.
371  */
372 void
374 
375  if (!AssocTools::containsKey(menuCommand_, event.GetId())) {
376  // Menu item ID doesn't have command associated, the event is skipped.
377  event.Skip();
378  }
379 
380  string command = menuCommand_[event.GetId()];
381  wxGetApp().simulation()->lineReader().input(command);
382 }
383 
384 
385 /**
386  * Sets the move cell attribute provider.
387  *
388  * @param attrProvider New attribute provider.
389  */
390 void
392  ProximDisasmAttrProvider* attrProvider) {
393 
394  codeTable_->setMoveCellAttrProvider(attrProvider);
395 }
ProximMainFrame
Definition: ProximMainFrame.hh:58
StopPointManager.hh
TTAProgram
Definition: Estimator.hh:65
TTAProgram::Program
Definition: Program.hh:63
Breakpoint::address
virtual InstructionAddress address() const
Definition: Breakpoint.cc:86
ProximToolbox::frontend
static TracedSimulatorFrontend * frontend()
Definition: ProximToolbox.cc:223
WxConversion::toWxString
static wxString toWxString(const std::string &source)
ProximDisassemblyWindow::~ProximDisassemblyWindow
virtual ~ProximDisassemblyWindow()
Definition: ProximDisassemblyWindow.cc:97
Breakpoint
Definition: Breakpoint.hh:50
AssocTools::containsKey
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
EVT_SIMULATOR_COMMAND_DONE
EVT_SIMULATOR_COMMAND_DONE(0, ProximDisassemblyWindow::onSimulatorCommand) EVT_MENU_RANGE(MENU_ID_FIRST_MAPPED
ProximToolbox::program
static const TTAProgram::Program & program()
Definition: ProximToolbox.cc:88
ProximDisassemblyWindow::reset
virtual void reset()
Definition: ProximDisassemblyWindow.cc:155
ProximDisassemblyWindow::setMoveAttrProvider
void setMoveAttrProvider(ProximDisasmAttrProvider *attrProvider)
Definition: ProximDisassemblyWindow.cc:391
ProximSimulationThread.hh
Proxim.hh
ProximDisassemblyWindow::onSetTempBp
void onSetTempBp(wxCommandEvent &event)
Definition: ProximDisassemblyWindow.cc:300
ProximDisassemblyWindow.hh
Conversion::toString
static std::string toString(const T &source)
POMDisassembler.hh
ProximSimulatorWindow
Definition: ProximSimulatorWindow.hh:47
assert
#define assert(condition)
Definition: Application.hh:86
MENU_ID_FIRST_MAPPED
MENU_ID_FIRST_MAPPED
Definition: ProximDisassemblyWindow.cc:66
ProximToolbox.hh
StopPointManager::stopPointCount
unsigned int stopPointCount()
Definition: StopPointManager.cc:269
ProximDisassemblyWindow::resetGrid
void resetGrid()
Definition: ProximDisassemblyWindow.cc:117
ProximConstants::SCL_RUN_UNTIL
static const std::string SCL_RUN_UNTIL
Command for running until specified instruciton is encoutnered.
Definition: ProximConstants.hh:163
ProximDisasmAttrProvider
Definition: ProximDisasmAttrProvider.hh:44
DisassemblyInstruction.hh
StopPointManager::stopPointWithHandleConst
const StopPoint & stopPointWithHandleConst(unsigned int handle) const
Definition: StopPointManager.cc:248
ProximDisassemblyWindow::onSimulatorCommand
void onSimulatorCommand(SimulatorEvent &event)
Definition: ProximDisassemblyWindow.cc:346
Conversion.hh
EVT_MENU_RANGE
EVT_MENU_RANGE(ProximConstants::COMMAND_FIRST, ProximConstants::COMMAND_LAST, ProximMainFrame::onCommandEvent) EVT_MENU_RANGE(ProximConstants
Definition: ProximMainFrame.cc:91
StopPointManager
Definition: StopPointManager.hh:50
NullInstruction.hh
Breakpoint.hh
ProximDisassemblyWindow::onRunUntil
void onRunUntil(wxCommandEvent &event)
Definition: ProximDisassemblyWindow.cc:314
StopPoint.hh
DisasmTopCountAttrProvider.hh
ProximDisassemblyWindow::initialize
void initialize()
Definition: ProximDisassemblyWindow.cc:105
ProximDisassemblyWindow::onRightClick
void onRightClick(wxGridEvent &event)
Definition: ProximDisassemblyWindow.cc:209
TracedSimulatorFrontend.hh
ProximConstants.hh
StopPoint::isEnabled
virtual bool isEnabled() const
Definition: StopPoint.cc:73
ProximConstants::SCL_SET_BREAKPOINT
static const std::string SCL_SET_BREAKPOINT
Command for setting breakpoints in the simulator control language.
Definition: ProximConstants.hh:151
AssocTools.hh
ProximDisassemblyWindow::onMappedMenuCommand
void onMappedMenuCommand(wxCommandEvent &event)
Definition: ProximDisassemblyWindow.cc:373
ProximDisassemblyWindow::loadProgram
void loadProgram(const TTAProgram::Program &program)
Definition: ProximDisassemblyWindow.cc:179
ProximDisassemblyGridTable
Definition: ProximDisassemblyGridTable.hh:47
WxConversion.hh
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
EVT_SIMULATOR_PROGRAM_LOADED
#define EVT_SIMULATOR_PROGRAM_LOADED(id, fn)
Definition: SimulatorEvent.hh:151
SimulatorEvent
Definition: SimulatorEvent.hh:42
ProximDisassemblyWindow::showAddress
void showAddress(unsigned address)
Definition: ProximDisassemblyWindow.cc:359
StopPointManager::stopPointHandle
unsigned int stopPointHandle(unsigned int index)
Definition: StopPointManager.cc:231
ProximDisassemblyWindow
Definition: ProximDisassemblyWindow.hh:58
ProximDisassemblyGridTable.hh
ProximDisassemblyWindow::onProgramLoaded
void onProgramLoaded(const SimulatorEvent &event)
Definition: ProximDisassemblyWindow.cc:198
ProximDisassemblyWindow::onSimulatorStop
void onSimulatorStop(const SimulatorEvent &event)
Definition: ProximDisassemblyWindow.cc:328
ProximDisassemblyWindow::onSetBreakpoint
void onSetBreakpoint(wxCommandEvent &event)
Definition: ProximDisassemblyWindow.cc:286
EVT_SIMULATOR_STOP
#define EVT_SIMULATOR_STOP(id, fn)
Definition: SimulatorEvent.hh:106
SimulatorFrontend::stopPointManager
StopPointManager & stopPointManager()
Definition: SimulatorFrontend.cc:2108
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
ProximConstants::SCL_SET_TEMP_BP
static const std::string SCL_SET_TEMP_BP
Command for setting temporary breakpointss in the sim.con.language.
Definition: ProximConstants.hh:153