OpenASIP 2.2
Loading...
Searching...
No Matches
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
55using namespace TTAProgram;
56
60 0, ProximDisassemblyWindow::onSimulatorCommand)
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
70using std::string;
71
72const unsigned ProximDisassemblyWindow::INFO_COLUMN_WIDTH = 30;
73const unsigned ProximDisassemblyWindow::ADDRESS_COLUMN_WIDTH = 60;
74const unsigned ProximDisassemblyWindow::BP_COLUMN_WIDTH = 80;
75const 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 */
99
100
101/**
102 * Creates the window contents.
103 */
104void
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 */
116void
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 */
154void
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 */
178void
191
192
193/**
194 * Updates disassembly window when a program is loaded to the
195 * simulator.
196 */
197void
201
202
203/**
204 * Handles RMB clicks on the disassembly window.
205 *
206 * A context menu is displayed at the cursor location.
207 */
208void
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 */
285void
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 */
299void
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 */
313void
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 */
327void
329 Word pc = wxGetApp().simulation()->frontend()->programCounter();
330 if (codeTable_->moveCellAttrProvider() != NULL) {
332 }
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 */
345void
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 */
358void
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 */
372void
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 */
390void
#define assert(condition)
END_EVENT_TABLE() using namespace IDF
find Finds info of the inner loops in the program
EVT_MENU_RANGE(ProximConstants::COMMAND_FIRST, ProximConstants::COMMAND_LAST, ProximMainFrame::onCommandEvent) EVT_MENU_RANGE(ProximConstants
#define EVT_SIMULATOR_COMMAND_DONE(id, fn)
#define EVT_SIMULATOR_PROGRAM_LOADED(id, fn)
#define EVT_SIMULATOR_STOP(id, fn)
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
virtual InstructionAddress address() const
Definition Breakpoint.cc:86
static std::string toString(const T &source)
void loadProgram(const TTAProgram::Program &program)
int rowOfAddress(Word address)
static const std::string SCL_RUN_UNTIL
Command for running until specified instruciton is encoutnered.
static const std::string SCL_SET_BREAKPOINT
Command for setting breakpoints in the simulator control language.
static const std::string SCL_SET_TEMP_BP
Command for setting temporary breakpointss in the sim.con.language.
void setMoveCellAttrProvider(ProximDisasmAttrProvider *attrProvider)
void setStopPointManager(StopPointManager &manager)
ProximDisasmAttrProvider * moveCellAttrProvider() const
void onSimulatorStop(const SimulatorEvent &event)
std::map< unsigned, std::string > menuCommand_
A map which contains command strings for context menu items.
void onSimulatorCommand(SimulatorEvent &event)
void loadProgram(const TTAProgram::Program &program)
ProximDisassemblyGridTable * codeTable_
Grid table which handles on-the-fly disassembly of the loaded program.
void setMoveAttrProvider(ProximDisasmAttrProvider *attrProvider)
void showAddress(unsigned address)
void onRunUntil(wxCommandEvent &event)
void onSetTempBp(wxCommandEvent &event)
wxGrid * codeGrid_
The grid disapleying the disassembly.
void onMappedMenuCommand(wxCommandEvent &event)
void onRightClick(wxGridEvent &event)
void onSetBreakpoint(wxCommandEvent &event)
void onProgramLoaded(const SimulatorEvent &event)
static const TTAProgram::Program & program()
static TracedSimulatorFrontend * frontend()
StopPointManager & stopPointManager()
unsigned int stopPointCount()
const StopPoint & stopPointWithHandleConst(unsigned int handle) const
unsigned int stopPointHandle(unsigned int index)
virtual bool isEnabled() const
Definition StopPoint.cc:73
static wxString toWxString(const std::string &source)