OpenASIP  2.0
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>
34 #include "DisassemblyGridTable.hh"
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 
47 using std::string;
48 
49 using namespace TTAProgram;
50 
51 
52 /**
53  * The Constructor.
54  */
56  wxGridTableBase(), program_(NULL), disassembler_(NULL) {
57 
58 }
59 
60 
61 /**
62  * The Destructor.
63  */
65  if (disassembler_ != NULL) {
66  delete disassembler_;
67  }
68 }
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  */
78 int
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  */
91 int
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  */
107 bool
108 DisassemblyGridTable::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  */
120 wxString
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)) {
144  disasm = WxConversion::toWxString(
145  disassembly->move(col - 1).toString());
146  } else {
147  int immCount = static_cast<int>(disassembly->longImmediateCount());
148  if (col < (busCount + 1 + immCount)) {
149  disasm = WxConversion::toWxString(
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  */
167 wxString
169  return WxConversion::toWxString(row);
170 }
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  */
179 wxString
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  */
203 bool
205  return true;
206 }
207 
208 
209 /**
210  * Not implemented, use setCellValue() instead.
211  */
212 void
213 DisassemblyGridTable::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  */
223 void
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  */
253 Word
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  */
265 int
267  return (int)address;
268 }
DisassemblyGridTable::GetRowLabelValue
virtual wxString GetRowLabelValue(int row)
Definition: DisassemblyGridTable.cc:168
TTAProgram
Definition: Estimator.hh:65
TTAProgram::Program
Definition: Program.hh:63
TTAProgram::Program::firstInstruction
Instruction & firstInstruction() const
Definition: Program.cc:353
DisassemblyGridTable::GetColLabelValue
virtual wxString GetColLabelValue(int col)
Definition: DisassemblyGridTable.cc:180
WxConversion::toWxString
static wxString toWxString(const std::string &source)
DisassemblyGridTable::GetValue
virtual wxString GetValue(int row, int col)
Definition: DisassemblyGridTable.cc:121
DisassemblyInstruction::longImmediateCount
Word longImmediateCount() const
Definition: DisassemblyInstruction.cc:109
DisassemblyGridTable::labels_
LabelMap labels_
Program labels.
Definition: DisassemblyGridTable.hh:80
DisassemblyGridTable::IsEmptyCell
virtual bool IsEmptyCell(int row, int col)
Definition: DisassemblyGridTable.cc:108
DisassemblyGridTable::loadProgram
void loadProgram(const TTAProgram::Program &program)
Definition: DisassemblyGridTable.cc:224
Procedure.hh
DisassemblyGridTable::addressOfRow
Word addressOfRow(int row)
Definition: DisassemblyGridTable.cc:254
TTAMachine::Machine::Navigator::count
int count() const
TTAProgram::GlobalScope::globalCodeLabelCount
int globalCodeLabelCount(Address address) const
Definition: GlobalScope.cc:93
TTAProgram::CodeLabel::address
virtual Address address() const
Definition: CodeLabel.cc:101
Conversion::toString
static std::string toString(const T &source)
POMDisassembler.hh
GlobalScope.hh
TTAProgram::Program::globalScopeConst
const GlobalScope & globalScopeConst() const
Definition: Program.cc:192
TTAProgram::Label::name
std::string name() const
Definition: Label.cc:74
DisassemblyInstruction.hh
Conversion.hh
POMDisassembler
Definition: POMDisassembler.hh:70
DisassemblyGridTable::GetNumberRows
virtual int GetNumberRows()
Definition: DisassemblyGridTable.cc:79
NullInstruction.hh
TTAProgram::CodeLabel
Definition: CodeLabel.hh:49
TTAProgram::GlobalScope
Definition: GlobalScope.hh:47
TTAProgram::Address::location
InstructionAddress location() const
Machine.hh
DisassemblyImmediateAssignment::toString
virtual std::string toString() const
Definition: DisassemblyImmediateAssignment.cc:67
TTAMachine::Machine::immediateSlotNavigator
virtual ImmediateSlotNavigator immediateSlotNavigator() const
Definition: Machine.cc:462
DisassemblyGridTable::rowOfAddress
int rowOfAddress(Word address)
Definition: DisassemblyGridTable.cc:266
DisassemblyGridTable::SetValue
virtual void SetValue(int row, int col, const wxString &value)
Definition: DisassemblyGridTable.cc:213
DisassemblyGridTable::DisassemblyGridTable
DisassemblyGridTable()
Definition: DisassemblyGridTable.cc:55
Program.hh
AssocTools.hh
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
TTAProgram::Program::targetProcessor
TTAMachine::Machine & targetProcessor() const
Definition: Program.cc:202
DisassemblyGridTable::GetNumberCols
virtual int GetNumberCols()
Definition: DisassemblyGridTable.cc:92
DisassemblyGridTable::program_
const TTAProgram::Program * program_
Program loaded in the table.
Definition: DisassemblyGridTable.hh:71
TTAProgram::GlobalScope::globalCodeLabel
const CodeLabel & globalCodeLabel(Address address, int index) const
Definition: GlobalScope.cc:118
WxConversion.hh
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
DisassemblyGridTable::CanHaveAttributes
virtual bool CanHaveAttributes()
Definition: DisassemblyGridTable.cc:204
DisassemblyInstruction::move
DisassemblyInstructionSlot & move(Word index) const
Definition: DisassemblyInstruction.cc:82
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
TTAProgram::Program::lastInstruction
Instruction & lastInstruction() const
Definition: Program.cc:463
DisassemblyGridTable::disassembler_
POMDisassembler * disassembler_
Disassembler for generating instruction disassemblies.
Definition: DisassemblyGridTable.hh:74
DisassemblyInstructionSlot::toString
virtual std::string toString() const =0
DisassemblyInstruction::longImmediate
DisassemblyImmediateAssignment & longImmediate(Word index) const
Definition: DisassemblyInstruction.cc:122
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
CodeLabel.hh
DisassemblyGridTable::~DisassemblyGridTable
virtual ~DisassemblyGridTable()
Definition: DisassemblyGridTable.cc:64
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327
DisassemblyGridTable.hh
DisassemblyInstruction
Definition: DisassemblyInstruction.hh:46
POMDisassembler::createInstruction
virtual DisassemblyInstruction * createInstruction(Word instructionIndex) const
Definition: POMDisassembler.cc:137