OpenASIP  2.0
FUPortImplementationDialog.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 FUPortImplementationDialog.cc
26  *
27  * Implementation of FUPortImplementationDialog class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/statline.h>
34 #include <wx/valgen.h>
35 #include <wx/listctrl.h>
37 #include "FUPortImplementation.hh"
38 #include "WxConversion.hh"
39 #include "ErrorDialog.hh"
40 #include "FunctionUnit.hh"
41 #include "FUPort.hh"
42 #include "HWOperation.hh"
43 #include "Application.hh"
44 #include "ExecutionPipeline.hh"
45 
46 using namespace HDB;
47 using namespace TTAMachine;
48 
49 BEGIN_EVENT_TABLE(FUPortImplementationDialog, wxDialog)
52 
53 /**
54  * The Constructor.
55  *
56  * @param parent Parent window of the dialog.
57  * @param id Window identifier for the dialog window.
58  * @param implementation FU port implementation to modify.
59  * @param architecthre Architecture of the modified port.
60  */
62  wxWindow* parent, wxWindowID id, FUPortImplementation& implementation,
63  const BaseFUPort& architecture) :
64  wxDialog(parent, id, _T("Function Unit Port Implementation"),
65  wxDefaultPosition),
66  implementation_(implementation), architecture_(architecture) {
67 
68  createContents(this, true, true);
69 
70  operandList_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_OPERAND_LIST));
71  assert(operandList_ != NULL);
72  operandList_->InsertColumn(
73  0, _T("Operation"), wxLIST_FORMAT_LEFT, 140);
74 
75  operandList_->InsertColumn(
76  1, _T("R/W"), wxLIST_FORMAT_LEFT, 60);
77 
78  operandList_->InsertColumn(
79  2, _T("io"), wxLIST_FORMAT_LEFT, 60);
80 
81  name_ = WxConversion::toWxString(implementation_.name());
82  loadPortName_ = WxConversion::toWxString(
83  implementation_.loadPort());
84 
85  guardPortName_ = WxConversion::toWxString(
86  implementation_.guardPort());
87 
88  widthFormula_ = WxConversion::toWxString(
89  implementation_.widthFormula());
90 
91  FindWindow(ID_NAME)->SetValidator(wxTextValidator(wxFILTER_ASCII, &name_));
92  FindWindow(ID_LOAD_PORT)->SetValidator(
93  wxTextValidator(wxFILTER_ASCII, &loadPortName_));
94  FindWindow(ID_GUARD_PORT)->SetValidator(
95  wxTextValidator(wxFILTER_ASCII, &guardPortName_));
96  FindWindow(ID_WIDTH)->SetValidator(
97  wxTextValidator(wxFILTER_ASCII, &widthFormula_));
98 
99  dynamic_cast<wxStaticText*>(FindWindow(ID_ARCHITECTURE_PORT_NAME))->
100  SetLabel(WxConversion::toWxString(implementation_.architecturePort()));
101 
102  TransferDataToWindow();
103 }
104 
105 /**
106  * The Destructor.
107  */
109 }
110 
111 
112 /**
113  * Transfers data from the dialog attributes to the dialog widgets.
114  *
115  * @return True, if the data was succesfully transferred.
116  */
117 bool
119 
120  operandList_->DeleteAllItems();
121  const FunctionUnit* fu = architecture_.parentUnit();
122  const FUPort* fuPort = dynamic_cast<const FUPort*>(&architecture_);
123  assert(fu != NULL);
124  int item = 0;
125  for (int i = 0; i < fu->operationCount(); i++) {
126  const HWOperation* operation = fu->operation(i);
127  if (fuPort != NULL && operation->isBound(*fuPort)) {
128  wxString rw;
129  bool read = false;
130  bool written = false;
131  for (int cycle = 0; cycle < operation->latency(); cycle++) {
132  if (operation->pipeline()->isPortRead(*fuPort, cycle)) {
133  read = true;
134  }
135  if (operation->pipeline()->isPortWritten(*fuPort, cycle)) {
136  written = true;
137  }
138  }
139  if (read) {
140  rw.Append(_T("R"));
141  }
142  if (written) {
143  rw.Append(_T("W"));
144  }
145  operandList_->InsertItem(
146  item, WxConversion::toWxString(operation->name()));
147 
148  operandList_->SetItem(item, 1, rw);
149 
150  operandList_->SetItem(
151  item, 2, WxConversion::toWxString(operation->io(*fuPort)));
152 
153  item++;
154  }
155  }
156 
157  return wxDialog::TransferDataToWindow();
158 }
159 
160 /**
161  * Event handler for the dialog OK-button.
162  */
163 void
165 
166  TransferDataFromWindow();
167 
168  name_ = name_.Trim(true).Trim(false);
169  loadPortName_ = loadPortName_.Trim(true).Trim(false);
170  guardPortName_ = guardPortName_.Trim(true).Trim(false);
171  widthFormula_ = widthFormula_.Trim(true).Trim(false);
172 
173  if (name_.IsEmpty()) {
174  wxString message = _T("Name field must not be empty.");
175  ErrorDialog dialog(this, message);
176  dialog.ShowModal();
177  return;
178  }
179 
180  if (widthFormula_.IsEmpty()) {
181  wxString message = _T("Width formula field must not be empty.");
182  ErrorDialog dialog(this, message);
183  dialog.ShowModal();
184  return;
185  }
186 
187  implementation_.setName(WxConversion::toString(name_));
188  implementation_.setLoadPort(WxConversion::toString(loadPortName_));
189  implementation_.setGuardPort(WxConversion::toString(guardPortName_));
190  implementation_.setWidthFormula(WxConversion::toString(widthFormula_));
191 
192  EndModal(wxID_OK);
193 }
194 
195 /**
196  * Creates the dialog contents.
197  */
198 wxSizer*
200  wxWindow *parent, bool call_fit, bool set_sizer) {
201 
202  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
203 
204  wxBoxSizer *item1 = new wxBoxSizer( wxVERTICAL );
205 
206  wxFlexGridSizer *item2 = new wxFlexGridSizer( 2, 0, 0 );
207 
208  wxStaticText *item3 = new wxStaticText( parent, ID_LABEL_ARCHITECTURE_PORT, wxT("Architecture port:"), wxDefaultPosition, wxDefaultSize, 0 );
209  item2->Add( item3, 0, wxALIGN_RIGHT|wxALL, 5 );
210 
211  wxStaticText *item4 = new wxStaticText( parent, ID_ARCHITECTURE_PORT_NAME, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
212  item2->Add( item4, 0, wxGROW|wxALL, 5 );
213 
214  wxStaticText *item5 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
215  item2->Add( item5, 0, wxALIGN_RIGHT|wxALL, 5 );
216 
217  wxTextCtrl *item6 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(200,-1), 0 );
218  item2->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
219 
220  wxStaticText *item7 = new wxStaticText( parent, ID_LOAD_PORT_LABEL, wxT("Load port:"), wxDefaultPosition, wxDefaultSize, 0 );
221  item2->Add( item7, 0, wxALIGN_RIGHT|wxALL, 5 );
222 
223  wxTextCtrl *item8 = new wxTextCtrl( parent, ID_LOAD_PORT, wxT(""), wxDefaultPosition, wxSize(80,-1), 0 );
224  item2->Add( item8, 0, wxGROW|wxALL, 5 );
225 
226  wxStaticText *item9 = new wxStaticText( parent, ID_GUARD_PORT_LABEL, wxT("Guard port:"), wxDefaultPosition, wxDefaultSize, 0 );
227  item2->Add( item9, 0, wxALIGN_RIGHT|wxALL, 5 );
228 
229  wxTextCtrl *item10 = new wxTextCtrl( parent, ID_GUARD_PORT, wxT(""), wxDefaultPosition, wxSize(200,-1), 0 );
230  item2->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
231 
232  wxStaticText *item11 = new wxStaticText( parent, ID_LABEL_WIDTH, wxT("Width formula:"), wxDefaultPosition, wxDefaultSize, 0 );
233  item2->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
234 
235  wxTextCtrl *item12 = new wxTextCtrl( parent, ID_WIDTH, wxT(""), wxDefaultPosition, wxSize(80,-1), 0 );
236  item2->Add( item12, 0, wxGROW|wxALL, 5 );
237 
238  item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
239 
240  wxStaticBox *item14 = new wxStaticBox( parent, -1, wxT("Operand bindings:") );
241  wxStaticBoxSizer *item13 = new wxStaticBoxSizer( item14, wxVERTICAL );
242 
243  wxListCtrl *item15 = new wxListCtrl( parent, ID_OPERAND_LIST, wxDefaultPosition, wxSize(200,120), wxLC_REPORT|wxSUNKEN_BORDER );
244  item13->Add( item15, 0, wxGROW|wxALL, 5 );
245 
246  item1->Add( item13, 0, wxGROW|wxALL, 5 );
247 
248  item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
249 
250  wxStaticLine *item16 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
251  item0->Add( item16, 0, wxGROW|wxALL, 5 );
252 
253  wxBoxSizer *item17 = new wxBoxSizer( wxHORIZONTAL );
254 
255  wxButton *item18 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
256  item17->Add( item18, 0, wxALIGN_CENTER, 5 );
257 
258  wxButton *item19 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
259  item17->Add( item19, 0, wxALIGN_CENTER|wxALL, 5 );
260 
261  item0->Add( item17, 0, wxALL, 5 );
262 
263  if (set_sizer)
264  {
265  parent->SetSizer( item0 );
266  if (call_fit)
267  item0->SetSizeHints( parent );
268  }
269 
270  return item0;
271 }
FUPortImplementationDialog::~FUPortImplementationDialog
virtual ~FUPortImplementationDialog()
Definition: FUPortImplementationDialog.cc:108
FUPortImplementationDialog.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
HDB
Definition: CostDatabase.hh:49
TTAMachine::HWOperation
Definition: HWOperation.hh:52
ExecutionPipeline.hh
implementation
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:61
HDB::FUPortImplementation
Definition: FUPortImplementation.hh:46
TTAMachine::BaseFUPort
Definition: BaseFUPort.hh:44
FindWindow
Definition: FindWindow.hh:49
FUPortImplementation.hh
FUPortImplementationDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: FUPortImplementationDialog.cc:118
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAMachine::HWOperation::io
int io(const FUPort &port) const
Definition: HWOperation.cc:364
HWOperation.hh
TTAMachine::Unit
Definition: Unit.hh:51
ErrorDialog
Definition: ErrorDialog.hh:42
TTAMachine::HWOperation::name
const std::string & name() const
Definition: HWOperation.cc:141
ErrorDialog.hh
TTAMachine::Port
Definition: Port.hh:54
Application.hh
TTAMachine::ExecutionPipeline::isPortWritten
bool isPortWritten(const FUPort &port, int cycle) const
Definition: ExecutionPipeline.cc:386
FUPortImplementationDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Creates the dialog contents.
Definition: FUPortImplementationDialog.cc:199
TTAMachine::HWOperation::isBound
bool isBound(const FUPort &port) const
Definition: HWOperation.cc:338
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
TTAMachine::ExecutionPipeline::isPortRead
bool isPortRead(const FUPort &port, int cycle) const
Definition: ExecutionPipeline.cc:362
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
FUPortImplementationDialog::onOK
void onOK(wxCommandEvent &event)
Definition: FUPortImplementationDialog.cc:164
FUPort.hh
FUPortImplementationDialog
Definition: FUPortImplementationDialog.hh:49
TTAMachine::HWOperation::pipeline
ExecutionPipeline * pipeline() const
Definition: HWOperation.cc:201
WxConversion.hh
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
TTAMachine::HWOperation::latency
int latency() const
Definition: HWOperation.cc:216
TTAMachine
Definition: Assembler.hh:48
WxConversion::toString
static std::string toString(const wxString &source)
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
FunctionUnit.hh