OpenASIP 2.2
Loading...
Searching...
No Matches
OTAOperationDialog.cc
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 Tampere University.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18/**
19 * @file OTAOperationDialog.cc
20 *
21 * Implementation of OTAOperationDialog class.
22 *
23 * @author Kari Hepola 2022
24 * @note rating: red
25 */
26
27#include <wx/wx.h>
28#include <wx/spinctrl.h>
29#include <wx/statline.h>
30#include <wx/valgen.h>
31#include <boost/format.hpp>
32
33#include "OTAOperationDialog.hh"
34#include "Machine.hh"
36#include "WxConversion.hh"
37#include "AssocTools.hh"
38#include "WidgetTools.hh"
39#include "InformationDialog.hh"
40#include "ModelConstants.hh"
41#include "WidgetTools.hh"
42#include "GUITextGenerator.hh"
43#include "ProDeTextGenerator.hh"
44#include "Application.hh"
45#include "FunctionUnit.hh"
46#include "HWOperation.hh"
47#include "ErrorDialog.hh"
48#include "OperationPool.hh"
49#include "Operation.hh"
50#include "RISCVFields.hh"
51#include "MapTools.hh"
52
53using boost::format;
54using std::string;
55using namespace TTAMachine;
56
57BEGIN_EVENT_TABLE(OTAOperationDialog, wxDialog)
58 EVT_LISTBOX(ID_LIST, OTAOperationDialog::onSelectOperation)
62
63/**
64 * The Constructor.
65 *
66 * @param parent Parent window of the dialog.
67 * @param format OperationTriggeredFormat format to edit.
68 * @param operation Operation to edit, NULL if a new operation is being added.
69 */
71 wxWindow* parent,
73 wxDialog(parent, -1, _T("Choose operation"), wxDefaultPosition),
74 operation_(""),
75 format_(format) {
76
77 createContents(this, true, true);
78 operationList_ = dynamic_cast<wxListBox*>(FindWindow(ID_LIST));
79 FindWindow(wxID_OK)->Disable();
80}
81
82
83/**
84 * The Destructor.
85 */
88
89int
110
111int
123
124bool
139
140std::set<TCEString>
141OTAOperationDialog::addRISCVBaseOperations(std::set<TCEString> opset) const {
142 std::map<std::string, int> ops;
155 }
156 for (const auto& op : ops) {
157 const std::string opName = op.first;
158 if (!opNameFilter_.empty() &&
159 opName.find(opNameFilter_) == std::string::npos) {
160 continue;
161 } else if (format_->hasOperation(opName)) {
162 continue;
163 } else if (op.first == "lui") {
164 opset.insert(opName);
165 continue;
166 }
167 const std::string OAName = RISCVFields::RISCVOperationNameTable.at(opName);
168 if (format_->machine()->hasOperation(OAName)) {
169 opset.insert(opName);
170 }
171 }
172 return opset;
173}
174
175
176/**
177 * Transfers data to the opset list.
178 */
179bool
181
182 operationList_->Clear();
183
184 std::set<TCEString> opset;
191 for (int i = 0; i < nav.count(); i++) {
192 FunctionUnit* fu = nav.item(i);
193 for (int j = 0; j < fu->operationCount(); j++) {
194 HWOperation* op = fu->operation(j);
195 TCEString opName =op->name();
196 opName = opName.lower();
197 if (!opNameFilter_.empty() &&
198 opName.find(opNameFilter_) == std::string::npos) {
199 continue;
200 } else if (format_->hasOperation(opName)) {
201 continue;
202 } else if (op->numberOfInputs() != numberOfInputs()) {
203 continue;
204 } else if (op->numberOfOutputs() != numberOfOutputs()) {
205 continue;
206 } else if (MapTools::containsValue(
208 continue;
209 }
210 opset.insert(opName);
211 }
212 }
213 }
214
215 opset = addRISCVBaseOperations(opset);
216
217
218 for (const auto& opName : opset) {
220 }
221
222 return true;
223}
224
225/**
226 * Reads user choices from the dialog widgets.
227 */
228bool
233
234/**
235 * Event handler for the OK button.
236 */
237void
238OTAOperationDialog::onOK(wxCommandEvent&) {
239 if (operationList_->GetSelection() == wxNOT_FOUND) {
240 wxString message = _T("No operation selected.");
241 ErrorDialog dialog(this, message);
242 dialog.ShowModal();
243 return;
244 }
247 }
249 EndModal(wxID_OK);
250}
251
252/**
253 * Event handler for the operation list selections.
254 *
255 * Enables and disables the OK button.
256 * Displays operation description and ports count.
257 */
258void
260 FindWindow(wxID_OK)->Enable(operationList_->GetSelection() != wxNOT_FOUND);
261
262 operation_ = WxConversion::toString(operationList_->GetStringSelection());
263}
264
265
266/**
267 * Event handler for opset filtering.
268 */
269void
271 std::string pattern(event.GetString().mb_str());
272 std::string::iterator it;
273 it = std::remove_if(pattern.begin(), pattern.end(), [](const char& c) {
274 return c == ' ';
275 });
276 pattern.erase(it, pattern.end());
277 for (auto& c : pattern) c = toupper(c);
278 opNameFilter_ = pattern;
281}
282
283/**
284 * Creates the dialog widgets.
285 *
286 * @param parent Parent window of the widgets.
287 */
288wxSizer*
289OTAOperationDialog::createContents(wxWindow *parent, bool call_fit, bool set_sizer) {
290
291 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
292 // Sizer for leftSizer and rightSizer
293 wxBoxSizer *upperSizer = new wxBoxSizer(wxHORIZONTAL);
294
295 // Sizer for oplistbox, filterlabel and filterinput
296 wxBoxSizer *leftSizer = new wxBoxSizer(wxVERTICAL);
297 // List of operations
298 wxListBox *opListBox = new wxListBox(parent, ID_LIST, wxDefaultPosition,
299 wxSize(210, 150), 0, NULL, wxLB_SINGLE|wxLB_SORT);
300 leftSizer->Add(opListBox, 0, wxEXPAND|wxALL, 5);
301
302 // Sizer for opNameFilterLabel and opNameFilter
303 wxBoxSizer *filterSizer = new wxBoxSizer(wxHORIZONTAL);
304 // TextLabel "Filter:"
305 wxStaticText *opNameFilterLabel = new wxStaticText(parent,
306 ID_OP_FILTER_LABEL, wxT("Filter:"), wxDefaultPosition, wxDefaultSize,
307 0);
308 // Operation filter input
309 wxTextCtrl *opNameFilter = new wxTextCtrl(parent, ID_OP_FILTER, wxT(""),
310 wxDefaultPosition, wxDefaultSize, 0);
311 filterSizer->Add(opNameFilterLabel, 0, 0);
312 filterSizer->Add(opNameFilter, 1, wxEXPAND);
313 leftSizer->Add(filterSizer, 0, wxEXPAND|wxALL, 5);
314
315 upperSizer->Add(leftSizer, 0, wxALL, 5);
316
317 mainSizer->Add(upperSizer, 1, wxEXPAND);
318
319 // Static line
320 wxStaticLine *horisontalLine = new wxStaticLine(parent, ID_LINE,
321 wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL);
322 mainSizer->Add(horisontalLine, 0, wxEXPAND|wxALL, 5);
323
324 // Sizer for Cancel and OK buttons
325 wxBoxSizer *buttonsSizer = new wxBoxSizer(wxHORIZONTAL);
326 // Cancel button
327 wxButton *cancelButton = new wxButton(parent, wxID_CANCEL, wxT("&Cancel"),
328 wxDefaultPosition, wxDefaultSize, 0);
329 buttonsSizer->Add(cancelButton, 0, wxALIGN_CENTER|wxALL, 5);
330 // OK button
331 wxButton *okButton = new wxButton(parent, wxID_OK, wxT("&OK"),
332 wxDefaultPosition, wxDefaultSize, 0);
333 buttonsSizer->Add(okButton, 0, wxALIGN_CENTER|wxALL, 5);
334
335 mainSizer->Add(buttonsSizer, 0, 0, 5);
336
337 if (set_sizer) {
338 parent->SetSizer(mainSizer);
339 if (call_fit) {
340 mainSizer->SetSizeHints( parent );
341 }
342 }
343
344 return mainSizer;
345}
END_EVENT_TABLE() using namespace IDF
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
static bool containsValue(const MapType &aMap, const ValueType &aValue)
std::set< TCEString > addRISCVBaseOperations(std::set< TCEString > opset) const
void onOK(wxCommandEvent &event)
void onOperationFilterChange(wxCommandEvent &event)
virtual bool TransferDataFromWindow()
TCEString operation_
Name of the selected operation.
virtual bool TransferDataToWindow()
TTAMachine::OperationTriggeredFormat * format_
wxListBox * operationList_
Operation list widget.
TCEString opNameFilter_
A string to filter opset list.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
void onSelectOperation(wxCommandEvent &event)
TCEString lower() const
Definition TCEString.cc:78
virtual Machine * machine() const
virtual TCEString name() const
virtual HWOperation * operation(const std::string &name) const
virtual int operationCount() const
const std::string & name() const
ComponentType * item(int index) const
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
bool hasOperation(const TCEString &opName) const
Definition Machine.cc:1042
bool hasOperation(const std::string &opName) const
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)
const std::string RISCV_S_TYPE_NAME
const std::string RISCV_R1R_TYPE_NAME
const std::string RISCV_R3R_TYPE_NAME
const std::map< std::string, int > RISCVSTypeOperations
const std::string RISCV_B_TYPE_NAME
const std::map< std::string, int > RISCVJTypeOperations
const std::map< std::string, int > RISCVITypeOperations
const std::string RISCV_J_TYPE_NAME
const std::map< std::string, int > RISCVUTypeOperations
const std::string RISCV_R_TYPE_NAME
const std::string RISCV_R1_TYPE_NAME
const std::string RISCV_I_TYPE_NAME
const std::string RISCV_U_TYPE_NAME
const std::map< std::string, int > RISCVRTypeOperations
Definition RISCVFields.hh:8
const std::map< std::string, int > RISCVBTypeOperations
const std::map< std::string, std::string > RISCVOperationNameTable