OpenASIP  2.0
ProximMemoryWindow.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 ProximMemoryWindow.cc
26  *
27  * Definition of ProximMemoryWindow class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 
34 #include <string>
35 #include <wx/statline.h>
36 #include <wx/spinctrl.h>
37 
38 #include "ProximMemoryWindow.hh"
39 #include "MemoryControl.hh"
40 #include "WxConversion.hh"
41 #include "MemorySystem.hh"
42 #include "Proxim.hh"
45 #include "Machine.hh"
46 #include "MemoryProxy.hh"
47 #include "Conversion.hh"
48 
49 BEGIN_EVENT_TABLE(ProximMemoryWindow, ProximSimulatorWindow)
52  EVT_CHOICE(ID_AS_CHOICE, ProximMemoryWindow::onASChoice)
54 
55 using std::string;
56 using namespace TTAMachine;
57 
58 
59 /**
60  * Constructor.
61  *
62  * @param parent Parent window of the window.
63  * @param id Window identifier.
64  */
66  ProximMainFrame* parent, int id):
67  ProximSimulatorWindow(parent, id, wxDefaultPosition, wxSize(800,600)),
68  memorySystem_(NULL),
69  memoryControl_(NULL), asInfoText_(NULL) {
70 
71  createContents();
72  simulator_ = wxGetApp().simulation()->frontend();
73 
74  if (simulator_->isSimulationInitialized() ||
75  simulator_->isSimulationStopped() ||
76  simulator_->hasSimulationEnded()) {
77 
78  loadProgramMemory();
79  }
80 }
81 
82 
83 /**
84  * Destructor.
85  */
87 }
88 
89 
90 /**
91  * Loads memory from the given address space to the memory window.
92  *
93  * @param as Address space of the memory to load.
94  */
95 void
97 
98  MemorySystem& memorySystem = simulator_->memorySystem();
99 
100  MemorySystem::MemoryPtr mem = memorySystem.memory(as);
101 
102  if (memoryControl_ == NULL) {
104  new MemoryControl(this, mem.get());
105  sizer_->Add(memoryControl_, 1, wxGROW);
106  sizer_->Layout();
107  Fit();
108  } else {
109  memoryControl_->setMemory(mem.get());
110  }
111 
112  wxString asInfo = WxConversion::toWxString(as.name());
113  asInfo.Prepend(_T(" "));
114  asInfo.Append(_T(": "));
115  asInfo.Append(
117 
118  asInfo.Append(_T(" - "));
119 
120  asInfo.Append(
122 
123  asInfo.Append(_T(" MAU: "));
124  asInfo.Append(WxConversion::toWxString(as.width()));
125  asInfoText_->SetLabel(asInfo);
126 }
127 
128 
129 /**
130  * Event handler which is called when a new program is loaded in the simulator.
131  */
132 void
135 }
136 
137 /**
138  * Resets the window when a new program or machine is being loaded in the
139  * simulator.
140  */
141 void
143  asChoice_->Clear();
144  asInfoText_->SetLabel(_T(""));
145  if (memoryControl_ != NULL) {
146  memoryControl_->Destroy();
147  memoryControl_ = NULL;
148  }
149 }
150 
151 /**
152  * Initializes simulated memory system in the window.
153  */
154 void
156  asChoice_->Clear();
157  MemorySystem& memorySystem = simulator_->memorySystem();
158 
159  for (unsigned int i = 0; i < memorySystem.memoryCount(); i++) {
160  string asName = memorySystem.addressSpace(i).name();
161  asChoice_->Append(WxConversion::toWxString(asName));
162  }
163  asChoice_->SetSelection(0);
164  wxCommandEvent dummy;
165  onASChoice(dummy);
166 }
167 
168 
169 /**
170  * Event handler for the address space choicer.
171  *
172  * Loads the selected address space in the memory control.
173  */
174 void
176  MemorySystem& memorySystem = simulator_->memorySystem();
177  const AddressSpace& as =
178  memorySystem.addressSpace(asChoice_->GetSelection());
179  loadMemory(as);
180 }
181 
182 
183 /**
184  * Event handler for simulation stop.
185  *
186  * Refreshes the memory display.
187  */
188 void
190 
192 
193  MemorySystem& memorySystem = simulator_->memorySystem();
194  MemoryProxy* mem = dynamic_cast<MemoryProxy*>(
195  memorySystem.memory(asChoice_->GetSelection()).get());
196 
197  if (mem != NULL) {
198 
199  unsigned reads = mem->readAccessCount();
200  for (unsigned i = 0; i < reads; i++) {
201  MemoryProxy::MemoryAccess access = mem->readAccess(i);
203  access.first, access.second, *wxGREEN);
204  }
205 
206  unsigned writes = mem->writeAccessCount();
207  for (unsigned i = 0; i < writes; i++) {
208  MemoryProxy::MemoryAccess access = mem->writeAccess(i);
210  access.first, access.second, *wxRED);
211  }
212  }
214 }
215 
216 
217 /**
218  * Creates the window contents.
219  */
220 void
222 
223  sizer_= new wxBoxSizer(wxVERTICAL);
224  wxBoxSizer *item1 = new wxBoxSizer(wxHORIZONTAL);
225  wxStaticText *item2 = new wxStaticText(
226  this, ID_TEXT_AS, wxT("Address space:"),
227  wxDefaultPosition, wxDefaultSize, 0);
228 
229  item1->Add(item2, 0, wxALIGN_CENTER|wxALL, 5);
230 
231  wxString *strs3 = (wxString*) NULL;
232  asChoice_ = new wxChoice(
233  this, ID_AS_CHOICE, wxDefaultPosition, wxSize(150,-1), 0, strs3, 0);
234 
235  item1->Add(asChoice_, 0, wxALIGN_CENTER|wxALL, 5);
236  sizer_->Add(item1, 0, wxALIGN_CENTER|wxALL, 5);
237 
238  wxStaticLine *item4 = new wxStaticLine(
239  this, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL);
240 
241  sizer_->Add(item4, 0, wxGROW|wxALL, 5);
242 
243  asInfoText_ = new wxStaticText(this, ID_TEXT_AS_INFO, wxT(""));
244  sizer_->Add(asInfoText_, 0, wxGROW|wxALL, 5);
245 
246  this->SetSizer(sizer_);
247  sizer_->SetSizeHints(this);
248 
249 }
ProximMemoryWindow::loadMemory
void loadMemory(const TTAMachine::AddressSpace &as)
Definition: ProximMemoryWindow.cc:96
ProximMainFrame
Definition: ProximMainFrame.hh:58
ProximMemoryWindow.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
MemoryControl::highlight
void highlight(Word address, unsigned count, const wxColour &colour)
Definition: MemoryControl.cc:564
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
ProximMemoryWindow::ID_TEXT_AS
@ ID_TEXT_AS
Definition: ProximMemoryWindow.hh:87
ProximMemoryWindow::~ProximMemoryWindow
virtual ~ProximMemoryWindow()
Definition: ProximMemoryWindow.cc:86
TTAMachine::AddressSpace
Definition: AddressSpace.hh:51
ProximMemoryWindow::ID_TEXT_AS_INFO
@ ID_TEXT_AS_INFO
Definition: ProximMemoryWindow.hh:88
ProximMemoryWindow::onProgramLoaded
void onProgramLoaded(const SimulatorEvent &event)
Definition: ProximMemoryWindow.cc:133
ProximMemoryWindow::asChoice_
wxChoice * asChoice_
Address space choicer widget.
Definition: ProximMemoryWindow.hh:78
ProximMemoryWindow
Definition: ProximMemoryWindow.hh:54
MemoryProxy::readAccess
MemoryAccess readAccess(unsigned int idx) const
Definition: MemoryProxy.cc:133
ProximSimulationThread.hh
ProximMemoryWindow::onASChoice
void onASChoice(wxCommandEvent &event)
Definition: ProximMemoryWindow.cc:175
Proxim.hh
ProximMemoryWindow::loadProgramMemory
void loadProgramMemory()
Definition: ProximMemoryWindow.cc:155
MemoryControl::clearHighlights
void clearHighlights()
Definition: MemoryControl.cc:553
MemorySystem.hh
MemoryProxy::MemoryAccess
std::pair< Word, int > MemoryAccess
Definition: MemoryProxy.hh:56
MemoryProxy::writeAccessCount
unsigned int writeAccessCount() const
Definition: MemoryProxy.cc:145
MemorySystem::MemoryPtr
boost::shared_ptr< Memory > MemoryPtr
Definition: MemorySystem.hh:57
ProximSimulatorWindow
Definition: ProximSimulatorWindow.hh:47
MemorySystem::memoryCount
unsigned int memoryCount() const
Definition: MemorySystem.cc:226
MemoryControl::updateView
void updateView()
Definition: MemoryControl.cc:290
ProximMemoryWindow::asInfoText_
wxStaticText * asInfoText_
Static text control displaying address space information.
Definition: ProximMemoryWindow.hh:82
ProximMemoryWindow::memoryControl_
MemoryControl * memoryControl_
MemoryControl widget which displays the memory contents.
Definition: ProximMemoryWindow.hh:72
MemoryControl
Definition: MemoryControl.hh:53
MemoryProxy
Definition: MemoryProxy.hh:53
Conversion.hh
dummy
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
MemoryProxy.hh
ProximMemoryWindow::ID_LINE
@ ID_LINE
Definition: ProximMemoryWindow.hh:93
MemoryControl.hh
Machine.hh
MemorySystem
Definition: MemorySystem.hh:55
ProximMemoryWindow::onSimulationStop
void onSimulationStop(const SimulatorEvent &event)
Definition: ProximMemoryWindow.cc:189
MemoryControl::setMemory
void setMemory(Memory *memory)
Definition: MemoryControl.cc:477
Conversion::toHexString
static std::string toHexString(T source, std::size_t digits=0, bool include0x=true)
TTAMachine::AddressSpace::width
virtual int width() const
Definition: AddressSpace.cc:155
ProximMemoryWindow::simulator_
SimulatorFrontend * simulator_
Simulator instance which contains the memory system to display.
Definition: ProximMemoryWindow.hh:74
ProximMemoryWindow::createContents
void createContents()
Definition: ProximMemoryWindow.cc:221
TracedSimulatorFrontend.hh
ProximMemoryWindow::ID_AS_CHOICE
@ ID_AS_CHOICE
Definition: ProximMemoryWindow.hh:86
SimulatorFrontend::memorySystem
MemorySystem & memorySystem(int coreId=-1)
Definition: SimulatorFrontend.cc:2121
ProximMemoryWindow::reset
virtual void reset()
Definition: ProximMemoryWindow.cc:142
MemoryProxy::writeAccess
MemoryAccess writeAccess(unsigned int idx) const
Definition: MemoryProxy.cc:157
MemorySystem::memory
MemoryPtr memory(const TTAMachine::AddressSpace &as)
Definition: MemorySystem.cc:170
ProximMemoryWindow::sizer_
wxBoxSizer * sizer_
Toplevel sizer for the window widgets.
Definition: ProximMemoryWindow.hh:76
WxConversion.hh
EVT_SIMULATOR_PROGRAM_LOADED
#define EVT_SIMULATOR_PROGRAM_LOADED(id, fn)
Definition: SimulatorEvent.hh:151
SimulatorEvent
Definition: SimulatorEvent.hh:42
TTAMachine
Definition: Assembler.hh:48
MemorySystem::addressSpace
const TTAMachine::AddressSpace & addressSpace(unsigned int i)
Definition: MemorySystem.cc:261
TTAMachine::AddressSpace::start
virtual ULongWord start() const
Definition: AddressSpace.cc:166
TTAMachine::AddressSpace::end
virtual ULongWord end() const
Definition: AddressSpace.cc:177
EVT_SIMULATOR_STOP
#define EVT_SIMULATOR_STOP(id, fn)
Definition: SimulatorEvent.hh:106
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
MemoryProxy::readAccessCount
unsigned int readAccessCount() const
Definition: MemoryProxy.cc:122