OpenASIP  2.0
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
MemoryGridTable Class Reference

#include <MemoryGridTable.hh>

Inheritance diagram for MemoryGridTable:
Inheritance graph
Collaboration diagram for MemoryGridTable:
Collaboration graph

Public Types

enum  SizeMode { SIZE_MAU, SIZE_TWO_MAUS, SIZE_FOUR_MAUS, SIZE_EIGHT_MAUS }
 
enum  DataMode {
  DATA_BIN, DATA_HEX, DATA_SIGNED_INT, DATA_UNSIGNED_INT,
  DATA_DOUBLE, DATA_FLOAT
}
 

Public Member Functions

 MemoryGridTable (Memory &memory)
 
virtual ~MemoryGridTable ()
 
virtual int GetNumberRows ()
 
virtual int GetNumberCols ()
 
virtual bool IsEmptyCell (int row, int col)
 
virtual wxString GetValue (int row, int col)
 
virtual wxString GetRowLabelValue (int row)
 
virtual wxString GetColLabelValue (int col)
 
virtual void SetValue (int row, int col, const wxString &value)
 
void writeValue (int row, int column, UIntWord memoryValue)
 
void writeValue (int row, int column, DoubleWord memoryValue)
 
void findAddress (Word addr, int &row, int &col)
 
void setNumberOfColumns (unsigned columns)
 
void setSizeMode (SizeMode mode)
 
void setDataMode (DataMode mode)
 
unsigned sizeOfCell () const
 

Private Member Functions

Word cellAddress (int row, int column) const
 
wxString memoryContents (ULongWord addr)
 

Private Attributes

Memorymemory_
 Memory to access. More...
 
Word start_
 Start address of the memory range to display. More...
 
Word end_
 End address of the memory range to display. More...
 
DataMode dataMode_
 Current data mode of the window (hex/binary/int...). More...
 
SizeMode sizeMode_
 Current size mode of the window (1/2/4... MAUs per cell). More...
 
int mauSize_
 Size of MAU in bits. More...
 
unsigned numberOfColumns_
 Current number of columns in the grid. More...
 

Static Private Attributes

static const std::string NOT_AVAILABLE = "N/A"
 String that is displayed in a cell that is not in the current AS. More...
 
static const int COLUMNS
 
static const Word MAX_ROWS = 600000000
 Maximum number of rows to display in the window. More...
 

Detailed Description

Grid table class which allows wxGrid to access TargetMemory contents without copying the memory contents to separate table.

Definition at line 47 of file MemoryGridTable.hh.

Member Enumeration Documentation

◆ DataMode

Enumerator
DATA_BIN 
DATA_HEX 
DATA_SIGNED_INT 
DATA_UNSIGNED_INT 
DATA_DOUBLE 
DATA_FLOAT 

Definition at line 71 of file MemoryGridTable.hh.

71  {
72  DATA_BIN,
73  DATA_HEX,
78  };

◆ SizeMode

Enumerator
SIZE_MAU 
SIZE_TWO_MAUS 
SIZE_FOUR_MAUS 
SIZE_EIGHT_MAUS 

Definition at line 64 of file MemoryGridTable.hh.

64  {
65  SIZE_MAU,
69  };

Constructor & Destructor Documentation

◆ MemoryGridTable()

MemoryGridTable::MemoryGridTable ( Memory memory)

The Constructor.

Parameters
memoryMemory to display in the grid.

Definition at line 49 of file MemoryGridTable.cc.

49  :
50  wxGridTableBase(),
51  memory_(memory),
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 }

References Memory::end(), end_, Memory::MAUSize(), mauSize_, Memory::start(), and start_.

Here is the call graph for this function:

◆ ~MemoryGridTable()

MemoryGridTable::~MemoryGridTable ( )
virtual

The Destructor.

Definition at line 70 of file MemoryGridTable.cc.

70  {
71 }

Member Function Documentation

◆ cellAddress()

Word MemoryGridTable::cellAddress ( int  row,
int  column 
) const
private

Calculates the address of given cell.

Parameters
rowThe selected row.
colummnThe selected column.
Returns
Address of the cell.

Definition at line 347 of file MemoryGridTable.cc.

347  {
348  Word address = 0;
349  unsigned size = sizeOfCell();
350  address += column * size;
351  address += row * numberOfColumns_ * size;
352  return address;
353 }

References numberOfColumns_, and sizeOfCell().

Referenced by writeValue().

Here is the call graph for this function:

◆ findAddress()

void MemoryGridTable::findAddress ( Word  addr,
int &  row,
int &  col 
)

Returns row and column nubmer of the address in the table.

Parameters
addressMemory address to find.
rowVariable to set the row to.
colVariable to set the column to.

Definition at line 364 of file MemoryGridTable.cc.

