OpenASIP 2.2
Loading...
Searching...
No Matches
AddRFFromHDBDialog.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 AddRFFromHDBDialog.cc
26 *
27 * Implementation of AddRFFromHDBDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <boost/format.hpp>
34#include <wx/statline.h>
35#include <wx/listctrl.h>
36#include <wx/dir.h>
37#include <wx/imaglist.h>
38
39#include "AddRFFromHDBDialog.hh"
40#include "Model.hh"
41#include "Machine.hh"
42#include "WxConversion.hh"
43#include "WidgetTools.hh"
44#include "HDBManager.hh"
45#include "RFArchitecture.hh"
46#include "WarningDialog.hh"
47#include "MapTools.hh"
48#include "Environment.hh"
49#include "FileSystem.hh"
50#include "HDBRegistry.hh"
51#include "Conversion.hh"
52#include "ProDeConstants.hh"
53
54#if !wxCHECK_VERSION(3, 0, 0)
55 typedef long int wxIntPtr;
56#endif
57
58using std::string;
59using boost::format;
60using namespace TTAMachine;
61using namespace HDB;
62
63BEGIN_EVENT_TABLE(AddRFFromHDBDialog, wxDialog)
68 EVT_LIST_COL_CLICK(ID_LIST, AddRFFromHDBDialog::onColumnClick)
70
71
72const int AddRFFromHDBDialog::DEFAULT_SIZE = 1;
73const int AddRFFromHDBDialog::DEFAULT_WIDTH = 32;
74const wxString AddRFFromHDBDialog::HDB_FILE_FILTER = _T("*.hdb");
75
76int wxCALLBACK
77RFListCompareASC(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData) {
78
79 ListItemData* lid1 = (ListItemData*)item1;
80 ListItemData* lid2 = (ListItemData*)item2;
81 int sortColumn = (int)sortData;
82
83 if (sortColumn == 0) {
84 return lid1->width - lid2->width;
85 } else if (sortColumn == 1) {
86 return lid1->size - lid2->size;
87 } else if (sortColumn == 2) {
88 return lid1->readPorts - lid2->readPorts;
89 } else if (sortColumn == 3) {
90 return lid1->writePorts - lid2->writePorts;
91 } else if (sortColumn == 4) {
92 return lid1->bidirPorts - lid2->bidirPorts;
93 } else if (sortColumn == 5) {
94 return lid1->maxReads - lid2->maxReads;
95 } else if (sortColumn == 6) {
96 return lid1->maxWrites - lid2->maxWrites;
97 } else if (sortColumn == 7) {
98 return lid1->hdbId - lid2->hdbId;
99 } else if (sortColumn == 8) {
100 return lid1->path.Cmp(lid2->path);
101 }
102
103 return 0;
104}
105
106int wxCALLBACK
108
109 ListItemData* lid1 = (ListItemData*)item1;
110 ListItemData* lid2 = (ListItemData*)item2;
111 int sortColumn = (int)sortData;
112
113 if (sortColumn == 0) {
114 return lid2->width - lid1->width;
115 } else if (sortColumn == 1) {
116 return lid2->size - lid1->size;
117 } else if (sortColumn == 2) {
118 return lid2->readPorts - lid1->readPorts;
119 } else if (sortColumn == 3) {
120 return lid2->writePorts - lid1->writePorts;
121 } else if (sortColumn == 4) {
122 return lid2->bidirPorts - lid1->bidirPorts;
123 } else if (sortColumn == 5) {
124 return lid2->maxReads - lid1->maxReads;
125 } else if (sortColumn == 6) {
126 return lid2->maxWrites - lid1->maxWrites;
127 } else if (sortColumn == 7) {
128 return lid2->hdbId - lid1->hdbId;
129 } else if (sortColumn == 8) {
130 return lid2->path.Cmp(lid1->path);
131 }
132
133 return 0;
134}
135
136/**
137 * The Constructor.
138 *
139 * @param parent Parent window of the dialog.
140 * @param machine Parent Machine of the immediate slots.
141 */
143 wxWindow* parent,
144 Model* model) :
145 wxDialog(
146 parent, -1, _T("HDB Register Files"), wxDefaultPosition, wxDefaultSize,
147 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
148 model_(model), sortColumn_(0), sortASC_(true) {
149
150 createContents(this, true, true);
151 SetSize(400, 300);
152
153 list_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_LIST));
154
155 list_->InsertColumn(0, _T("Width"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
156 list_->InsertColumn(1, _T("Size"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
157 list_->InsertColumn(2, _T("Read ports"), wxLIST_FORMAT_LEFT, 100);
158 list_->InsertColumn(3, _T("Write ports"), wxLIST_FORMAT_LEFT, 100);
159 list_->InsertColumn(4, _T("Bidir ports"), wxLIST_FORMAT_LEFT, 100);
160 list_->InsertColumn(5, _T("Max Reads"), wxLIST_FORMAT_LEFT, 100);
161 list_->InsertColumn(6, _T("Max RW"), wxLIST_FORMAT_LEFT, 100);
162 list_->InsertColumn(7, _T("ID"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
163 list_->InsertColumn(8, _T("HDB"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
164
165 string iconPath =
167
168 wxImageList* imageList = new wxImageList(13, 17);
169 imageList->Add(wxIcon(
171 imageList->Add(wxIcon(
173 list_->SetImageList(imageList, wxIMAGE_LIST_SMALL);
174
175 // Disable conditional buttons.
176 FindWindow(ID_ADD)->Disable();
177}
178
179
180/**
181 * The Destructor.
182 */
185
186
187/**
188 * Transfers data from the HDBs to the dialog list.
189 *
190 * @return True, if the data transfer was ssuccesful.
191 */
192bool
194
196 list_->DeleteAllItems();
197
199 registry.loadFromSearchPaths();
200
201 for (int i = 0; i < registry.hdbCount(); i++) {
202 loadHDB(registry.hdb(i));
203 }
204
205 wxString errorMessage;
206 for (int i = 0; i < registry.hdbErrorCount(); i++) {
207 errorMessage.Append(
209 errorMessage.Append(_T("\n"));
210 WarningDialog dialog(this, errorMessage);
211 dialog.ShowModal();
212 }
213
214 if (registry.hdbCount() < 1) {
215 wxString message = _T("No HDBs found in HDB search paths.");
216 WarningDialog dialog(this, message);
217 dialog.ShowModal();
218 }
219
220 list_->SetColumnWidth(8, wxLIST_AUTOSIZE);
221 return wxDialog::TransferDataToWindow();
222}
223
224/**
225 * Loads register files from a HDB to the dialog list.
226 *
227 * @param manager HDBManager managing the HDB to load.
228 * @return True, if the HDB was succesfully loaded.
229 */
230bool
232
233 std::string path = manager.fileName();
234
235 const std::set<RowID> rfArchIDs = manager.rfArchitectureIDs();
236 std::set<RowID>::iterator iter = rfArchIDs.begin();
237
238 // Read properties of all register files in the HDB and append
239 // data to the register file list widget.
240 for (; iter != rfArchIDs.end(); iter++) {
241
242 RFArchitecture* arch = manager.rfArchitectureByID(*iter);
243
244 if (arch->latency() != 1) {
245 continue;
246 }
247
248 rfArchitectures_.insert(
249 std::pair<int, RFArchitecture*>(list_->GetItemCount(), arch));
250
251 ListItemData* lid = new ListItemData;
252
253 if (arch->hasParameterizedWidth()) {
254 list_->InsertItem(0, _T("param"));
255 lid->width = 0;
256 } else {
257 list_->InsertItem(0, WxConversion::toWxString(arch->width()));
258 lid->width = arch->width();
259 }
260 if (arch->hasParameterizedSize()) {
261 list_->SetItem(0, 1, _T("param"));
262 lid->size = 0;
263 } else {
264 list_->SetItem(0, 1, WxConversion::toWxString(arch->size()));
265 lid->size = arch->size();
266 }
267 list_->SetItem(0, 2, WxConversion::toWxString(arch->readPortCount()));
268 lid->readPorts = arch->readPortCount();
269 list_->SetItem(
271 lid->writePorts = arch->writePortCount();
272 list_->SetItem(0, 4, WxConversion::toWxString(arch->bidirPortCount()));
273 lid->bidirPorts = arch->bidirPortCount();
274 list_->SetItem(0, 5, WxConversion::toWxString(arch->maxReads()));
275 lid->maxReads = arch->maxReads();
276 list_->SetItem(0, 6, WxConversion::toWxString(arch->maxWrites()));
277 lid->maxWrites = arch->maxWrites();
278 list_->SetItem(0, 7, WxConversion::toWxString(*iter));
279 lid->hdbId = *iter;
280 list_->SetItem(0, 8, WxConversion::toWxString(path));
281 lid->path = WxConversion::toWxString(path);
282 lid->id = list_->GetItemCount() - 1;
283 list_->SetItemData(0, (long)lid);
284 }
285 // default sorting column is "Width"
286 list_->SortItems(RFListCompareASC, 0);
288
289 return true;
290}
291
292/**
293 * Enables and disables the delete button according to slot list selection.
294 */
295void
297 if (list_->GetSelectedItemCount() == 1) {
298 FindWindow(ID_ADD)->Enable();
299 } else {
300 FindWindow(ID_ADD)->Disable();
301 }
302}
303
304
305/**
306 * Adds a new register file to the machine when "Add" button is pressed.
307 */
308void
310
311 long item = -1;
312 item = list_->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
313 if ( item == -1 ) return;
314
315 ListItemData* lid = (ListItemData*)list_->GetItemData(item);
316 int id = lid->id;
317 const RFArchitecture* arch =
319
321
322 int size = DEFAULT_SIZE;
323 int width = DEFAULT_WIDTH;
324
325 if (!arch->hasParameterizedWidth()) {
326 size = arch->width();
327 }
328
329 if (!arch->hasParameterizedSize()) {
330 size = arch->size();
331 }
332
333 // Generate name for the new register file.
334 string name =
335 "RF_" + Conversion::toString(size) + "x" + Conversion::toString(width);
336
337 string rfName = name;
338 int idx = 1;
339 while (machine->registerFileNavigator().hasItem(rfName)) {
340 rfName = name + "_" + Conversion::toString(idx);
341 idx++;
342 }
343
344 RegisterFile* rf = new RegisterFile(
345 rfName, size, width, arch->maxReads(), arch->maxWrites(),
347
348 for (int i = 0; i < arch->readPortCount(); i++) {
349 string name = "r" + Conversion::toString(i);
350 new RFPort(name, *rf);
351 }
352
353 for (int i = 0; i < arch->writePortCount(); i++) {
354 string name = "w" + Conversion::toString(i);
355 new RFPort(name, *rf);
356 }
357
358 for (int i = 0; i < arch->bidirPortCount(); i++) {
359 string name = "rw" + Conversion::toString(i);
360 new RFPort(name, *rf);
361 }
362
366
367}
368
369/**
370 * Closes the dialog when the close button is pressed.
371 */
372void
374 Close();
375}
376
377
378/**
379 * Creates the dialog contents.
380 *
381 * @param parent Parent dialog of the contents.
382 * @param call_fit If true, fits the contents inside the dialog.
383 * @param set_sizer If true, sets the main sizer as dialog contents.
384 * @return Top level sizer of the dialog contents.
385 */
386wxSizer*
388 wxWindow *parent, bool call_fit, bool set_sizer) {
389
390 wxFlexGridSizer *item0 = new wxFlexGridSizer( 1, 0, 0 );
391 item0->AddGrowableCol( 0 );
392 item0->AddGrowableRow( 0 );
393
394 wxListCtrl *item1 = new wxListCtrl( parent, ID_LIST, wxDefaultPosition, wxSize(160,120), wxLC_REPORT|wxSUNKEN_BORDER );
395 item0->Add( item1, 0, wxGROW|wxALL, 5 );
396
397 wxButton *item2 = new wxButton( parent, ID_ADD, wxT("&Add"), wxDefaultPosition, wxDefaultSize, 0 );
398 item0->Add( item2, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
399
400 wxStaticLine *item3 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
401 item0->Add( item3, 0, wxGROW|wxALL, 5 );
402
403 wxButton *item4 = new wxButton( parent, ID_CLOSE, wxT("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
404 item0->Add( item4, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
405
406 if (set_sizer) {
407 parent->SetSizer( item0 );
408 if (call_fit) {
409 item0->SetSizeHints( parent );
410 }
411 }
412
413 return item0;
414}
415
416
417/**
418 * Sorts HDB RF list according to clicked column.
419 */
420void
422
423 int clickedColumn = event.GetColumn();
424
425 if (clickedColumn == sortColumn_) {
427 } else {
428 sortASC_ = true;
429 setColumnImage(sortColumn_, -1); // removes arrow from old column
430 sortColumn_ = clickedColumn;
431 }
432
433 setColumnImage(clickedColumn, sortASC_);
434
435 if (sortASC_) {
436 list_->SortItems(RFListCompareASC, clickedColumn);
437 } else {
438 list_->SortItems(RFListCompareDESC, clickedColumn);
439 }
440}
441
442
443/**
444 * Sets sorting arrow image on selected column
445 *
446 * @param col Column index to set the image
447 * @param image Image index in wxImageList
448 */
449void
451 wxListItem item;
452 item.SetMask(wxLIST_MASK_IMAGE);
453 item.SetImage(image);
454 list_->SetColumn(col, item);
455}
long int wxIntPtr
int wxCALLBACK RFListCompareDESC(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)
long int wxIntPtr
int wxCALLBACK RFListCompareASC(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine * machine
the architecture 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
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
const int DEFAULT_WIDTH
Default window width.
#define DEFAULT_SIZE
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
bool loadHDB(const HDB::HDBManager &manager)
AddRFFromHDBDialog(wxWindow *parent, Model *model)
void onColumnClick(wxListEvent &event)
void onAdd(wxCommandEvent &event)
static const int DEFAULT_SIZE
Default size for the rf, if the size is parameterized in the HDB.
static const int DEFAULT_WIDTH
Default bit width for the rf, if the size is parameterized in the HDB.
void onClose(wxCommandEvent &event)
wxListCtrl * list_
Immediate slot list widget.
void setColumnImage(int col, int image)
std::map< int, HDB::RFArchitecture * > rfArchitectures_
Map of rf architectures displayed in the dialog list.
Model * model_
Model of the current adf file.
virtual bool TransferDataToWindow()
void onListSelectionChange(wxListEvent &event)
static std::string toString(const T &source)
static std::string iconDirPath()
static const std::string DIRECTORY_SEPARATOR
std::set< RowID > rfArchitectureIDs() const
std::string fileName() const
virtual RFArchitecture * rfArchitectureByID(RowID id) const
static HDBRegistry & instance()
CachedHDBManager & hdb(const std::string fileName)
void loadFromSearchPaths()
std::string hdbErrorMessage(unsigned int index)
bool hasParameterizedWidth() const
bool zeroRegister() const
bool hasParameterizedSize() const
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)
static void deleteAllValues(MapType &aMap)
Definition Model.hh:50
void pushToStack()
Definition Model.cc:167
void notifyObservers(bool modified=true)
Definition Model.cc:152
TTAMachine::Machine * getMachine()
Definition Model.cc:88
static const std::string ICON_SORT_DESC
Icon location for descending sort.
static const std::string ICON_SORT_ASC
Icon location for ascending sort.
bool hasItem(const std::string &name) const
virtual RegisterFileNavigator registerFileNavigator() const
Definition Machine.cc:450
virtual void addRegisterFile(RegisterFile &unit)
Definition Machine.cc:236
@ NORMAL
Used for general register allocation.
static wxString toWxString(const std::string &source)