OpenASIP  2.0
VLIWConnectICCmd.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2017 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 VLIWConnectICCmd.cc
26  *
27  * Definition of VLIWConnectICCmd class.
28  *
29  * @author Alex Hirvonen 2017 (alex.hirvonen-no.spam-gmail.com)
30  * @note rating: red
31  */
32 
33 
34 #include <wx/docview.h>
35 #include <string>
36 
37 #include "VLIWConnectICCmd.hh"
38 #include "ProDeConstants.hh"
39 #include "Machine.hh"
40 #include "Model.hh"
41 #include "MDFDocument.hh"
42 #include "FileSystem.hh"
43 #include "DSDBManager.hh"
44 #include "ProDe.hh"
46 
47 
48 using namespace TTAMachine;
49 
50 
52  EditorCommand(ProDeConstants::CMD_NAME_VLIW_CONNECT_IC) {
53 }
54 
55 
57 
58 
59 /**
60  * Executes the command.
61  *
62  * @return True, if the command was succesfully executed, false otherwise.
63  */
64 bool
66 
67  assert(view() != NULL);
68 
69  TTAMachine::Machine* machine = dynamic_cast<MDFDocument*>(
70  view()->GetDocument())->getModel()->getMachine();
71 
72  Model* model = dynamic_cast<MDFDocument*>(
73  view()->GetDocument())->getModel();
74 
75  model->pushToStack();
76 
77  // open up a temporary dsdb
78  const std::string dsdbFile = "tmp.dsdb";
80  DSDBManager* dsdb = DSDBManager::createNew(dsdbFile);
81  RowID archID = dsdb->addArchitecture(*machine);
82 
84  RowID confID = dsdb->addConfiguration(confIn);
85 
86  // load VLIWConnectIC explorer plugin
87  DesignSpaceExplorer explorer;
89  explorer.loadExplorerPlugin("VLIWConnectIC", dsdb);
90  plugin->setDSDB(*dsdb);
91 
92  try {
93  std::vector<RowID> result = plugin->explore(confID, 0);
94  // store the new machine
95  TTAMachine::Machine& newMachine =
96  *dsdb->architecture(confID+result.size());
97  machine->copyFromMachine(newMachine);
98  } catch (Exception e) {
99  std::cerr << "Could not create VLIW Connect IC" << std::endl;
101  model->popFromStack();
102  return false;
103  }
105  model->notifyObservers();
106 
107  return true;
108 }
109 
110 /**
111  * Returns id of this command.
112  */
113 int
116 }
117 
118 
119 /**
120  * Creates and returns a new instance of this command.
121  */
124  return new VLIWConnectICCmd();
125 }
126 
127 
128 /**
129  * Returns short version of the command name.
130  */
131 std::string
134 }
135 
136 
137 /**
138  * Returns true when the command is executable, false when not.
139  *
140  * This command is executable when a document is open.
141  *
142  * @return True, if a document is open.
143  */
144 bool
146 
147  wxDocManager* manager = wxGetApp().docManager();
148  wxView* view = manager->GetCurrentView();
149 
150  if (view == NULL) {
151  return false;
152  }
153 
154  Model* model = dynamic_cast<MDFDocument*>(
155  view->GetDocument())->getModel();
156 
157  if (model == NULL) {
158  return false;
159  }
160  return true;
161 }
ILLEGAL_ROW_ID
#define ILLEGAL_ROW_ID
Definition: DSDBManager.hh:58
ProDe.hh
FileSystem.hh
FileSystem::removeFileOrDirectory
static bool removeFileOrDirectory(const std::string &path)
Definition: FileSystem.cc:493
MDFDocument.hh
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
VLIWConnectICCmd::Do
virtual bool Do()
Definition: VLIWConnectICCmd.cc:65
DSDBManager::architecture
TTAMachine::Machine * architecture(RowID id) const
Definition: DSDBManager.cc:807
DesignSpaceExplorerPlugin
Definition: DesignSpaceExplorerPlugin.hh:55
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
VLIWConnectICCmd::shortName
virtual std::string shortName() const
Definition: VLIWConnectICCmd.cc:132
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
DesignSpaceExplorerPlugin.hh
VLIWConnectICCmd.hh
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
DSDBManager::MachineConfiguration
Definition: DSDBManager.hh:78
VLIWConnectICCmd::create
virtual VLIWConnectICCmd * create() const
Definition: VLIWConnectICCmd.cc:123
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
Model.hh
Machine.hh
Exception
Definition: Exception.hh:54
DSDBManager
Definition: DSDBManager.hh:76
DesignSpaceExplorer::loadExplorerPlugin
static DesignSpaceExplorerPlugin * loadExplorerPlugin(const std::string &pluginName, DSDBManager *dsdb=NULL)
Definition: DesignSpaceExplorer.cc:527
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
VLIWConnectICCmd::isEnabled
virtual bool isEnabled()
Definition: VLIWConnectICCmd.cc:145
DSDBManager.hh
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
DSDBManager::addConfiguration
RowID addConfiguration(const MachineConfiguration &conf)
Definition: DSDBManager.cc:299
DSDBManager::addArchitecture
RowID addArchitecture(const TTAMachine::Machine &mom)
Definition: DSDBManager.cc:191
DSDBManager::createNew
static DSDBManager * createNew(const std::string &file)
Definition: DSDBManager.cc:141
DesignSpaceExplorerPlugin::explore
virtual std::vector< RowID > explore(const RowID &startPointConfigurationID, const unsigned int &maxIter=0)
Definition: DesignSpaceExplorerPlugin.cc:174
Model
Definition: Model.hh:50
VLIWConnectICCmd::id
virtual int id() const
Definition: VLIWConnectICCmd.cc:114
DesignSpaceExplorer::setDSDB
virtual void setDSDB(DSDBManager &dsdb)
Definition: DesignSpaceExplorer.cc:107
VLIWConnectICCmd::VLIWConnectICCmd
VLIWConnectICCmd()
Definition: VLIWConnectICCmd.cc:51
ProDeConstants::COMMAND_VLIW_CONNECT_IC
@ COMMAND_VLIW_CONNECT_IC
Definition: ProDeConstants.hh:455
TTAMachine::Machine::copyFromMachine
virtual void copyFromMachine(Machine &machine)
Definition: Machine.cc:890
EditorCommand
Definition: EditorCommand.hh:46
DesignSpaceExplorer
Definition: DesignSpaceExplorer.hh:70
VLIWConnectICCmd
Definition: VLIWConnectICCmd.hh:42
ProDeConstants::CMD_SNAME_VLIW_CONNECT_IC
static const std::string CMD_SNAME_VLIW_CONNECT_IC
Command name for the "VLIW Connect IC" command.
Definition: ProDeConstants.hh:245
ProDeConstants
Definition: ProDeConstants.hh:43
TTAMachine
Definition: Assembler.hh:48
VLIWConnectICCmd::~VLIWConnectICCmd
virtual ~VLIWConnectICCmd()
Definition: VLIWConnectICCmd.cc:56
TTAMachine::Machine
Definition: Machine.hh:73