OpenASIP 2.2
Loading...
Searching...
No Matches
DisassemblyGridTable.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 DisassemblyGridTable.cc
26 *
27 * Implementation of DisassemblyGridTable class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
35#include "Conversion.hh"
36#include "WxConversion.hh"
37#include "Program.hh"
38#include "POMDisassembler.hh"
39#include "AssocTools.hh"
41#include "NullInstruction.hh"
42#include "Machine.hh"
43#include "GlobalScope.hh"
44#include "CodeLabel.hh"
45#include "Procedure.hh"
46
47using std::string;
48
49using namespace TTAProgram;
50
51
52/**
53 * The Constructor.
54 */
56 wxGridTableBase(), program_(NULL), disassembler_(NULL) {
57
58}
59
60
61/**
62 * The Destructor.
63 */
69
70
71/**
72 * Returns row count of the grid.
73 *
74 * The row count is limited to MAX_ROWS due to limtiations of wxGrid.
75 *
76 * @return Number of rows in the table.
77 */
78int
80 Word firstAddress = program_->firstInstruction().address().location();
81 Word lastAddress = program_->lastInstruction().address().location();
82 return lastAddress - firstAddress + 1;
83}
84
85
86/**
87 * Returns column count of the grid.
88 *
89 * @return Number of coulmns in the table.
90 */
91int
93 int busCount = program_->targetProcessor().busNavigator().count();
94 int immSlotCount =
96 return busCount + immSlotCount + 1;
97}
98
99
100/**
101 * Returns true, if the given cell is empty, false otherwise.
102 *
103 * @param row Row of the cell.
104 * @param col Column of the cell.
105 * @return True, if the column is empty.
106 */
107bool
108DisassemblyGridTable::IsEmptyCell(int /* row UNUSED */, int /* col UNUSED */) {
109 return false;
110}
111
112
113/**
114 * Returns cell value as a wxString.
115 *
116 * @param row Row of the cell.
117 * @param col Column of the cell.
118 * @return Cell contents as a wxString.
119 */
120wxString
122
123 int busCount = program_->targetProcessor().busNavigator().count();
124
125 if (col == 0) {
126 wxString labels = WxConversion::toWxString("");
127 std::pair<LabelMap::iterator, LabelMap::iterator> range =
128 labels_.equal_range(row);
129 LabelMap::iterator firstEqual = range.first;
130 LabelMap::iterator lastEqual = range.second;
131 while (firstEqual != lastEqual) {
132 labels += WxConversion::toWxString(firstEqual->second)
134 firstEqual++;
135 }
136 return labels;
137 } else if (col > 0) {
138 Word address = (Word) row;
139 DisassemblyInstruction* disassembly =
141
142 wxString disasm;
143 if (col < (busCount + 1)) {
145 disassembly->move(col - 1).toString());
146 } else {
147 int immCount = static_cast<int>(disassembly->longImmediateCount());
148 if (col < (busCount + 1 + immCount)) {
150 disassembly->longImmediate(col - 1 - busCount).toString());
151 }
152 }
153 delete disassembly;
154 return disasm;
155 }
156
157 return _T("");
158}
159
160
161/**
162 * Returns row label of a grid row.
163 *
164 * @param row Row number.
165 * @return Label for the grid row.
166 */
167wxString
171
172
173/**
174 * Returns column label of a grid column.
175 *
176 * @param col Column number.
177 * @return Label for the grid column.
178 */
179wxString
181
182 int busCount = program_->targetProcessor().busNavigator().count();
183
184 if (col > 0 && col < (busCount + 1)) {
185 const TTAMachine::Machine::BusNavigator& navigator =
187
188 string label = Conversion::toString(col - 1);
189 label += ": ";
190 label += navigator.item(col - 1)->name();
191 return WxConversion::toWxString(label);
192 } else {
193 return _T("");
194 }
195}
196
197
198/**
199 * Returns true if the grid cells can have attributes.
200 *
201 * @return Always true.
202 */
203bool
207
208
209/**
210 * Not implemented, use setCellValue() instead.
211 */
212void
213DisassemblyGridTable::SetValue(int, int, const wxString&) {
214 // Do nothing.
215}
216
217
218/**
219 * Loads a new program in the grid table.
220 *
221 * @param program Program to load.
222 */
223void
225
226 program_ = &program;
227
228 if (disassembler_ != NULL) {
229 delete disassembler_;
230 }
231
233
234 labels_.clear();
235
236 const GlobalScope& gScope = program_->globalScopeConst();
237 int labelCount = gScope.globalCodeLabelCount();
238
239 for (int i = 0; i < labelCount; i++) {
240 const CodeLabel& codeLabel = gScope.globalCodeLabel(i);
241 unsigned address = codeLabel.address().location();
242 std::string label = codeLabel.name();
243 labels_.insert(std::pair<unsigned, string>(address, label));
244 }
245}
246
247/**
248 * Returns address of the instruction on a row.
249 *
250 * @param row Row of the instruction.
251 * @return Address of the instruction.
252 */
253Word
255 return (Word)row;
256}
257
258
259/**
260 * Returns row of the instruction with given address.
261 *
262 * @param address Address of the instruction.
263 * @return Row of the instruction.
264 */
265int
267 return (int)address;
268}
find Finds info of the inner loops in the program
static std::string toString(const T &source)
virtual wxString GetColLabelValue(int col)
virtual bool IsEmptyCell(int row, int col)
virtual wxString GetValue(int row, int col)
virtual wxString GetRowLabelValue(int row)
void loadProgram(const TTAProgram::Program &program)
int rowOfAddress(Word address)
POMDisassembler * disassembler_
Disassembler for generating instruction disassemblies.
virtual void SetValue(int row, int col, const wxString &value)
LabelMap labels_
Program labels.
const TTAProgram::Program * program_
Program loaded in the table.
virtual std::string toString() const =0
DisassemblyInstructionSlot & move(Word index) const
DisassemblyImmediateAssignment & longImmediate(Word index) const
virtual DisassemblyInstruction * createInstruction(Word instructionIndex) const
ComponentType * item(int index) const
virtual ImmediateSlotNavigator immediateSlotNavigator() const
Definition Machine.cc:462
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
InstructionAddress location() const
virtual Address address() const
Definition CodeLabel.cc:101
const CodeLabel & globalCodeLabel(Address address, int index) const
int globalCodeLabelCount(Address address) const
Address address() const
std::string name() const
Definition Label.cc:74
Instruction & firstInstruction() const
Definition Program.cc:353
Instruction & lastInstruction() const
Definition Program.cc:463
const GlobalScope & globalScopeConst() const
Definition Program.cc:192
TTAMachine::Machine & targetProcessor() const
Definition Program.cc:202
static wxString toWxString(const std::string &source)