OpenASIP  2.0
ValidateMachineDialog.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 ValidateMachineDialog.cc
26  *
27  * Definition of ValidateMachineDialog class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 #include <wx/statline.h>
35 #include <wx/html/htmlwin.h>
36 
37 #include "ValidateMachineDialog.hh"
38 #include "WxConversion.hh"
41 
42 using std::string;
43 using namespace TTAMachine;
44 
45 BEGIN_EVENT_TABLE(ValidateMachineDialog, wxDialog)
47  EVT_CHECKBOX(ID_CHECK_ANSI_C, ValidateMachineDialog::onCheck)
48  EVT_CHECKBOX(ID_CHECK_GLOBAL_CONN_REGISTER, ValidateMachineDialog::onCheck)
51 
52 
53 /**
54  * The Constructor.
55  *
56  * @param parent Parent window of the dialog.
57  * @param machine Machine containing the address spaces.
58  */
60  wxWindow* parent,
61  const TTAMachine::Machine& machine):
62  wxDialog(parent, -1, _T("Validate Machine"), wxDefaultPosition),
63  machine_(machine) {
64 
65  createContents(this, true, true);
66 
67  checkAnsiC_ = dynamic_cast<wxCheckBox*>(FindWindow(ID_CHECK_ANSI_C));
68  checkGlobalConnReg_ = dynamic_cast<wxCheckBox*>(
69  FindWindow(ID_CHECK_GLOBAL_CONN_REGISTER));
70 
71  FindWindow(ID_VALIDATE)->Disable();
72 
73  // Global connection register check in ProgrammabilityValidator
74  // doesn't work for arbitrary machines yet. The global
75  // connection register checkbox is therefore disabled.
76  // Following disable-call can be removed when the
77  // ProgrammabilityValiadtor works for all machines.
78  //FindWindow(ID_CHECK_GLOBAL_CONN_REGISTER)->Disable();
79 }
80 
81 
82 /**
83  * The Destructor.
84  */
86 }
87 
88 
89 /**
90  * Event handler for the checkbox check toggles.
91  *
92  * Disables the Validate-button if no checkboxes are checked.
93  */
94 void
96  if (checkAnsiC_->IsChecked() ||
97  checkGlobalConnReg_->IsChecked()) {
98 
99  FindWindow(ID_VALIDATE)->Enable();
100  } else {
101  FindWindow(ID_VALIDATE)->Disable();
102  }
103 }
104 
105 
106 /**
107  * Event handler for the Validate-button.
108  *
109  * Validates the machine using a ProgrammabilityValidator.
110  * Only checks that are selected with the checkboxes are ran.
111  */
112 void
114 
115  bool valid = true;
116 
117  wxString resultPage = _T("<html><body><small>");
118 
119  std::set<ProgrammabilityValidator::ErrorCode> checks;
120  if (checkGlobalConnReg_->IsChecked()) {
121  checks.insert(
124  }
125  if (checkAnsiC_->IsChecked()) {
126  checks.insert(
128  OPERATION_MISSING_FROM_THE_PRIMITIVE_OPERATION_SET);
129  }
130 
131  assert(!checks.empty());
132 
133  try {
134  ProgrammabilityValidator validator(machine_);
135 
136  ProgrammabilityValidatorResults* results = validator.validate(checks);
137  for (int i = 0; i < results->errorCount(); i++) {
138  valid = false;
139  resultPage.Append(
140  WxConversion::toWxString(results->error(i).second));
141  resultPage.Append(_T("<hr>"));
142  }
143  delete results;
144  results = NULL;
145  } catch (IllegalMachine& e) {
146  valid = false;
147  resultPage.Append(WxConversion::toWxString(e.errorMessage()));
148  }
149  if (valid) {
150  resultPage.Append(
151  _T("<font color=#00c000>Validity checks passed!</font>"));
152  }
153  resultPage.Append(_T("</small></body></html>"));
154  resultsWindow_->SetPage(resultPage);
155 }
156 
157 
158 /**
159  * Event handler for the Close-button.
160  *
161  * Closes the dialog.
162  */
163 void
165  Close();
166 }
167 
168 
169 /**
170  * Creates the dialog window contents.
171  *
172  * This method was generated with wxDesigner, thus the ugly code and
173  * too long lines.
174  *
175  * @return Main sizer of the created contents.
176  * @param parent The dialog window.
177  * @param call_fit If true, fits the contents inside the dialog.
178  * @param set_sizer If true, sets the main sizer as dialog contents.
179  */
180 wxSizer*
182  wxWindow *parent, bool call_fit, bool set_sizer) {
183 
184  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
185 
186  wxBoxSizer *item1 = new wxBoxSizer( wxVERTICAL );
187 
188  wxStaticBox *item3 = new wxStaticBox( parent, -1, wxT("Validate:") );
189  wxStaticBoxSizer *item2 = new wxStaticBoxSizer( item3, wxVERTICAL );
190 
191  wxCheckBox *item4 = new wxCheckBox( parent, ID_CHECK_ANSI_C, wxT("Check for operations needed to support ANSI C."), wxDefaultPosition, wxDefaultSize, 0 );
192  item2->Add( item4, 0, wxALL, 5 );
193 
194  wxCheckBox *item5 = new wxCheckBox( parent, ID_CHECK_GLOBAL_CONN_REGISTER, wxT("Check for global connection register."), wxDefaultPosition, wxDefaultSize, 0 );
195  item2->Add( item5, 0, wxALL, 5 );
196 
197  wxButton *item6 = new wxButton( parent, ID_VALIDATE, wxT("Validate"), wxDefaultPosition, wxDefaultSize, 0 );
198  item2->Add( item6, 0, wxALIGN_RIGHT|wxALL, 5 );
199 
200  item1->Add( item2, 0, wxGROW|wxALL, 5 );
201 
202  wxStaticBox *item8 = new wxStaticBox( parent, -1, wxT("Results:") );
203  wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxVERTICAL );
204 
205  resultsWindow_ = new wxHtmlWindow(parent, ID_RESULTS, wxDefaultPosition, wxSize(250, 250));
206  wxWindow* item9 = resultsWindow_;
207  wxASSERT( item9 );
208  item7->Add( item9, 0, wxGROW|wxALL, 5 );
209 
210  item1->Add( item7, 0, wxGROW|wxALL, 5 );
211 
212  item0->Add( item1, 0, wxGROW|wxALL, 5 );
213 
214  wxStaticLine *item10 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
215  item0->Add( item10, 0, wxGROW|wxALL, 5 );
216 
217  wxButton *item11 = new wxButton( parent, ID_CLOSE, wxT("Close"), wxDefaultPosition, wxDefaultSize, 0 );
218  item0->Add( item11, 0, wxALIGN_RIGHT|wxALL, 5 );
219 
220  if (set_sizer)
221  {
222  parent->SetSizer( item0 );
223  if (call_fit)
224  item0->SetSizeHints( parent );
225  }
226 
227  return item0;
228 }
ValidateMachineDialog::onValidate
void onValidate(wxCommandEvent &event)
Definition: ValidateMachineDialog.cc:113
ProgrammabilityValidatorResults.hh
ValidateMachineDialog::onClose
void onClose(wxCommandEvent &event)
Definition: ValidateMachineDialog.cc:164
ProgrammabilityValidator::GLOBAL_CONNECTION_REGISTER_NOT_FOUND
@ GLOBAL_CONNECTION_REGISTER_NOT_FOUND
Global connection register could not be determined.
Definition: ProgrammabilityValidator.hh:87
WxConversion::toWxString
static wxString toWxString(const std::string &source)
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
ProgrammabilityValidatorResults
Definition: ProgrammabilityValidatorResults.hh:46
ValidateMachineDialog
Definition: ValidateMachineDialog.hh:47
FindWindow
Definition: FindWindow.hh:49
ProgrammabilityValidatorResults::error
Error error(int index) const
Definition: ProgrammabilityValidatorResults.cc:70
assert
#define assert(condition)
Definition: Application.hh:86
ProgrammabilityValidator::MISSING_CONNECTION
@ MISSING_CONNECTION
Connection is missing to or from the global connection register.
Definition: ProgrammabilityValidator.hh:89
ProgrammabilityValidator
Definition: ProgrammabilityValidator.hh:75
ProgrammabilityValidator.hh
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
ValidateMachineDialog::~ValidateMachineDialog
~ValidateMachineDialog()
Definition: ValidateMachineDialog.cc:85
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
IllegalMachine
Definition: Exception.hh:878
ValidateMachineDialog::onCheck
void onCheck(wxCommandEvent &event)
Definition: ValidateMachineDialog.cc:95
WxConversion.hh
ProgrammabilityValidatorResults::errorCount
int errorCount() const
Definition: ProgrammabilityValidatorResults.cc:56
TTAMachine
Definition: Assembler.hh:48
ValidateMachineDialog.hh
ValidateMachineDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: ValidateMachineDialog.cc:181
ProgrammabilityValidator::validate
ProgrammabilityValidatorResults * validate()
Definition: ProgrammabilityValidator.cc:137
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine
Definition: Machine.hh:73