OpenASIP 2.2
Loading...
Searching...
No Matches
MemoryGridTable.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 MemoryGridTable.cc
26 *
27 * Implementation of MemoryGridTable class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34#include "MemoryGridTable.hh"
35#include "Conversion.hh"
36#include "WxConversion.hh"
37#include "Memory.hh"
38
39using std::string;
40
41const Word MemoryGridTable::MAX_ROWS = 600000000;
42const string MemoryGridTable::NOT_AVAILABLE = "N/A";
43
44/**
45 * The Constructor.
46 *
47 * @param memory Memory to display in the grid.
48 */
50 wxGridTableBase(),
51 memory_(memory),
52 dataMode_(DATA_HEX),
53 sizeMode_(SIZE_MAU),
54 numberOfColumns_(8) {
55
56 start_ = memory.start();
57 end_ = memory.end();
58 mauSize_ = memory.MAUSize();
59
60 // Kludge to avoid overflow with some calculations when the AS size = 2^32.
61 // The grid-widget is not capable of displaying enough rows,
62 // so the last address wouldn't be displayed anyway.
63 if (start_ == 0 && end_ == 0xffffffff) end_ = 0xfffffffe;
64}
65
66
67/**
68 * The Destructor.
69 */
72
73
74/**
75 * Returns row count of the grid.
76 *
77 * The row count is limited to MAX_ROWS due to limtiations of wxGrid.
78 *
79 * @return Number of rows in the table.
80 */
81int
83
84 Word size = end_ - start_ + 1;
85 Word cells = size / sizeOfCell();
86 Word rows = cells / numberOfColumns_;
87 if ((cells % numberOfColumns_) != 0) {
88 rows++;
89 }
90 if (rows > MAX_ROWS) {
91 rows = MAX_ROWS;
92 }
93 return rows;
94}
95
96/**
97 * Returns column count of the grid.
98 *
99 * @return Number of coulmns in the table.
100 */
101int
105
106
107/**
108 * Returns true, if the given cell is empty, false otherwise.
109 *
110 * @param row Row of the cell.
111 * @param col Column of the cell.
112 * @return True, if the column is empty.
113 */
114bool
115MemoryGridTable::IsEmptyCell(int /* row UNUSED */, int /* col UNUSED */) {
116 return false;
117}
118
119
120/**
121 * Returns cell value as a wxString.
122 *
123 * Returns memory contents corresponding to the cell coordinates. The
124 * memory value is formatted to the string depending on the size and
125 * type modes set.
126 *
127 * @param row Row of the cell.
128 * @param col Column of the cell.
129 * @return Cell contents as a wxString.
130 */
131wxString
132MemoryGridTable::GetValue(int row, int col) {
133
134 unsigned addr =
135 start_ + (row * numberOfColumns_ * sizeOfCell()) +
136 (col * sizeOfCell());
137
138 if ((addr + sizeOfCell()) > (end_ + 1)) {
140 }
141
142 wxString value = memoryContents(addr);
143 return value;
144}
145
146
147/**
148 * Returns row label of a grid row.
149 *
150 * The label is the memory address of the first cell in the row.
151 *
152 * @param row Row number.
153 * @return Label for the grid row.
154 */
155wxString
157
158 string address = Conversion::toHexString(
160
161 return WxConversion::toWxString(address);
162}
163
164
165/**
166 * Returns column label of a grid column.
167 *
168 * The label is the offset of the column compared to the first cell in the
169 * row.
170 *
171 * @param col Column number.
172 * @return Label for the grid column.
173 */
174wxString
176 string offset = Conversion::toHexString(col * sizeOfCell());
177 return WxConversion::toWxString(offset);
178}
179
180
181/**
182 * Not implemented, use setCellValue() instead.
183 */
184void
185MemoryGridTable::SetValue(int, int, const wxString&) {
186 // Do nothing.
187}
188
189
190/**
191 * Returns contents of the given memory contents as a wxString.
192 *
193 * The string formatting depends on the current sizeMode_ and dataMode_ set.
194 *
195 * @param addr Memory address to return.
196 * @return Memory contents as a wxString.
197 */
198wxString
200
201 unsigned size = sizeOfCell();
202 string dataString = NOT_AVAILABLE;
203 unsigned int cellSize = sizeOfCell() * mauSize_;
204
205 if ((size * mauSize_) <= sizeof(SIntWord) * BYTE_BITWIDTH) {
206
207 // read one word
208 ULongWord data = 0;
209
210 if (addr < start_ || addr > end_) {
211 // memory not available
213 } else {
214 memory_.read(addr, size, data);
215 }
216
217
218 if (dataMode_ == DATA_BIN) {
219 dataString =
220 Conversion::toBinary(static_cast<int>(data), cellSize);
221 } else if (dataMode_ == DATA_HEX) {
222 unsigned digits = cellSize / 4;
223 if ((cellSize % 4) != 0) {
224 cellSize++;
225 }
226 dataString = Conversion::toHexString(data, digits);
227 } else if (dataMode_ == DATA_SIGNED_INT) {
228 int extendedValue = data;
229 extendedValue =
230 extendedValue <<
231 ((sizeof(extendedValue)*BYTE_BITWIDTH) - cellSize);
232 extendedValue =
233 extendedValue >>
234 ((sizeof(extendedValue)*BYTE_BITWIDTH) - cellSize);
235 dataString = Conversion::toString(extendedValue);
236 } else if (dataMode_ == DATA_UNSIGNED_INT) {
237 dataString = Conversion::toString(data);
238 } else if (dataMode_ == DATA_FLOAT &&
239 cellSize == sizeof(FloatWord) * BYTE_BITWIDTH) {
240
241 FloatWord flt;
242 memory_.read(addr, flt);
243 dataString = Conversion::toString(flt);
244 }
245 } else if ((size * mauSize_) <= sizeof(DoubleWord) * BYTE_BITWIDTH) {
246
247 // Only double display is available due to the limitations of
248 // stringstream hex/bin conversion.
250 && cellSize == sizeof(DoubleWord) * BYTE_BITWIDTH) {
251
252 // read one double word
253 DoubleWord data = 0;
254 if (addr < start_ || addr > end_) {
255 // memory not available
257 } else {
258 memory_.read(addr, data);
259 }
260
261 dataString = Conversion::toString(data);
262 }
263 }
264 return WxConversion::toWxString(dataString);
265}
266
267
268
269/**
270 * Sets the number of columns to display.
271 *
272 * @param columns New table width.
273 */
274void
276 numberOfColumns_ = columns;
277}
278
279
280/**
281 * Sets the data display mode of the table.
282 *
283 * @param mode Data display mode to set.
284 */
285void
289
290
291/**
292 * Sets the memory size per cell.
293 *
294 * @param mode Size mode to set.
295 */
296void
300
301
302/**
303 * Sets the memory value correspoding to a cell.
304 *
305 * @param row Row of the cell.
306 * @param column Column of the cell.
307 * @param memoryValue Value to set.
308 */
309void
310MemoryGridTable::writeValue(int row, int column, UIntWord memoryValue) {
311 Word address = start_;
312 address += cellAddress(row, column);
313 int size = sizeOfCell();
314 if (address < end_) {
315 memory_.write(address, size, memoryValue);
317 }
318}
319
320
321/**
322 * Sets the memory value correspoding to a cell.
323 *
324 * @param row Row of the cell.
325 * @param column Column of the cell.
326 * @param memoryValue Value to set.
327 */
328void
329MemoryGridTable::writeValue(int row, int column, DoubleWord memoryValue) {
330 Word address = start_;
331 address += cellAddress(row, column);
332 if (address < end_) {
333 memory_.write(address, memoryValue);
335 }
336}
337
338
339/**
340 * Calculates the address of given cell.
341 *
342 * @param row The selected row.
343 * @param colummn The selected column.
344 * @return Address of the cell.
345 */
346Word
347MemoryGridTable::cellAddress(int row, int column) const {
348 Word address = 0;
349 unsigned size = sizeOfCell();
350 address += column * size;
351 address += row * numberOfColumns_ * size;
352 return address;
353}
354
355
356/**
357 * Returns row and column nubmer of the address in the table.
358 *
359 * @param address Memory address to find.
360 * @param row Variable to set the row to.
361 * @param col Variable to set the column to.
362 */
363void
364MemoryGridTable::findAddress(Word addr, int& row, int& col) {
365 unsigned cellSize = sizeOfCell();
366 row = addr / ((unsigned)numberOfColumns_ * cellSize);
367 col = (addr % ((unsigned)numberOfColumns_ * cellSize)) / cellSize;
368}
369
370
371/**
372 * Returns size of memory displayed in a single cell.
373 *
374 * @return Memory size of a cell.
375 */
376unsigned
378 if (sizeMode_ == SIZE_MAU) {
379 return 1;
380 } else if (sizeMode_ == SIZE_TWO_MAUS) {
381 return 2;
382 } else if (sizeMode_ == SIZE_FOUR_MAUS) {
383 return 4;
384 } else if (sizeMode_ == SIZE_EIGHT_MAUS) {
385 return 8;
386 }
387 assert(false);
388 return 0;
389}
#define assert(condition)
unsigned long ULongWord
Definition BaseType.hh:51
Word UIntWord
Definition BaseType.hh:144
float FloatWord
Definition BaseType.hh:160
const Byte BYTE_BITWIDTH
Definition BaseType.hh:136
double DoubleWord
Definition BaseType.hh:166
SignedWord SIntWord
Definition BaseType.hh:149
static std::string toHexString(T source, std::size_t digits=0, bool include0x=true)
static std::string toBinary(unsigned int source, unsigned int stringWidth=0)
static std::string toString(const T &source)
void writeValue(int row, int column, UIntWord memoryValue)
Word start_
Start address of the memory range to display.
int mauSize_
Size of MAU in bits.
void setNumberOfColumns(unsigned columns)
virtual wxString GetValue(int row, int col)
wxString memoryContents(ULongWord addr)
virtual wxString GetRowLabelValue(int row)
virtual int GetNumberCols()
static const Word MAX_ROWS
Maximum number of rows to display in the window.
void findAddress(Word addr, int &row, int &col)
DataMode dataMode_
Current data mode of the window (hex/binary/int...).
virtual wxString GetColLabelValue(int col)
MemoryGridTable(Memory &memory)
unsigned sizeOfCell() const
Memory & memory_
Memory to access.
Word cellAddress(int row, int column) const
void setDataMode(DataMode mode)
Word end_
End address of the memory range to display.
void setSizeMode(SizeMode mode)
static const std::string NOT_AVAILABLE
String that is displayed in a cell that is not in the current AS.
virtual int GetNumberRows()
SizeMode sizeMode_
Current size mode of the window (1/2/4... MAUs per cell).
virtual ~MemoryGridTable()
virtual void SetValue(int row, int col, const wxString &value)
virtual bool IsEmptyCell(int row, int col)
unsigned numberOfColumns_
Current number of columns in the grid.
virtual ULongWord end()
Definition Memory.hh:117
virtual void advanceClock()
Definition Memory.cc:819
virtual void write(ULongWord address, MAU data)=0
Definition Memory.cc:95
virtual Memory::MAU read(ULongWord address)=0
Definition Memory.cc:160
virtual ULongWord MAUSize()
Definition Memory.hh:118
virtual ULongWord start()
Definition Memory.hh:116
static wxString toWxString(const std::string &source)
mode
Definition tceopgen.cc:45