OpenASIP 2.2
Loading...
Searching...
No Matches
GenerateProcessorDialog.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2011 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 GenerateProcessorDialog.cc
26 *
27 * Implementation of GenerateProcessorDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30 * @author Otto Esko 2008 (otto.esko-no.spam-tut.fi)
31 * @author Pekka Jääskeläinen 2011
32 * @author Vinogradov Viacheslav(added Verilog generating) 2012
33 * @note rating: red
34 */
35
36#include <string>
37#include <vector>
38#include <sstream>
39
40#include <wx/wx.h>
41#include <wx/dirdlg.h>
42#include <wx/statline.h>
43#include <wx/filedlg.h>
44
46#include "WxConversion.hh"
47#include "BinaryEncoding.hh"
48#include "BEMSerializer.hh"
49#include "BEMGenerator.hh"
50#include "ErrorDialog.hh"
51#include "WarningDialog.hh"
52#include "BEMValidator.hh"
53#include "FileSystem.hh"
56#include "ProGeUI.hh"
57#include "PluginTools.hh"
58#include "InformationDialog.hh"
61
62#if wxCHECK_VERSION(3, 0, 0)
63 #define wxSAVE wxFD_SAVE
64 #define wxOVERWRITE_PROMPT wxFD_OVERWRITE_PROMPT
65 #define wxOPEN wxFD_OPEN
66 #define wxFILE_MUST_EXIST wxFD_FILE_MUST_EXIST
67#endif
68
69using std::vector;
70using std::string;
71
72BEGIN_EVENT_TABLE(GenerateProcessorDialog, wxDialog)
78
79
80/**
81 * The Constructor.
82 *
83 * @param paren Parent window of the dialog.
84 * @param machine Processor architecture.
85 * @param imp Processor implementation definition.
86 */
88 wxWindow* parent,
89 TTAMachine::Machine& machine,
90 const IDF::MachineImplementation& impl) :
91 wxDialog(parent, -1, _T("Generate Processor"), wxDefaultPosition),
92 machine_(machine), impl_(impl), bem_(NULL) {
93
94 createContents(this, true, true);
95}
96
97
98/**
99 * The Destructor.
100 */
102 if (bem_ != NULL) {
103 delete bem_;
104 }
105}
106
107/**
108 * Event handler for the OK button.
109 */
110void
112
113 std::ostringstream errorStream;
114 std::ostringstream warningStream;
115
116 // Binary encoding map.
117 if (dynamic_cast<wxRadioButton*>(
118 FindWindow(ID_GENERATE_BEM))->GetValue()) {
119
120 // Generate new bem.
121 if (bem_ != NULL) {
122 delete bem_;
123 bem_ = NULL;
124 }
125 BEMGenerator generator(machine_);
126 bem_ = generator.generate();
127
128 if (dynamic_cast<wxCheckBox*>(FindWindow(ID_SAVE_BEM))->IsChecked()) {
129 wxTextCtrl* ctrl =
130 dynamic_cast<wxTextCtrl*>(FindWindow(ID_BEM_SAVE_PATH));
131 string bemPath = WxConversion::toString(ctrl->GetValue());
132 if (bemPath != "") {
133 BEMSerializer serializer;
134 serializer.setDestinationFile(bemPath);
135 try {
136 serializer.writeBinaryEncoding(*bem_);
137 } catch (Exception& e) {
138 wxString message = _T("Error saving BEM:");
139 message.Append(WxConversion::toWxString(e.errorMessage()));
140 ErrorDialog dialog(this, message);
141 dialog.ShowModal();
142 return;
143 }
144 } else {
145 wxString message = _T("BEM target file not defined.");
146 ErrorDialog dialog(this, message);
147 dialog.ShowModal();
148 return;
149 }
150 }
151
152 } else {
153 if (bem_ == NULL) {
154 wxString message = _T("Error: No binary encoding map loaded.");
155 ErrorDialog dialog(this, message);
156 dialog.ShowModal();
157 return;
158 }
159 }
160
161 // Target directory.
162 wxTextCtrl* ctrl = dynamic_cast<wxTextCtrl*>(FindWindow(ID_TARGET));
163 string targetDir = WxConversion::toString(ctrl->GetValue());
164 if (!FileSystem::fileExists(targetDir) ||
165 !FileSystem::fileIsDirectory(targetDir)) {
166
167 wxString message = _T("Target directory '");
168 message.Append(WxConversion::toWxString(targetDir));
169 message.Append(_T("' does not exist."));
170 ErrorDialog dialog(this, message);
171 dialog.ShowModal();
172 return;
173 }
174
176 options.outputDirectory = targetDir;
177 options.sharedOutputDirectory = targetDir;
178 options.generateTestbench = true;
179 options.validate();
180 // validate() would override this based on the given string option
181 wxRadioButton *VHDLItem = (wxRadioButton *) FindWindow(ID_VHDL);
182 options.language = (VHDLItem->GetValue()) ? ProGe::VHDL : ProGe::Verilog;
183
184 ProGe::ProGeUI progeUI;
185 try {
186 std::ostringstream verboseStream;
187
188
189 progeUI.loadMachine(machine_);
190 progeUI.loadBinaryEncoding(*bem_);
192 progeUI.generateProcessor(options, 1,
193 errorStream, warningStream, verboseStream);
194 } catch (Exception& e) {
195 wxString message = WxConversion::toWxString(e.errorMessage());
196 ErrorDialog dialog(this, message);
197 dialog.ShowModal();
198 return;
199 }
200
201 string testBenchDir = targetDir + FileSystem::DIRECTORY_SEPARATOR + "tb";
202 try {
203 progeUI.generateTestBench(options.language, testBenchDir, targetDir);
204 } catch (const Exception& e) {
205 std::cerr << e.errorMessage() << std::endl;
206 wxString message = WxConversion::toWxString(e.errorMessage());
207 ErrorDialog dialog(this, message);
208 dialog.ShowModal();
209 }
210
211 try {
212 progeUI.generateScripts(options.language, targetDir, targetDir,
213 targetDir, testBenchDir, "52390");
214 } catch (const Exception& e) {
215 std::cerr << "Warning: Processor Generator failed to "
216 << "generate simulation/compilation scripts."
217 << std::endl;
218 std::cerr << e.errorMessage() << std::endl;
219 }
220
221 string warningMessages = warningStream.str();
222 if (warningMessages != "") {
223 WarningDialog dialog(this, WxConversion::toWxString(warningMessages));
224 dialog.ShowModal();
225 }
226
227 string errorMessages = errorStream.str();
228 if (errorMessages != "") {
229 ErrorDialog dialog(this, WxConversion::toWxString(errorMessages));
230 dialog.ShowModal();
231 return;
232 }
233
234 wxString message = _T("Processor was succesfully generated.");
235 InformationDialog dialog(this, message);
236 dialog.ShowModal();
237
238 EndModal(wxID_OK);
239}
240
241/**
242 * Event handler for the bem saving Browse... button.
243 */
244void
246
247 wxString fileTypes = _T("Binary Encoding Map (.bem)|*.bem|");
248 wxFileDialog dialog(
249 this, _T("Choose a file"), _T("."), _T(""), fileTypes,
250 wxSAVE | wxOVERWRITE_PROMPT);
251
252 if (dialog.ShowModal() == wxID_OK) {
253 wxTextCtrl* ctrl = dynamic_cast<wxTextCtrl*>(
255 ctrl->SetValue(dialog.GetPath());
256 }
257}
258
259
260/**
261 * Event handler for the ben loading Browse... button.
262 */
263void
265
266 wxTextCtrl* ctrl = dynamic_cast<wxTextCtrl*>(FindWindow(ID_BEM_LOAD_PATH));
267
268 wxFileDialog dialog(
269 this, _T("Choose a file"), _T(""), _T(""),
270 _T("Binary Encoding Maps (*.bem)|*.bem|All files|*"),
271 (wxOPEN | wxFILE_MUST_EXIST));
272
273 if (dialog.ShowModal() == wxID_OK) {
274 if (bem_ != NULL) {
275 delete bem_;
276 bem_ = NULL;
277 ctrl->SetValue(_T(""));
278 }
279 string path = WxConversion::toString(dialog.GetPath());
280 try {
281 BEMSerializer serializer;
282 serializer.setSourceFile(path);
283 bem_ = serializer.readBinaryEncoding();
284 } catch (Exception& e) {
285 wxString message = _T("Error loading binary encoding map:\n");
286 message.Append(WxConversion::toWxString(e.errorMessage()));
287 ErrorDialog dialog(this, message);
288 dialog.ShowModal();
289 return;
290 }
291 ctrl->SetValue(dialog.GetPath());
292 }
293}
294
295
296/**
297 * Event handler for the target directory Browse... button.
298 */
299void
301
302 wxDirDialog dialog(
303 this, _T("Choose a directory"), _T(""), wxDD_NEW_DIR_BUTTON);
304
305 if (dialog.ShowModal() == wxID_OK) {
306 wxTextCtrl* ctrl = dynamic_cast<wxTextCtrl*>(FindWindow(ID_TARGET));
307 ctrl->SetValue(dialog.GetPath());
308 }
309}
310
311/**
312 * Loads the given IC/decoder generator plugin.
313 *
314 * @param pluginFile The file that implements the plugin.
315 * @param pluginName Name of the plugin.
316 */
319 const string& pluginFile,
320 const string& pluginName) {
321
322 PluginTools pluginTool;
323
324 // initialize the plugin tool
325 vector<string> pluginPaths = Environment::icDecoderPluginPaths();
326 for (vector<string>::const_iterator iter = pluginPaths.begin();
327 iter != pluginPaths.end(); iter++) {
328 try {
329 pluginTool.addSearchPath(*iter);
330 } catch (const FileNotFound&) {
331 }
332 }
333
334 try {
335 pluginTool.registerModule(pluginFile);
336 } catch (Exception& e) {
337 wxString message = _T("Error loading IC/Decoder generator plugin:\n");
338 message.Append(WxConversion::toWxString(e.errorMessage()));
339 ErrorDialog dialog(this, message);
340 dialog.ShowModal();
341 return NULL;
342 }
343
346
347 pluginTool.importSymbol(
348 "create_generator_plugin_" + pluginName, creator, pluginFile);
349
350 ProGe::ICDecoderGeneratorPlugin* plugin = creator(machine_, *bem_);
351 return plugin;
352}
353
354/**
355 * Craetes the dialog contents.
356 */
357wxSizer*
359 wxWindow *parent, bool call_fit, bool set_sizer) {
360
361 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
362
363 wxBoxSizer *item1 = new wxBoxSizer( wxVERTICAL );
364
365 //HDL type radio buttons
366 wxStaticBox *hdl_box = new wxStaticBox( parent, -1, wxT("HDL type selection:") );
367 wxStaticBoxSizer *hdl_boxsizer = new wxStaticBoxSizer( hdl_box, wxVERTICAL );
368
369 wxRadioButton *vhdl_item = new wxRadioButton( parent, ID_VHDL, wxT("VHDL"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
370 vhdl_item->SetValue( TRUE );
371
372 wxRadioButton *verilog_item = new wxRadioButton( parent, ID_VERILOG, wxT("Verilog"), wxDefaultPosition, wxDefaultSize, 0 );
373
374 hdl_boxsizer->Add( vhdl_item, 0, wxALL, 5 );
375 hdl_boxsizer->Add( verilog_item, 0, wxALL, 5 );
376 item1->Add( hdl_boxsizer, 0, wxGROW|wxALL, 5 );
377 //
378
379 wxStaticBox *item3 = new wxStaticBox( parent, -1, wxT("Binary Encoding Map:") );
380 wxStaticBoxSizer *item2 = new wxStaticBoxSizer( item3, wxVERTICAL );
381
382 wxRadioButton *item4 = new wxRadioButton( parent, ID_GENERATE_BEM, wxT("Generate new"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
383 item4->SetValue( TRUE );
384 item2->Add( item4, 0, wxALL, 5 );
385
386 wxBoxSizer *item5 = new wxBoxSizer( wxVERTICAL );
387
388 wxBoxSizer *item6 = new wxBoxSizer( wxHORIZONTAL );
389
390 wxCheckBox *item7 = new wxCheckBox( parent, ID_SAVE_BEM, wxT("Save to file:"), wxDefaultPosition, wxDefaultSize, 0 );
391 item6->Add( item7, 0, wxLEFT, 5 );
392
393 item5->Add( item6, 0, wxALL, 5 );
394
395 wxBoxSizer *item8 = new wxBoxSizer( wxHORIZONTAL );
396
397 wxTextCtrl *item9 = new wxTextCtrl( parent, ID_BEM_SAVE_PATH, wxT(""), wxDefaultPosition, wxSize(300,-1), 0 );
398 item8->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
399
400 wxButton *item10 = new wxButton( parent, ID_BROWSE_BEM_SAVE, wxT("Browse..."), wxDefaultPosition, wxDefaultSize, 0 );
401 item8->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
402
403 item5->Add( item8, 0, wxALL, 5 );
404
405 item2->Add( item5, 0, wxGROW|wxALL, 5 );
406
407 wxRadioButton *item11 = new wxRadioButton( parent, ID_LOAD_BEM, wxT("Load from file"), wxDefaultPosition, wxDefaultSize, 0 );
408 item2->Add( item11, 0, wxALL, 5 );
409
410 wxBoxSizer *item12 = new wxBoxSizer( wxHORIZONTAL );
411
412 wxTextCtrl *item13 = new wxTextCtrl( parent, ID_BEM_LOAD_PATH, wxT(""), wxDefaultPosition, wxSize(300,-1), 0 );
413 item12->Add( item13, 0, wxALIGN_CENTER|wxALL, 5 );
414
415 wxButton *item14 = new wxButton( parent, ID_BROWSE_BEM_LOAD, wxT("Browse..."), wxDefaultPosition, wxDefaultSize, 0 );
416 item12->Add( item14, 0, wxALIGN_CENTER|wxALL, 5 );
417
418 item2->Add( item12, 0, wxALL, 5 );
419
420 item1->Add( item2, 0, wxGROW|wxALL, 5 );
421
422 item1->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
423
424 wxStaticBox *item16 = new wxStaticBox( parent, -1, wxT("Target directory:") );
425 wxStaticBoxSizer *item15 = new wxStaticBoxSizer( item16, wxVERTICAL );
426
427 wxBoxSizer *item17 = new wxBoxSizer( wxHORIZONTAL );
428
429 wxTextCtrl *item18 = new wxTextCtrl( parent, ID_TARGET, wxT(""), wxDefaultPosition, wxSize(300,-1), 0 );
430 item17->Add( item18, 0, wxALIGN_CENTER|wxALL, 5 );
431
432 wxButton *item19 = new wxButton( parent, ID_BROWSE_TARGET, wxT("Browse..."), wxDefaultPosition, wxDefaultSize, 0 );
433 item17->Add( item19, 0, wxALIGN_CENTER|wxALL, 5 );
434
435 item15->Add( item17, 0, wxALL, 5 );
436
437 item1->Add( item15, 0, wxGROW|wxALL, 5 );
438
439 wxStaticLine *item20 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
440 item1->Add( item20, 0, wxGROW|wxALL, 5 );
441
442 wxBoxSizer *item21 = new wxBoxSizer( wxHORIZONTAL );
443
444 wxButton *item22 = new wxButton( parent, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
445 item21->Add( item22, 0, wxALIGN_CENTER|wxALL, 5 );
446
447 wxButton *item23 = new wxButton( parent, wxID_OK, wxT("OK"), wxDefaultPosition, wxDefaultSize, 0 );
448 item21->Add( item23, 0, wxALIGN_CENTER|wxALL, 5 );
449
450 item1->Add( item21, 0, wxALL, 5 );
451
452 item0->Add( item1, 0, wxGROW|wxALL, 5 );
453
454 if (set_sizer)
455 {
456 parent->SetSizer( item0 );
457 if (call_fit)
458 item0->SetSizeHints( parent );
459 }
460
461 return item0;
462}
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine * machine
the architecture definition of the estimated processor
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
const string TRUE
Value used for true in attribute and element values.
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
BinaryEncoding * generate()
BinaryEncoding * readBinaryEncoding()
void writeBinaryEncoding(const BinaryEncoding &bem)
static std::vector< std::string > icDecoderPluginPaths(bool libraryPathsOnly=false)
std::string errorMessage() const
Definition Exception.cc:123
static const std::string DIRECTORY_SEPARATOR
static bool fileIsDirectory(const std::string fileName)
static bool fileExists(const std::string fileName)
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
BinaryEncoding * bem_
Binary Encosing Map.
const IDF::MachineImplementation & impl_
Processor implementation definition.
TTAMachine::Machine & machine_
Processor architecture.
void onBrowseBEMSave(wxCommandEvent &event)
void onBrowseBEMLoad(wxCommandEvent &event)
ProGe::ICDecoderGeneratorPlugin * loadICDecoderGeneratorPlugin(const std::string &pluginFile, const std::string &pluginName)
void onBrowseTargetDir(wxCommandEvent &event)
void onOK(wxCommandEvent &event)
void importSymbol(const std::string &symbolName, T *&target, const std::string &module)
void addSearchPath(const std::string &searchPath)
void registerModule(const std::string &module)
void loadBinaryEncoding(const BinaryEncoding &bem)
Definition ProGeUI.cc:170
void generateScripts(const ProGe::HDL language, const std::string &dstDir, const std::string &progeOutDir, const std::string &sharedOutDir, const std::string &testBenchDir, const std::string &simulationRuntime)
Definition ProGeUI.cc:416
void loadMachineImplementation(const IDF::MachineImplementation &idf)
Definition ProGeUI.cc:175
void generateProcessor(const ProGeOptions &options, int imemWidthInMAUs, std::ostream &errorStream, std::ostream &warningStream, std::ostream &verboseStream)
Definition ProGeUI.cc:298
void generateTestBench(const ProGe::HDL language, const std::string &dstDir, const std::string &progeOutDir)
Definition ProGeUI.cc:375
void loadMachine(const TTAMachine::Machine &adf)
Definition ProGeUI.cc:165
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)
void setSourceFile(const std::string &fileName)
void setDestinationFile(const std::string &fileName)
@ Verilog
Verilog.
Definition ProGeTypes.hh:42
@ VHDL
VHDL.
Definition ProGeTypes.hh:41