OpenASIP 2.2
Loading...
Searching...
No Matches
BlockImplementationDialog.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 BlockImplementationDialog.cc
26 *
27 * Implementation of BlockImplementationDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30 * @author Esa Määttä 2007 (esa.maatta-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#include <wx/statline.h>
36#include "HDBManager.hh"
37#include "HDBRegistry.hh"
38#include "WxConversion.hh"
39#include "ErrorDialog.hh"
40#include "RegisterFile.hh"
41#include "FunctionUnit.hh"
42#include "FUEntry.hh"
43#include "RFEntry.hh"
44#include "RFImplementation.hh"
45#include "RFArchitecture.hh"
46#include "FUImplementation.hh"
47#include "FUArchitecture.hh"
48#include "Conversion.hh"
50#include "WidgetTools.hh"
51#include "StringTools.hh"
52#include "InformationDialog.hh"
53#include "ImmediateUnit.hh"
54
55#if wxCHECK_VERSION(3, 0, 0)
56 #define wxOPEN wxFD_OPEN
57 #define wxFILE_MUST_EXIST wxFD_FILE_MUST_EXIST
58#endif
59
60BEGIN_EVENT_TABLE(BlockImplementationDialog, wxDialog)
63 EVT_CHOICE(ID_HDB_CHOICE, BlockImplementationDialog::onHDBSelection)
64
65 EVT_LIST_ITEM_FOCUSED(ID_LIST, BlockImplementationDialog::onImplSelection)
66 EVT_LIST_DELETE_ITEM(ID_LIST, BlockImplementationDialog::onImplSelection)
71)
72using namespace IDF;
73using namespace TTAMachine;
74using namespace HDB;
75
76std::set<std::string> BlockImplementationDialog::hdbs_;
77int BlockImplementationDialog::selection_ = 0;
78const std::string BlockImplementationDialog::defaultHDB_("asic_130nm_1.5V.hdb");
79/**
80 * The Constructor.
81 *
82 * @param parent Parent window of the dialog.
83 * @param block Block to select the implementation for.
84 * @param impl IDF UnitImplementationLocation object for the block.
85 */
87 wxWindow* parent, const TTAMachine::Component& block,
88 UnitImplementationLocation& impl) :
89 wxDialog(parent, -1, _T("Select implementation from a HDB file"),
90 wxDefaultPosition, wxDefaultSize,
91 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
92 block_(block), impl_(impl) {
93
94 createContents(this, true, true);
95 SetSize(wxSize(580, 300));
96
97 list_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_LIST));
98 hdbChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_HDB_CHOICE));
99
100 list_->InsertColumn(0, _T("module name"), wxLIST_FORMAT_LEFT, 150);
101 list_->InsertColumn(1, _T("id"), wxLIST_FORMAT_LEFT, 50);
102 list_->InsertColumn(2, _T("param size"), wxLIST_FORMAT_LEFT, 100);
103 list_->InsertColumn(3, _T("param width"), wxLIST_FORMAT_LEFT, 100);
104
105 if (dynamic_cast<const RegisterFile*>(&block) != 0) {
106 list_->InsertColumn(4, _T("guard latency"), wxLIST_FORMAT_LEFT, 170);
107 }
108
110 registry.loadFromSearchPaths();
111 for (int i = 0; i < registry.hdbCount(); i++) {
112 hdbs_.insert(registry.hdbPath(i));
113 }
114 if (!hdbs_.empty()) {
115 std::set<std::string>::iterator iter = hdbs_.begin();
116 bool defaultHDBFound = false;
117 for (; iter != hdbs_.end(); iter++) {
118 std::string shortPath = Environment::shortHDBPath(*iter);
119 hdbChoice_->Append(WxConversion::toWxString(shortPath));
120 if (!defaultHDBFound && StringTools::endsWith(*iter, defaultHDB_)) {
121 selection_ = hdbChoice_->GetCount() - 1;
122 defaultHDBFound = true;
123 }
124 }
125 hdbChoice_->SetSelection(selection_);
126 wxCommandEvent dummy;
127 onHDBSelection(dummy);
128 }
129 FindWindow(wxID_OK)->Disable();
130}
131
132/**
133 * The Destructor.
134 */
137
138/**
139 * Event handler for the 'Browse...' button.
140 *
141 * Opens a file dialog.
142 */
143void
145 wxFileDialog dialog(
146 this, _T("Choose a HDB file containing the implementation"),
147 _T(""), _T(""), _T("HDBs|*.hdb|All files|*.*"),
148 (wxOPEN | wxFILE_MUST_EXIST));
149
150 if (dialog.ShowModal() == wxID_OK) {
151 std::string hdb = std::string(dialog.GetPath().mb_str());
152 hdb = Environment::shortHDBPath(hdb);
153 auto wxHDB = WxConversion::toWxString(hdb);
154 int item = hdbChoice_->FindString(wxHDB);
155 if (item == wxNOT_FOUND) {
156 item = hdbChoice_->Append(wxHDB);
157 }
158 hdbChoice_->Select(item);
159 wxListEvent dummy;
161 }
162}
163
164void
166 if (list_->GetSelectedItemCount() == 1) {
167 FindWindow(wxID_OK)->Enable();
168 } else {
169 FindWindow(wxID_OK)->Disable();
170 }
171}
172
173/**
174 * Event handler for the HDB choicer widget.
175 */
176void
178
179 std::string path = WxConversion::toString(
180 hdbChoice_->GetStringSelection());
181 path = Environment::longHDBPath(path);
182
183 list_->DeleteAllItems();
184
185 try {
186 HDBManager& hdb = HDBRegistry::instance().hdb(path);
187
188 const FunctionUnit* fu = dynamic_cast<const FunctionUnit*>(&block_);
189 if (fu != NULL) {
190 int i = 0;
191 std::set<RowID> fuEntryIDs = hdb.fuEntriesByArchitecture(*fu);
192 if (fuEntryIDs.empty()) {
193 wxString message = _T("No implementations for '");
194 message.Append(WxConversion::toWxString(fu->name()));
195 message.Append(_T("' found in '"));
196 message.Append(hdbChoice_->GetStringSelection());
197 message.Append(_T("'."));
198 InformationDialog dialog(this, message);
199 dialog.ShowModal();
200 }
201 std::set<RowID>::iterator iter = fuEntryIDs.begin();
202 for (; iter != fuEntryIDs.end(); iter++) {
203
204 if (hdb.fuByEntryID(*iter)->hasImplementation()) {
205 const FUImplementation& impl =
206 hdb.fuByEntryID(*iter)->implementation();
207 const FUArchitecture& arch =
208 hdb.fuByEntryID(*iter)->architecture();
209 list_->InsertItem(
211 // we want to select the FU *entry ID* which points to the
212 // implementation
213 list_->SetItem(i, 1, WxConversion::toWxString(*iter));
214 if (arch.hasParameterizedWidth("p1")) {
215 list_->SetItem(i, 3, WxConversion::toWxString("*"));
216 }
217 }
218 }
219 }
220
221 // Register files.
222 const BaseRegisterFile* rf =
223 dynamic_cast<const BaseRegisterFile*>(&block_);
224
225 if (rf != NULL) {
226 int width = rf->width();
227 int size = rf->size();
228 int i = 0;
229 int readPorts = 0;
230 int writePorts = 0;
231 int bidirPorts = 0;
232 for (int p = 0; p < rf->portCount(); p++) {
233 const RFPort* port = rf->port(p);
234 if (port->inputSocket() != NULL &&
235 port->outputSocket() != NULL) {
236
237 bidirPorts++;
238 } else if (port->inputSocket() != NULL) {
239 writePorts++;
240 } else if (port->outputSocket() != NULL) {
241 readPorts++;
242 }
243 }
244
245 int maxReads = 0;
246 int maxWrites = 0;
247 int guardLatency = 0;
248 int latency = 1;
249 bool zeroRegister = false;
250 const RegisterFile* r = dynamic_cast<const RegisterFile*>(rf);
251 if (r != NULL) {
252 maxReads = r->maxReads();
253 maxWrites = r->maxWrites();
254 guardLatency = r->guardLatency();
255 zeroRegister = r->zeroRegister();
256 }
257 const ImmediateUnit* iu = dynamic_cast<const ImmediateUnit*>(rf);
258 if (iu != NULL) {
259 // TODO: XXX
260 latency = iu->latency();
261 // Immediate units have always one write port (not seen in adf)
262 writePorts = 1;
263 }
264 std::set<RowID> rfEntryIDs =
266 readPorts, writePorts, bidirPorts,
267 maxReads,
268 maxWrites,
269 latency,
270 r->isUsedAsGuard(),
271 guardLatency,
272 width,
273 size,
274 zeroRegister);
275
276 if (rfEntryIDs.empty()) {
277 wxString message = _T("No implementations for '");
278 message.Append(WxConversion::toWxString(rf->name()));
279 message.Append(_T("' found in '"));
280 message.Append(hdbChoice_->GetStringSelection());
281 message.Append(_T("'."));
282 InformationDialog dialog(this, message);
283 dialog.ShowModal();
284 }
285 std::set<RowID>::iterator iter = rfEntryIDs.begin();
286 for (; iter != rfEntryIDs.end(); iter++) {
287 if (hdb.rfByEntryID(*iter)->hasImplementation()) {
288
289 const RFImplementation& impl =
290 hdb.rfByEntryID(*iter)->implementation();
291
292 const RFArchitecture& arch =
293 hdb.rfByEntryID(*iter)->architecture();
294
295 list_->InsertItem(
297
298 // we want to select the RF *entry ID* which points to the
299 // implementation
300 list_->SetItem(i, 1, WxConversion::toWxString(*iter));
301
302 if (arch.hasParameterizedSize()) {
303 list_->SetItem(i, 2, WxConversion::toWxString("*"));
304 }
305 if (arch.hasParameterizedWidth()) {
306 list_->SetItem(i, 3, WxConversion::toWxString("*"));
307 }
308
309 list_->SetItem(i, 4, r->isUsedAsGuard() ?
310 WxConversion::toWxString(guardLatency) :
311 WxConversion::toWxString("not used as guard"));
312 }
313 }
314
315 }
316 } catch (Exception& e) {
317 wxString message = _T("Error opening '");
318 message.Append(WxConversion::toWxString(path));
319 message.Append(_T("':\n\n"));
320 message.Append(WxConversion::toWxString(e.errorMessage()));
321 ErrorDialog dialog(this, message);
322 dialog.ShowModal();
323 hdbChoice_->Delete(hdbChoice_->GetSelection());
324 return;
325 }
326
327 hdbs_.insert(path);
328 selection_ = hdbChoice_->GetSelection();
329}
330
331/**
332 * Do the things that are done to close the dialog on ok
333 */
334void
336 std::string HDBpath = WxConversion::toString(
337 hdbChoice_->GetStringSelection());
338 HDBpath = Environment::longHDBPath(HDBpath);
339 impl_.setHDBFile(HDBpath);
341 impl_.setID(id);
342 EndModal(wxID_OK);
343}
344
345/**
346 * Event handler for the OK button.
347 *
348 * Updates the UnitImplementationLocation object.
349 */
350void
352 doOK();
353}
354
355/**
356 * Event handler for list activation OK button.
357 *
358 * Updates the UnitImplementationLocation object.
359 */
360void
364
365/**
366 * Creates the dialog widgets.
367 */
368wxSizer*
370 wxWindow *parent,
371 bool call_fit,
372 bool set_sizer) {
373 wxFlexGridSizer *item0 = new wxFlexGridSizer( 1, 0, 0 );
374 item0->AddGrowableCol( 0 );
375 item0->AddGrowableRow( 1 );
376
377 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
378
379 wxString *strs2 = (wxString*) NULL;
380 wxChoice *item2 = new wxChoice( parent, ID_HDB_CHOICE, wxDefaultPosition, wxSize(250,-1), 0, strs2, 0 );
381 item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
382
383 wxButton *item3 = new wxButton( parent, ID_BROWSE, wxT("Browse..."), wxDefaultPosition, wxDefaultSize, 0 );
384 item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
385
386 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
387
388 wxListCtrl *item4 = new wxListCtrl( parent, ID_LIST, wxDefaultPosition, wxSize(300,120), wxLC_REPORT|wxSUNKEN_BORDER );
389 item0->Add( item4, 0, wxGROW|wxALL, 5 );
390
391 wxStaticLine *item5 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
392 item0->Add( item5, 0, wxGROW|wxALL, 5 );
393
394 wxBoxSizer *item6 = new wxBoxSizer( wxHORIZONTAL );
395
396 wxButton *item7 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
397 item6->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
398
399 wxButton *item8 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
400 item6->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
401
402 item0->Add( item6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
403
404 if (set_sizer)
405 {
406 parent->SetSizer( item0 );
407 if (call_fit)
408 item0->SetSizeHints( parent );
409 }
410
411 return item0;
412}
END_EVENT_TABLE() using namespace IDF
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection EVT_LIST_ITEM_DESELECTED(ID_ARCH_PORT_LIST, FUImplementationDialog::onArchPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_ARCH_PORT_LIST
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection FUImplementationDialog::onArchPortActivation EVT_LIST_ITEM_SELECTED(ID_EXTERNAL_PORT_LIST, FUImplementationDialog::onExternalPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_EXTERNAL_PORT_LIST
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection FUImplementationDialog::onArchPortActivation FUImplementationDialog::onExternalPortActivation FUImplementationDialog::onParameterSelection EVT_LIST_ITEM_ACTIVATED(ID_PARAMETER_LIST, FUImplementationDialog::onParameterActivation) EVT_LIST_ITEM_DESELECTED(ID_PARAMETER_LIST
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
const TTAMachine::Component & block_
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
static int selection_
Static variable for the hdb choicer selection.
IDF::UnitImplementationLocation & impl_
void onBrowse(wxCommandEvent &event)
void onOK(wxCommandEvent &event)
static std::set< std::string > hdbs_
Static set for hdb paths.
void onHDBSelection(wxCommandEvent &event)
void onImplSelection(wxListEvent &event)
static int toInt(const T &source)
static TCEString longHDBPath(const TCEString &hdbPath)
static TCEString shortHDBPath(const TCEString &hdbPath)
std::string errorMessage() const
Definition Exception.cc:123
bool hasParameterizedWidth(const std::string &port) const
FUImplementation & implementation() const
Definition FUEntry.cc:86
virtual bool hasImplementation() const
Definition FUEntry.cc:74
FUArchitecture & architecture() const
Definition FUEntry.cc:129
std::set< RowID > fuEntriesByArchitecture(const TTAMachine::FunctionUnit &fu) const
FUEntry * fuByEntryID(RowID id) const
std::set< RowID > rfEntriesByArchitecture(int readPorts, int writePorts, int bidirPorts, int maxReads, int maxWrites, int latency, bool guardSupport, int guardLatency=0, int width=0, int size=0, bool zeroRegister=false) const
RFEntry * rfByEntryID(RowID id) const
static HDBRegistry & instance()
CachedHDBManager & hdb(const std::string fileName)
void loadFromSearchPaths()
std::string hdbPath(unsigned int index)
bool hasParameterizedWidth() const
bool hasParameterizedSize() const
virtual bool hasImplementation() const
Definition RFEntry.cc:74
RFArchitecture & architecture() const
Definition RFEntry.cc:145
RFImplementation & implementation() const
Definition RFEntry.cc:102
virtual void setHDBFile(std::string file)
static bool endsWith(const std::string &source, const std::string &searchString)
virtual int size() const
virtual int width() const
virtual RFPort * port(const std::string &name) const
virtual TCEString name() const
virtual int latency() const
virtual Socket * outputSocket() const
Definition Port.cc:281
virtual Socket * inputSocket() const
Definition Port.cc:261
virtual int maxReads() const
virtual bool zeroRegister() const
virtual int guardLatency() const
virtual bool isUsedAsGuard() const
virtual int maxWrites() const
virtual int portCount() const
Definition Unit.cc:135
static std::string lcStringSelection(wxListCtrl *list, int column)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)