OpenASIP  2.0
ProximRegisterWindow.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2010 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 ProximRegisterWindow.cc
26  *
27  * Definition of ProximRegisterWindow class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @author Pekka Jääskeläinen 2010
31  * @note rating: red
32  */
33 
34 
35 #include <string>
36 
37 #include "ProximRegisterWindow.hh"
38 #include "WxConversion.hh"
40 #include "ProximMainFrame.hh"
41 
42 #include "Machine.hh"
43 #include "RegisterFile.hh"
44 #include "RegisterFileState.hh"
45 #include "MachineState.hh"
46 #include "RegisterState.hh"
47 #include "StateData.hh"
48 #include "SimValue.hh"
51 
53 #include "DisassemblyFPRegister.hh"
55 #include "DisassemblyRegister.hh"
56 
57 #include "Conversion.hh"
58 
59 #include <wx/listctrl.h>
60 
61 using std::string;
62 using namespace TTAMachine;
63 
64 const std::string ProximRegisterWindow::RF_PREFIX = "RF: ";
65 const std::string ProximRegisterWindow::IMM_PREFIX = "IMM: ";
66 
67 /**
68  * Constructor.
69  *
70  * @param parent Parent window of the window.
71  * @param id Window identifier.
72  */
74  ProximMainFrame* parent, int id):
75  ProximUnitWindow(parent, id) {
76 
77  valueList_->InsertColumn(0, _T("Register"), wxLIST_FORMAT_LEFT, 100);
78  valueList_->InsertColumn(1, _T("Value"), wxLIST_FORMAT_RIGHT, 120);
79 
80  modeChoice_->Disable();
81 
85 
86  reinitialize();
87  }
88 }
89 
90 /**
91  * Destructor.
92  */
94 }
95 
96 
97 /**
98  * Sets the available register file selections in the register file choice.
99  */
100 void
102 
103  unitChoice_->Clear();
104 
105  // parallel simulation
106  const Machine::RegisterFileNavigator& rfNavigator =
108 
109  for (int i = 0; i < rfNavigator.count(); i++) {
110  string rfName = RF_PREFIX + rfNavigator.item(i)->name();
111  unitChoice_->Append(WxConversion::toWxString(rfName));
112  }
113 
114  const Machine::ImmediateUnitNavigator& immNavigator =
116  for (int i = 0; i < immNavigator.count(); i++) {
117  string rfName = IMM_PREFIX + immNavigator.item(i)->name();
118  unitChoice_->Append(WxConversion::toWxString(rfName));
119  }
120 
121  unitChoice_->SetSelection(0);
122  update();
123 }
124 
125 
126 /**
127  * Event handler for the register file choicer.
128  *
129  * When the choice selection changes, corresponding register file registers
130  * are loaded in the register list.
131  */
132 void
134 
135  int rfIndex = unitChoice_->GetSelection();
136 
137  modeChoice_->Disable();
138  modeChoice_->Enable();
139 
140  // Machine is not a universal machine.
141  const Machine::RegisterFileNavigator& rfNavigator =
143 
144  if (rfIndex < rfNavigator.count()) {
145  loadRegisterFile(*rfNavigator.item(rfIndex));
146  } else {
147  const Machine::ImmediateUnitNavigator& immNavigator =
149 
150  rfIndex = rfIndex - rfNavigator.count();
151  loadImmediateUnit(*immNavigator.item(rfIndex));
152  }
153 }
154 
155 /**
156  * Loads register file registers to the register list.
157  *
158  * @param rf Register file to display.
159  */
160 void
162 
163  valueList_->DeleteAllItems();
164 
165  RegisterFileState& rfState =
167 
168  // Append all registers to the register list.
169  int row = 0;
170  for (unsigned i = 0; i < rfState.registerCount(); i++) {
171  wxString value;
172  const RegisterState& state = rfState.registerState(i);
173 
174  wxString mode = modeChoice_->GetStringSelection();
175 
176  if (mode == MODE_UNSIGNED) {
177  value = WxConversion::toWxString(state.value().unsignedValue());
178  } else if (mode == MODE_INT) {
179  int intValue = state.value().intValue();
180  value = WxConversion::toWxString(intValue);
181  } else if (mode == MODE_HEX) {
182  value = WxConversion::toWxString(
184  } else if (mode == MODE_BIN) {
185  int intValue = state.value().intValue();
186  value = WxConversion::toWxString(
187  Conversion::toBinString(intValue));
188  }
189 
190  DisassemblyRegister r(rf.name(), i);
191  valueList_->InsertItem(
193 
194  valueList_->SetItem(row, 1, value);
195  row++;
196  }
197 }
198 
199 /**
200  * Loads register file registers to the register list.
201  *
202  * @param imm Immediate Unit to display.
203  */
204 void
206 
207  valueList_->DeleteAllItems();
208 
209  LongImmediateUnitState& immState =
211 
212  // Append all registers to the register list.
213  int row = 0;
214  for (int i = 0; i < immState.immediateRegisterCount(); i++) {
215  wxString value;
216 
217  const LongImmediateRegisterState& state =
218  immState.immediateRegister(i);
219 
220  wxString mode = modeChoice_->GetStringSelection();
221 
222  if (mode == MODE_UNSIGNED) {
223  value = WxConversion::toWxString(state.value().unsignedValue());
224  } else if (mode == MODE_INT) {
225  int intValue = state.value().intValue();
226  value = WxConversion::toWxString(intValue);
227  } else if (mode == MODE_HEX) {
228  value = WxConversion::toWxString(
230  } else if (mode == MODE_BIN) {
231  int intValue = static_cast<int>(state.value().unsignedValue());
232  value = WxConversion::toWxString(
233  Conversion::toBinString(intValue));
234  }
235 
236  DisassemblyRegister r(imm.name(), i);
237  valueList_->InsertItem(
239 
240  valueList_->SetItem(row, 1, value);
241  row++;
242  }
243 }
244 
245 
246 /**
247  * Sets the registerfile displayed in the window.
248  *
249  * @param name Name of the register file.
250  */
251 void
252 ProximRegisterWindow::showRegisterFile(const std::string& name) {
253 
254  unitChoice_->SetStringSelection(
256  update();
257 }
258 
259 /**
260  * Sets the immediate unit dipslayed in the window.
261  *
262  * @param name Name of the immediate unit.
263  */
264 void
265 ProximRegisterWindow::showImmediateUnit(const std::string& name) {
266 
267  unitChoice_->SetStringSelection(
269  update();
270 }
ProximMainFrame
Definition: ProximMainFrame.hh:58
SimValue::intValue
int intValue() const
Definition: SimValue.cc:895
LongImmediateUnitState::immediateRegister
virtual LongImmediateRegisterState & immediateRegister(int i)
Definition: LongImmediateUnitState.cc:160
MachineState::longImmediateUnitState
LongImmediateUnitState & longImmediateUnitState(const std::string &name)
Definition: MachineState.cc:196
ProximRegisterWindow::loadImmediateUnit
void loadImmediateUnit(const TTAMachine::ImmediateUnit &iu)
Definition: ProximRegisterWindow.cc:205
WxConversion::toWxString
static wxString toWxString(const std::string &source)
DisassemblyRegister::toString
std::string toString() const
Definition: DisassemblyRegister.cc:66
mode
mode
Definition: tceopgen.cc:45
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
RegisterFileState.hh
SimulatorFrontend::machine
const TTAMachine::Machine & machine() const
Definition: SimulatorFrontend.cc:263
ProximUnitWindow::modeChoice_
wxChoice * modeChoice_
Value display mode choicer widget.
Definition: ProximUnitWindow.hh:62
LongImmediateUnitState::immediateRegisterCount
virtual int immediateRegisterCount() const
Definition: LongImmediateUnitState.cc:174
SimulatorFrontend::isSimulationStopped
bool isSimulationStopped() const
Definition: SimulatorFrontend.cc:1271
ProximRegisterWindow::~ProximRegisterWindow
virtual ~ProximRegisterWindow()
Definition: ProximRegisterWindow.cc:93
ProximRegisterWindow::ProximRegisterWindow
ProximRegisterWindow(ProximMainFrame *parent, int id)
Definition: ProximRegisterWindow.cc:73
TTAMachine::Machine::Navigator::count
int count() const
ProximUnitWindow::MODE_UNSIGNED
static const wxString MODE_UNSIGNED
String for the mode choicer unsigned integer mode.
Definition: ProximUnitWindow.hh:69
DisassemblyFPRegister.hh
ProximUnitWindow::unitChoice_
wxChoice * unitChoice_
Unit choicer widget.
Definition: ProximUnitWindow.hh:60
LongImmediateUnitState.hh
ProximRegisterWindow::showImmediateUnit
void showImmediateUnit(const std::string &name)
Definition: ProximRegisterWindow.cc:265
RegisterState::value
virtual const SimValue & value() const
Definition: RegisterState.cc:92
LongImmediateRegisterState
Definition: LongImmediateRegisterState.hh:47
TTAMachine::Machine::immediateUnitNavigator
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition: Machine.cc:416
ProximUnitWindow::valueList_
wxListCtrl * valueList_
List widget for the values.
Definition: ProximUnitWindow.hh:64
Conversion.hh
LongImmediateRegisterState.hh
StateData.hh
ProximUnitWindow::MODE_INT
static const wxString MODE_INT
String for the mode choicer integer mode.
Definition: ProximUnitWindow.hh:67
ProximRegisterWindow::reinitialize
virtual void reinitialize()
Definition: ProximRegisterWindow.cc:101
ProximUnitWindow
Definition: ProximUnitWindow.hh:51
ProximRegisterWindow::RF_PREFIX
static const std::string RF_PREFIX
Prefix for register files in the unit choicer.
Definition: ProximRegisterWindow.hh:68
DisassemblyBoolRegister.hh
ProximRegisterWindow::update
virtual void update()
Definition: ProximRegisterWindow.cc:133
ProximUnitWindow::simulator_
SimulatorFrontend * simulator_
Simulator instance .
Definition: ProximUnitWindow.hh:58
Machine.hh
Conversion::toHexString
static std::string toHexString(T source, std::size_t digits=0, bool include0x=true)
ProximRegisterWindow::showRegisterFile
void showRegisterFile(const std::string &name)
Definition: ProximRegisterWindow.cc:252
DisassemblyIntRegister.hh
SimValue::unsignedValue
unsigned int unsignedValue() const
Definition: SimValue.cc:919
ProximRegisterWindow::loadRegisterFile
void loadRegisterFile(const TTAMachine::RegisterFile &rf)
Definition: ProximRegisterWindow.cc:161
TracedSimulatorFrontend.hh
TTAMachine::Machine::registerFileNavigator
virtual RegisterFileNavigator registerFileNavigator() const
Definition: Machine.cc:450
DisassemblyRegister.hh
RegisterFileState::registerCount
virtual std::size_t registerCount() const
Definition: RegisterFileState.cc:95
RegisterFileState::registerState
virtual RegisterState & registerState(int index)
Definition: RegisterFileState.cc:81
SimulatorFrontend::machineState
MachineState & machineState(int core=-1)
Definition: SimulatorFrontend.cc:2138
RegisterFile.hh
SimValue.hh
Conversion::toBinString
static std::string toBinString(int source)
Definition: Conversion.cc:81
ProximMainFrame.hh
MachineState.hh
RegisterFileState
Definition: RegisterFileState.hh:49
RegisterState
Definition: RegisterState.hh:50
DisassemblyRegister
Definition: DisassemblyRegister.hh:51
ProximUnitWindow::MODE_HEX
static const wxString MODE_HEX
String for the mode choicer hexadecimal mode.
Definition: ProximUnitWindow.hh:71
RegisterState.hh
WxConversion.hh
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
ProximRegisterWindow::IMM_PREFIX
static const std::string IMM_PREFIX
Prefix for immediate units in the unit choicer.
Definition: ProximRegisterWindow.hh:70
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
SimulatorFrontend::hasSimulationEnded
bool hasSimulationEnded() const
Definition: SimulatorFrontend.cc:1283
ProximRegisterWindow.hh
TTAMachine
Definition: Assembler.hh:48
ProximUnitWindow::MODE_BIN
static const wxString MODE_BIN
String for the mode choicer binary mode.
Definition: ProximUnitWindow.hh:73
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
SimulatorFrontend::isSimulationInitialized
bool isSimulationInitialized() const
Definition: SimulatorFrontend.cc:1228
LongImmediateUnitState
Definition: LongImmediateUnitState.hh:55
LongImmediateRegisterState::value
virtual const SimValue & value() const
Definition: LongImmediateRegisterState.cc:99
MachineState::registerFileState
RegisterFileState & registerFileState(const std::string &name)
Definition: MachineState.cc:213
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50