364  {
365  unsigned cellSize = sizeOfCell();
366  row = addr / ((unsigned)numberOfColumns_ * cellSize);
367  col = (addr % ((unsigned)numberOfColumns_ * cellSize)) / cellSize;
368 }

References numberOfColumns_, and sizeOfCell().

Referenced by MemoryControl::onGoTo().

Here is the call graph for this function:

◆ GetColLabelValue()

wxString MemoryGridTable::GetColLabelValue ( int  col)
virtual

Returns column label of a grid column.

The label is the offset of the column compared to the first cell in the row.

Parameters
colColumn number.
Returns
Label for the grid column.

Definition at line 175 of file MemoryGridTable.cc.

175  {
176  string offset = Conversion::toHexString(col * sizeOfCell());
177  return WxConversion::toWxString(offset);
178 }

References sizeOfCell(), Conversion::toHexString(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ GetNumberCols()

int MemoryGridTable::GetNumberCols ( )
virtual

Returns column count of the grid.

Returns
Number of coulmns in the table.

Definition at line 102 of file MemoryGridTable.cc.

102  {
103  return numberOfColumns_;
104 }

References numberOfColumns_.

Referenced by MemoryControl::clearHighlights(), and MemoryControl::highlight().

◆ GetNumberRows()

int MemoryGridTable::GetNumberRows ( )
virtual

Returns row count of the grid.

The row count is limited to MAX_ROWS due to limtiations of wxGrid.

Returns
Number of rows in the table.

Definition at line 82 of file MemoryGridTable.cc.

82  {
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 }

References end_, MAX_ROWS, numberOfColumns_, sizeOfCell(), and start_.

Here is the call graph for this function:

◆ GetRowLabelValue()

wxString MemoryGridTable::GetRowLabelValue ( int  row)
virtual

Returns row label of a grid row.

The label is the memory address of the first cell in the row.

Parameters
rowRow number.
Returns
Label for the grid row.

Definition at line 156 of file MemoryGridTable.cc.

156  {
157 
158  string address = Conversion::toHexString(
159  start_ + row * numberOfColumns_ * sizeOfCell());
160 
161  return WxConversion::toWxString(address);
162 }

References numberOfColumns_, sizeOfCell(), start_, Conversion::toHexString(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ GetValue()

wxString MemoryGridTable::GetValue ( int  row,
int  col 
)
virtual

Returns cell value as a wxString.

Returns memory contents corresponding to the cell coordinates. The memory value is formatted to the string depending on the size and type modes set.

Parameters
rowRow of the cell.
colColumn of the cell.
Returns
Cell contents as a wxString.

Definition at line 132 of file MemoryGridTable.cc.

132  {
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 }

References end_, memoryContents(), NOT_AVAILABLE, numberOfColumns_, sizeOfCell(), start_, and WxConversion::toWxString().

Here is the call graph for this function:

◆ IsEmptyCell()

bool MemoryGridTable::IsEmptyCell ( int  row,
int  col 
)
virtual

Returns true, if the given cell is empty, false otherwise.

Parameters
rowRow of the cell.
colColumn of the cell.
Returns
True, if the column is empty.

Definition at line 115 of file MemoryGridTable.cc.

115  {
116  return false;
117 }

◆ memoryContents()

wxString MemoryGridTable::memoryContents ( ULongWord  addr)
private

Returns contents of the given memory contents as a wxString.

The string formatting depends on the current sizeMode_ and dataMode_ set.

Parameters
addrMemory address to return.
Returns
Memory contents as a wxString.

Definition at line 199 of file MemoryGridTable.cc.

199  {
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.
249  if (dataMode_ == DATA_DOUBLE
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 }

References BYTE_BITWIDTH, DATA_BIN, DATA_DOUBLE, DATA_FLOAT, DATA_HEX, DATA_SIGNED_INT, DATA_UNSIGNED_INT, dataMode_, end_, mauSize_, memory_, NOT_AVAILABLE, Memory::read(), sizeOfCell(), Conversion::toBinary(), Conversion::toHexString(), Conversion::toString(), and WxConversion::toWxString().

Referenced by GetValue().

Here is the call graph for this function:

◆ setDataMode()

void MemoryGridTable::setDataMode ( DataMode  mode)

Sets the data display mode of the table.

Parameters
modeData display mode to set.

Definition at line 286 of file MemoryGridTable.cc.

286  {
287  dataMode_ = mode;
288 }

References dataMode_.

Referenced by MemoryControl::onDataModeChanged().

◆ setNumberOfColumns()

void MemoryGridTable::setNumberOfColumns ( unsigned  columns)

Sets the number of columns to display.

Parameters
columnsNew table width.

Definition at line 275 of file MemoryGridTable.cc.

275  {
276  numberOfColumns_ = columns;
277 }

References numberOfColumns_.

Referenced by MemoryControl::onWidthChanged().

◆ setSizeMode()

void MemoryGridTable::setSizeMode ( SizeMode  mode)

Sets the memory size per cell.

Parameters
modeSize mode to set.

Definition at line 297 of file MemoryGridTable.cc.

297  {
298  sizeMode_ = mode;
299 }

References sizeMode_.

Referenced by MemoryControl::onSizeModeChanged().

◆ SetValue()

void MemoryGridTable::SetValue ( int  row,
int  col,
const wxString &  value 
)
virtual

Not implemented, use setCellValue() instead.

Definition at line 185 of file MemoryGridTable.cc.

185  {
186  // Do nothing.
187 }

◆ sizeOfCell()

unsigned MemoryGridTable::sizeOfCell ( ) const

Returns size of memory displayed in a single cell.

Returns
Memory size of a cell.

Definition at line 377 of file MemoryGridTable.cc.

377  {
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 }

References assert, SIZE_EIGHT_MAUS, SIZE_FOUR_MAUS, SIZE_MAU, SIZE_TWO_MAUS, and sizeMode_.

Referenced by cellAddress(), findAddress(), GetColLabelValue(), GetNumberRows(), GetRowLabelValue(), GetValue(), memoryContents(), MemoryControl::onWriteMemory(), MemoryControl::updateView(), and writeValue().

◆ writeValue() [1/2]

void MemoryGridTable::writeValue ( int  row,
int  column,
DoubleWord  memoryValue 
)

Sets the memory value correspoding to a cell.

Parameters
rowRow of the cell.
columnColumn of the cell.
memoryValueValue to set.

Definition at line 329 of file MemoryGridTable.cc.

329  {
330  Word address = start_;
331  address += cellAddress(row, column);
332  if (address < end_) {
333  memory_.write(address, memoryValue);
335  }
336 }

References Memory::advanceClock(), cellAddress(), end_, memory_, start_, and Memory::write().

Here is the call graph for this function:

◆ writeValue() [2/2]

void MemoryGridTable::writeValue ( int  row,
int  column,
UIntWord  memoryValue 
)

Sets the memory value correspoding to a cell.

Parameters
rowRow of the cell.
columnColumn of the cell.
memoryValueValue to set.

Definition at line 310 of file MemoryGridTable.cc.

310  {
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 }

References Memory::advanceClock(), cellAddress(), end_, memory_, sizeOfCell(), start_, and Memory::write().

Referenced by MemoryControl::clearMemory(), and MemoryControl::onWriteMemory().

Here is the call graph for this function:

Member Data Documentation

◆ COLUMNS

const int MemoryGridTable::COLUMNS
staticprivate

Definition at line 98 of file MemoryGridTable.hh.

◆ dataMode_

DataMode MemoryGridTable::dataMode_
private

Current data mode of the window (hex/binary/int...).

Definition at line 102 of file MemoryGridTable.hh.

Referenced by memoryContents(), and setDataMode().

◆ end_

Word MemoryGridTable::end_
private

End address of the memory range to display.

Definition at line 94 of file MemoryGridTable.hh.

Referenced by GetNumberRows(), GetValue(), memoryContents(), MemoryGridTable(), and writeValue().

◆ mauSize_

int MemoryGridTable::mauSize_
private

Size of MAU in bits.

Definition at line 106 of file MemoryGridTable.hh.

Referenced by memoryContents(), and MemoryGridTable().

◆ MAX_ROWS

const Word MemoryGridTable::MAX_ROWS = 600000000
staticprivate

Maximum number of rows to display in the window.

Definition at line 100 of file MemoryGridTable.hh.

Referenced by GetNumberRows().

◆ memory_

Memory& MemoryGridTable::memory_
private

Memory to access.

Definition at line 90 of file MemoryGridTable.hh.

Referenced by memoryContents(), and writeValue().

◆ NOT_AVAILABLE

const string MemoryGridTable::NOT_AVAILABLE = "N/A"
staticprivate

String that is displayed in a cell that is not in the current AS.

Definition at line 97 of file MemoryGridTable.hh.

Referenced by GetValue(), and memoryContents().

◆ numberOfColumns_

unsigned MemoryGridTable::numberOfColumns_
private

Current number of columns in the grid.

Definition at line 108 of file MemoryGridTable.hh.

Referenced by cellAddress(), findAddress(), GetNumberCols(), GetNumberRows(), GetRowLabelValue(), GetValue(), and setNumberOfColumns().

◆ sizeMode_

SizeMode MemoryGridTable::sizeMode_
private

Current size mode of the window (1/2/4... MAUs per cell).

Definition at line 104 of file MemoryGridTable.hh.

Referenced by setSizeMode(), and sizeOfCell().

◆ start_

Word MemoryGridTable::start_
private

Start address of the memory range to display.

Definition at line 92 of file MemoryGridTable.hh.

Referenced by GetNumberRows(), GetRowLabelValue(), GetValue(), MemoryGridTable(), and writeValue().


The documentation for this class was generated from the following files:
MemoryGridTable::memory_
Memory & memory_
Memory to access.
Definition: MemoryGridTable.hh:90
MemoryGridTable::sizeMode_
SizeMode sizeMode_
Current size mode of the window (1/2/4... MAUs per cell).
Definition: MemoryGridTable.hh:104
WxConversion::toWxString
static wxString toWxString(const std::string &source)
mode
mode
Definition: tceopgen.cc:45
Memory::MAUSize
virtual ULongWord MAUSize()
Definition: Memory.hh:118
MemoryGridTable::memoryContents
wxString memoryContents(ULongWord addr)
Definition: MemoryGridTable.cc:199
MemoryGridTable::SIZE_MAU
@ SIZE_MAU
Definition: MemoryGridTable.hh:65
MemoryGridTable::DATA_SIGNED_INT
@ DATA_SIGNED_INT
Definition: MemoryGridTable.hh:74
Conversion::toString
static std::string toString(const T &source)
MemoryGridTable::DATA_UNSIGNED_INT
@ DATA_UNSIGNED_INT
Definition: MemoryGridTable.hh:75
assert
#define assert(condition)
Definition: Application.hh:86
MemoryGridTable::numberOfColumns_
unsigned numberOfColumns_
Current number of columns in the grid.
Definition: MemoryGridTable.hh:108
Conversion::toBinary
static std::string toBinary(unsigned int source, unsigned int stringWidth=0)
Definition: Conversion.cc:155
MemoryGridTable::DATA_HEX
@ DATA_HEX
Definition: MemoryGridTable.hh:73
FloatWord
float FloatWord
Definition: BaseType.hh:160
MemoryGridTable::DATA_FLOAT
@ DATA_FLOAT
Definition: MemoryGridTable.hh:77
MemoryGridTable::SIZE_EIGHT_MAUS
@ SIZE_EIGHT_MAUS
Definition: MemoryGridTable.hh:68
MemoryGridTable::start_
Word start_
Start address of the memory range to display.
Definition: MemoryGridTable.hh:92
SIntWord
SignedWord SIntWord
Definition: BaseType.hh:149
MemoryGridTable::dataMode_
DataMode dataMode_
Current data mode of the window (hex/binary/int...).
Definition: MemoryGridTable.hh:102
DoubleWord
double DoubleWord
Definition: BaseType.hh:166
Memory::read
virtual Memory::MAU read(ULongWord address)=0
Definition: Memory.cc:160
MemoryGridTable::mauSize_
int mauSize_
Size of MAU in bits.
Definition: MemoryGridTable.hh:106
Conversion::toHexString
static std::string toHexString(T source, std::size_t digits=0, bool include0x=true)
MemoryGridTable::DATA_DOUBLE
@ DATA_DOUBLE
Definition: MemoryGridTable.hh:76
Memory::advanceClock
virtual void advanceClock()
Definition: Memory.cc:819
MemoryGridTable::MAX_ROWS
static const Word MAX_ROWS
Maximum number of rows to display in the window.
Definition: MemoryGridTable.hh:100
Memory::write
virtual void write(ULongWord address, MAU data)=0
Definition: Memory.cc:95
BYTE_BITWIDTH
const Byte BYTE_BITWIDTH
Definition: BaseType.hh:136
Memory::end
virtual ULongWord end()
Definition: Memory.hh:117
MemoryGridTable::end_
Word end_
End address of the memory range to display.
Definition: MemoryGridTable.hh:94
ULongWord
unsigned long ULongWord
Definition: BaseType.hh:51
MemoryGridTable::SIZE_FOUR_MAUS
@ SIZE_FOUR_MAUS
Definition: MemoryGridTable.hh:67
MemoryGridTable::cellAddress
Word cellAddress(int row, int column) const
Definition: MemoryGridTable.cc:347
MemoryGridTable::sizeOfCell
unsigned sizeOfCell() const
Definition: MemoryGridTable.cc:377
MemoryGridTable::DATA_BIN
@ DATA_BIN
Definition: MemoryGridTable.hh:72
MemoryGridTable::SIZE_TWO_MAUS
@ SIZE_TWO_MAUS
Definition: MemoryGridTable.hh:66
MemoryGridTable::NOT_AVAILABLE
static const std::string NOT_AVAILABLE
String that is displayed in a cell that is not in the current AS.
Definition: MemoryGridTable.hh:97
Memory::start
virtual ULongWord start()
Definition: Memory.hh:116