OpenASIP  2.0
AddGCUCmd.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 AddGCUCmd.cc
26  *
27  * Definition of AddGCUCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/wx.h>
34 #include <wx/docview.h>
35 #include <boost/format.hpp>
36 
37 #include "AddGCUCmd.hh"
38 #include "GCUDialog.hh"
39 #include "Model.hh"
40 #include "MDFDocument.hh"
41 #include "ProDeConstants.hh"
42 #include "ProDe.hh"
43 #include "InformationDialog.hh"
44 #include "Machine.hh"
45 #include "ControlUnit.hh"
46 #include "ProDeTextGenerator.hh"
47 #include "WxConversion.hh"
48 #include "ModelConstants.hh"
49 #include "HWOperation.hh"
50 #include "ExecutionPipeline.hh"
51 #include "FUPort.hh"
52 #include "SpecialRegisterPort.hh"
53 
54 using std::string;
55 using boost::format;
56 using namespace TTAMachine;
57 
58 const std::string AddGCUCmd::RA_PORT_NAME = "ra";
59 const std::string AddGCUCmd::OP_PORT_NAME = "pc";
60 const std::string AddGCUCmd::OPNAME_JUMP = "jump";
61 const std::string AddGCUCmd::OPNAME_CALL = "call";
62 
63 /**
64  * The Constructor.
65  */
67  EditorCommand(ProDeConstants::CMD_NAME_ADD_GCU) {
68 }
69 
70 
71 
72 /**
73  * Executes the command.
74  *
75  * @return true, if the command was succesfully executed, false otherwise.
76  */
77 bool
79 
80  assert(parentWindow() != NULL);
81  assert(view() != NULL);
82 
83  Model* model = dynamic_cast<MDFDocument*>(
84  view()->GetDocument())->getModel();
85 
86 
87  // check that the machine doesn't have a global control unit yet
88  if (model->getMachine()->controlUnit() != NULL) {
90  format fmt = generator->text(ProDeTextGenerator::MSG_ERROR_ONE_GCU);
91  string title = fmt.str();
92  wxString message = WxConversion::toWxString(title);
93  InformationDialog info(parentWindow(), message);
94  info.ShowModal();
95  return false;
96  }
97 
98  model->pushToStack();
99 
100  // Add default ports.
101  ControlUnit* gcu = new ControlUnit(
103 
104  FUPort* opPort = new FUPort(OP_PORT_NAME, 32, *gcu, true, true);
105  SpecialRegisterPort* raPort =
106  new SpecialRegisterPort(RA_PORT_NAME, 32, *gcu);
107 
108  gcu->setReturnAddressPort(*raPort);
109 
110  // Add default operations.
111  HWOperation* jump = new HWOperation(OPNAME_JUMP, *gcu);
112  jump->bindPort(1, *opPort);
113  jump->pipeline()->addPortRead(1, 0, 1);
114 
115  HWOperation* call = new HWOperation(OPNAME_CALL, *gcu);
116  call->bindPort(1, *opPort);
117  call->pipeline()->addPortRead(1, 0, 1);
118 
119  gcu->setMachine(*(model->getMachine()));
120 
121  GCUDialog dialog(parentWindow(), gcu);
122  if (dialog.ShowModal() == wxID_OK) {
123  model->notifyObservers();
124  return true;
125  } else {
126  model->popFromStack();
127  return false;
128  }
129 
130  return false;
131 }
132 
133 
134 /**
135  * Returns id of this command.
136  *
137  * @return ID for this command to be used in menus and toolbars.
138  */
139 int
140 AddGCUCmd::id() const {
142 }
143 
144 
145 /**
146  * Creates and returns a new instance of this command.
147  *
148  * @return Newly created instance of this command.
149  */
150 AddGCUCmd*
152  return new AddGCUCmd();
153 }
154 
155 
156 
157 /**
158  * Returns short version of the command name.
159  *
160  * @return Short name of the command to be used in the toolbar.
161  */
162 string
165 }
166 
167 
168 /**
169  * Returns true when the command is executable, false when not.
170  *
171  * This command is executable when a document is open.
172  *
173  * @return True, if a document is open.
174  */
175 bool
177  wxDocManager* manager = wxGetApp().docManager();
178  if (manager->GetCurrentView() != NULL) {
179  return true;
180  }
181  return false;
182 }
ProDe.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
MDFDocument.hh
AddGCUCmd::OP_PORT_NAME
static const std::string OP_PORT_NAME
Name for the jump/call operand port.
Definition: AddGCUCmd.hh:57
TTAMachine::HWOperation
Definition: HWOperation.hh:52
ProDeConstants::CMD_SNAME_ADD_GCU
static const std::string CMD_SNAME_ADD_GCU
Command name for the "Add Global Control Unit" command.
Definition: ProDeConstants.hh:217
ExecutionPipeline.hh
TTAMachine::HWOperation::bindPort
virtual void bindPort(int operand, const FUPort &port)
Definition: HWOperation.cc:269
ProDeConstants::COMMAND_ADD_GCU
@ COMMAND_ADD_GCU
Definition: ProDeConstants.hh:423
ProDeConstants::COMP_DEFAULT_NAME_GCU
static const std::string COMP_DEFAULT_NAME_GCU
Default name for new control units.
Definition: ProDeConstants.hh:357
AddGCUCmd::create
virtual AddGCUCmd * create() const
Definition: AddGCUCmd.cc:151
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ProDeTextGenerator.hh
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAMachine::Machine::controlUnit
virtual ControlUnit * controlUnit() const
Definition: Machine.cc:345
HWOperation.hh
TTAMachine::SpecialRegisterPort
Definition: SpecialRegisterPort.hh:48
GCUDialog
Definition: GCUDialog.hh:48
TTAMachine::ControlUnit
Definition: ControlUnit.hh:50
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
AddGCUCmd.hh
InformationDialog.hh
AddGCUCmd
Definition: AddGCUCmd.hh:44
Model.hh
TTAMachine::ExecutionPipeline::addPortRead
void addPortRead(int operand, int start, int duration)
Definition: ExecutionPipeline.cc:141
AddGCUCmd::Do
virtual bool Do()
Definition: AddGCUCmd.cc:78
GCUDialog.hh
ModelConstants.hh
Machine.hh
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
AddGCUCmd::AddGCUCmd
AddGCUCmd()
Definition: AddGCUCmd.cc:66
AddGCUCmd::shortName
virtual std::string shortName() const
Definition: AddGCUCmd.cc:163
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
Model
Definition: Model.hh:50
TTAMachine::ControlUnit::setMachine
virtual void setMachine(Machine &mach)
Definition: ControlUnit.cc:119
AddGCUCmd::id
virtual int id() const
Definition: AddGCUCmd.cc:140
FUPort.hh
ControlUnit.hh
SpecialRegisterPort.hh
ProDeTextGenerator::MSG_ERROR_ONE_GCU
@ MSG_ERROR_ONE_GCU
Error: Multiple control units.
Definition: ProDeTextGenerator.hh:224
AddGCUCmd::RA_PORT_NAME
static const std::string RA_PORT_NAME
Name for the return address port.
Definition: AddGCUCmd.hh:55
TTAMachine::ControlUnit::setReturnAddressPort
void setReturnAddressPort(const SpecialRegisterPort &port)
Definition: ControlUnit.cc:271
TTAMachine::HWOperation::pipeline
ExecutionPipeline * pipeline() const
Definition: HWOperation.cc:201
EditorCommand
Definition: EditorCommand.hh:46
WxConversion.hh
InformationDialog
Definition: InformationDialog.hh:42
ProDeConstants
Definition: ProDeConstants.hh:43
TTAMachine
Definition: Assembler.hh:48
AddGCUCmd::OPNAME_JUMP
static const std::string OPNAME_JUMP
Name string for the jump operation.
Definition: AddGCUCmd.hh:59
AddGCUCmd::isEnabled
virtual bool isEnabled()
Definition: AddGCUCmd.cc:176
AddGCUCmd::OPNAME_CALL
static const std::string OPNAME_CALL
Name string for the call operation.
Definition: AddGCUCmd.hh:61
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88