OpenASIP 2.2
Loading...
Searching...
No Matches
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"
53
54using std::string;
55using boost::format;
56using namespace TTAMachine;
57
58const std::string AddGCUCmd::RA_PORT_NAME = "ra";
59const std::string AddGCUCmd::OP_PORT_NAME = "pc";
60const std::string AddGCUCmd::OPNAME_JUMP = "jump";
61const 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 */
77bool
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 */
139int
143
144
145/**
146 * Creates and returns a new instance of this command.
147 *
148 * @return Newly created instance of this command.
149 */
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 */
162string
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 */
175bool
177 wxDocManager* manager = wxGetApp().docManager();
178 if (manager->GetCurrentView() != NULL) {
179 return true;
180 }
181 return false;
182}
#define assert(condition)
static const std::string RA_PORT_NAME
Name for the return address port.
Definition AddGCUCmd.hh:55
static const std::string OPNAME_CALL
Name string for the call operation.
Definition AddGCUCmd.hh:61
virtual std::string shortName() const
Definition AddGCUCmd.cc:163
virtual int id() const
Definition AddGCUCmd.cc:140
virtual bool Do()
Definition AddGCUCmd.cc:78
virtual AddGCUCmd * create() const
Definition AddGCUCmd.cc:151
static const std::string OPNAME_JUMP
Name string for the jump operation.
Definition AddGCUCmd.hh:59
static const std::string OP_PORT_NAME
Name for the jump/call operand port.
Definition AddGCUCmd.hh:57
virtual bool isEnabled()
Definition AddGCUCmd.cc:176
wxView * view() const
wxWindow * parentWindow() const
Definition GUICommand.cc:75
Definition Model.hh:50
void pushToStack()
Definition Model.cc:167
void notifyObservers(bool modified=true)
Definition Model.cc:152
void popFromStack(bool modified=false)
Definition Model.cc:195
TTAMachine::Machine * getMachine()
Definition Model.cc:88
static const std::string CMD_SNAME_ADD_GCU
Command name for the "Add Global Control Unit" command.
static const std::string COMP_DEFAULT_NAME_GCU
Default name for new control units.
static ProDeTextGenerator * instance()
@ MSG_ERROR_ONE_GCU
Error: Multiple control units.
void setReturnAddressPort(const SpecialRegisterPort &port)
virtual void setMachine(Machine &mach)
void addPortRead(int operand, int start, int duration)
ExecutionPipeline * pipeline() const
virtual void bindPort(int operand, const FUPort &port)
virtual ControlUnit * controlUnit() const
Definition Machine.cc:345
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)