OpenASIP  2.0
BlocksConnectICCmd.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2021 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 BlocksConnectICCmd.cc
26  *
27  * Definition of BlocksConnectICCmd class. (Derived from VLIWConnectICCmd.cc)
28  *
29  * @author Kanishkan Vadivel 2021 (k.vadivel-no.spam-tue.nl)
30  * @note rating: red
31  */
32 
33 #include "BlocksConnectICCmd.hh"
34 
35 #include <wx/docview.h>
36 
37 #include <string>
38 
39 #include "DSDBManager.hh"
41 #include "FileSystem.hh"
42 #include "MDFDocument.hh"
43 #include "Machine.hh"
44 #include "Model.hh"
45 #include "ProDe.hh"
46 #include "ProDeConstants.hh"
47 
48 using namespace TTAMachine;
49 
51  : EditorCommand(ProDeConstants::CMD_NAME_BLOCKS_CONNECT_IC) {}
52 
54 
55 /**
56  * Executes the command.
57  *
58  * @return True, if the command was succesfully executed, false otherwise.
59  */
60 bool
62  assert(view() != NULL);
63 
65  dynamic_cast<MDFDocument*>(view()->GetDocument())
66  ->getModel()
67  ->getMachine();
68 
69  Model* model =
70  dynamic_cast<MDFDocument*>(view()->GetDocument())->getModel();
71 
72  model->pushToStack();
73 
74  // open up a temporary dsdb
75  const std::string dsdbFile = "tmp.dsdb";
77  DSDBManager* dsdb = DSDBManager::createNew(dsdbFile);
78  RowID archID = dsdb->addArchitecture(*machine);
79 
81  RowID confID = dsdb->addConfiguration(confIn);
82 
83  // load BlocksConnectIC explorer plugin
84  DesignSpaceExplorer explorer;
86  explorer.loadExplorerPlugin("BlocksConnectIC", dsdb);
87  plugin->setDSDB(*dsdb);
88 
89  try {
90  std::vector<RowID> result = plugin->explore(confID, 0);
91  // store the new machine
92  TTAMachine::Machine& newMachine =
93  *dsdb->architecture(confID + result.size());
94  machine->copyFromMachine(newMachine);
95  } catch (Exception e) {
96  std::cerr << "Could not create Blocks Connect IC" << std::endl;
98  model->popFromStack();
99  return false;
100  }
102  model->notifyObservers();
103 
104  return true;
105 }
106 
107 /**
108  * Returns id of this command.
109  */
110 int
113 }
114 
115 /**
116  * Creates and returns a new instance of this command.
117  */
120  return new BlocksConnectICCmd();
121 }
122 
123 /**
124  * Returns short version of the command name.
125  */
126 std::string
129 }
130 
131 /**
132  * Returns true when the command is executable, false when not.
133  *
134  * This command is executable when a document is open.
135  *
136  * @return True, if a document is open.
137  */
138 bool
140  wxDocManager* manager = wxGetApp().docManager();
141  wxView* view = manager->GetCurrentView();
142 
143  if (view == NULL) {
144  return false;
145  }
146 
147  Model* model =
148  dynamic_cast<MDFDocument*>(view->GetDocument())->getModel();
149 
150  if (model == NULL) {
151  return false;
152  }
153  return true;
154 }
ILLEGAL_ROW_ID
#define ILLEGAL_ROW_ID
Definition: DSDBManager.hh:58
ProDe.hh
BlocksConnectICCmd.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
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
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
DesignSpaceExplorerPlugin.hh
BlocksConnectICCmd::isEnabled
virtual bool isEnabled()
Definition: BlocksConnectICCmd.cc:139
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
BlocksConnectICCmd::~BlocksConnectICCmd
virtual ~BlocksConnectICCmd()
Definition: BlocksConnectICCmd.cc:53
DSDBManager::MachineConfiguration
Definition: DSDBManager.hh:78
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
Model.hh
BlocksConnectICCmd::shortName
virtual std::string shortName() const
Definition: BlocksConnectICCmd.cc:127
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
DSDBManager.hh
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants::CMD_SNAME_BLOCKS_CONNECT_IC
static const std::string CMD_SNAME_BLOCKS_CONNECT_IC
Command name for the "Blocks Connect IC" command.
Definition: ProDeConstants.hh:247
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
DesignSpaceExplorer::setDSDB
virtual void setDSDB(DSDBManager &dsdb)
Definition: DesignSpaceExplorer.cc:107
BlocksConnectICCmd::id
virtual int id() const
Definition: BlocksConnectICCmd.cc:111
TTAMachine::Machine::copyFromMachine
virtual void copyFromMachine(Machine &machine)
Definition: Machine.cc:890
EditorCommand
Definition: EditorCommand.hh:46
DesignSpaceExplorer
Definition: DesignSpaceExplorer.hh:70
BlocksConnectICCmd
Definition: BlocksConnectICCmd.hh:41
ProDeConstants
Definition: ProDeConstants.hh:43
TTAMachine
Definition: Assembler.hh:48
BlocksConnectICCmd::BlocksConnectICCmd
BlocksConnectICCmd()
Definition: BlocksConnectICCmd.cc:50
BlocksConnectICCmd::create
virtual BlocksConnectICCmd * create() const
Definition: BlocksConnectICCmd.cc:119
BlocksConnectICCmd::Do
virtual bool Do()
Definition: BlocksConnectICCmd.cc:61
TTAMachine::Machine
Definition: Machine.hh:73
ProDeConstants::COMMAND_BLOCKS_CONNECT_IC
@ COMMAND_BLOCKS_CONNECT_IC
Definition: ProDeConstants.hh:456