OpenASIP  2.0
AddRFCmd.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 AddRFCmd.cc
26  *
27  * Definition of AddRFCmd 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 
36 #include "AddRFCmd.hh"
37 #include "RFDialog.hh"
38 #include "Model.hh"
39 #include "MDFDocument.hh"
40 #include "ProDeConstants.hh"
41 #include "ModelConstants.hh"
42 #include "ErrorDialog.hh"
43 #include "ProDe.hh"
44 #include "RegisterFile.hh"
45 #include "Machine.hh"
46 #include "Conversion.hh"
47 
48 using std::string;
49 using namespace TTAMachine;
50 
51 /**
52  * The Constructor.
53  */
55  EditorCommand(ProDeConstants::CMD_NAME_ADD_RF) {
56 }
57 
58 
59 
60 /**
61  * Executes the command.
62  *
63  * @return true, if the command was succesfully executed, false otherwise.
64  */
65 bool
67 
68  assert(parentWindow() != NULL);
69  assert(view() != NULL);
70 
71  Model* model = dynamic_cast<MDFDocument*>(
72  view()->GetDocument())->getModel();
73 
74  model->pushToStack();
75 
76  // Generate name for the new RF.
80  int i = 1;
81  while (navigator.hasItem(newName)) {
84  i++;
85  }
86 
87  RegisterFile* rf = new RegisterFile(
93 
94  rf->setMachine(*(model->getMachine()));
95 
96  RFDialog dialog(parentWindow(), rf);
97 
98  if (dialog.ShowModal() == wxID_OK) {
99  model->notifyObservers();
100  return true;
101  } else {
102  // register file creation was cancelled
103  model->popFromStack();
104  return false;
105  }
106 }
107 
108 
109 /**
110  * Returns id of this command.
111  *
112  * @return ID for this command to be used in menus and toolbars.
113  */
114 int
115 AddRFCmd::id() const {
117 }
118 
119 
120 /**
121  * Creates and returns a new instance of this command.
122  *
123  * @return Newly created instance of this command.
124  */
125 AddRFCmd*
127  return new AddRFCmd();
128 }
129 
130 /**
131  * Returns short version of the command name.
132  *
133  * @return Short name of the command to be used in the toolbar.
134  */
135 string
138 }
139 
140 
141 /**
142  * Returns true when the command is executable, false when not.
143  *
144  * This command is executable when a document is open.
145  *
146  * @return True, if a document is open.
147  */
148 bool
150  wxDocManager* manager = wxGetApp().docManager();
151  if (manager->GetCurrentView() != NULL) {
152  return true;
153  }
154  return false;
155 }
AddRFCmd.hh
AddRFCmd::AddRFCmd
AddRFCmd()
Definition: AddRFCmd.cc:54
ProDe.hh
ModelConstants::DEFAULT_RF_SIZE
static const int DEFAULT_RF_SIZE
Default register file type.
Definition: ModelConstants.hh:48
MDFDocument.hh
ModelConstants::DEFAULT_RF_GUARD_LATENCY
static const int DEFAULT_RF_GUARD_LATENCY
Default local RF guard latency.
Definition: ModelConstants.hh:54
ProDeConstants::CMD_SNAME_ADD_RF
static const std::string CMD_SNAME_ADD_RF
Command name for the "Add Register File" command.
Definition: ProDeConstants.hh:207
AddRFCmd::shortName
virtual std::string shortName() const
Definition: AddRFCmd.cc:136
RFDialog.hh
Conversion::toString
static std::string toString(const T &source)
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
ModelConstants::DEFAULT_WIDTH
static const int DEFAULT_WIDTH
Default bit width.
Definition: ModelConstants.hh:46
ErrorDialog.hh
Conversion.hh
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
Model.hh
ModelConstants.hh
NORMAL
@ NORMAL
Definition: tceopgen.cc:45
Machine.hh
ProDeConstants::COMMAND_ADD_RF
@ COMMAND_ADD_RF
Definition: ProDeConstants.hh:418
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
TTAMachine::Machine::registerFileNavigator
virtual RegisterFileNavigator registerFileNavigator() const
Definition: Machine.cc:450
Model
Definition: Model.hh:50
RegisterFile.hh
TTAMachine::Unit::setMachine
virtual void setMachine(Machine &mach)
Definition: Unit.cc:253
ProDeConstants::COMP_NEW_NAME_PREFIX_RF
static const std::string COMP_NEW_NAME_PREFIX_RF
Prefix for new register file names.
Definition: ProDeConstants.hh:365
EditorCommand
Definition: EditorCommand.hh:46
AddRFCmd::create
virtual AddRFCmd * create() const
Definition: AddRFCmd.cc:126
AddRFCmd::id
virtual int id() const
Definition: AddRFCmd.cc:115
AddRFCmd::isEnabled
virtual bool isEnabled()
Definition: AddRFCmd.cc:149
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
AddRFCmd::Do
virtual bool Do()
Definition: AddRFCmd.cc:66
ModelConstants::DEFAULT_RF_MAX_WRITES
static const int DEFAULT_RF_MAX_WRITES
Default maximum read ports while writing for a register file.
Definition: ModelConstants.hh:52
ProDeConstants
Definition: ProDeConstants.hh:43
TTAMachine
Definition: Assembler.hh:48
AddRFCmd
Definition: AddRFCmd.hh:43
ModelConstants::DEFAULT_RF_MAX_READS
static const int DEFAULT_RF_MAX_READS
Default maximum read ports of register file.
Definition: ModelConstants.hh:50
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
RFDialog
Definition: RFDialog.hh:47
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88