OpenASIP  2.0
Public Member Functions | Static Private Attributes | List of all members
AddGCUCmd Class Reference

#include <AddGCUCmd.hh>

Inheritance diagram for AddGCUCmd:
Inheritance graph
Collaboration diagram for AddGCUCmd:
Collaboration graph

Public Member Functions

 AddGCUCmd ()
 
virtual bool Do ()
 
virtual int id () const
 
virtual AddGCUCmdcreate () const
 
virtual std::string shortName () const
 
virtual bool isEnabled ()
 
- Public Member Functions inherited from EditorCommand
 EditorCommand (std::string name, wxWindow *parent=NULL)
 
virtual ~EditorCommand ()
 
void setView (wxView *view)
 
wxView * view () const
 
virtual std::string icon () const
 
- Public Member Functions inherited from GUICommand
 GUICommand (std::string name, wxWindow *parent)
 
virtual ~GUICommand ()
 
virtual bool isChecked () const
 
void setParentWindow (wxWindow *view)
 
wxWindow * parentWindow () const
 
std::string name () const
 

Static Private Attributes

static const std::string RA_PORT_NAME = "ra"
 Name for the return address port. More...
 
static const std::string OP_PORT_NAME = "pc"
 Name for the jump/call operand port. More...
 
static const std::string OPNAME_JUMP = "jump"
 Name string for the jump operation. More...
 
static const std::string OPNAME_CALL = "call"
 Name string for the call operation. More...
 

Detailed Description

Command for adding new global control unit to the Machine.

Displays a global control unit dialog and creates a new global control unit according to the dialog output.

Definition at line 44 of file AddGCUCmd.hh.

Constructor & Destructor Documentation

◆ AddGCUCmd()

AddGCUCmd::AddGCUCmd ( )

The Constructor.

Definition at line 66 of file AddGCUCmd.cc.

Referenced by create().

Member Function Documentation

◆ create()

AddGCUCmd * AddGCUCmd::create ( ) const
virtual

Creates and returns a new instance of this command.

Returns
Newly created instance of this command.

Implements GUICommand.

Definition at line 151 of file AddGCUCmd.cc.

151  {
152  return new AddGCUCmd();
153 }

References AddGCUCmd().

Here is the call graph for this function:

◆ Do()

bool AddGCUCmd::Do ( )
virtual

Executes the command.

Returns
true, if the command was succesfully executed, false otherwise.

Implements GUICommand.

Definition at line 78 of file AddGCUCmd.cc.

78  {
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 }

References TTAMachine::ExecutionPipeline::addPortRead(), assert, TTAMachine::HWOperation::bindPort(), ProDeConstants::COMP_DEFAULT_NAME_GCU, TTAMachine::Machine::controlUnit(), Model::getMachine(), ProDeTextGenerator::instance(), ProDeTextGenerator::MSG_ERROR_ONE_GCU, Model::notifyObservers(), OP_PORT_NAME, OPNAME_CALL, OPNAME_JUMP, GUICommand::parentWindow(), TTAMachine::HWOperation::pipeline(), Model::popFromStack(), Model::pushToStack(), RA_PORT_NAME, TTAMachine::ControlUnit::setMachine(), TTAMachine::ControlUnit::setReturnAddressPort(), Texts::TextGenerator::text(), WxConversion::toWxString(), and EditorCommand::view().

Here is the call graph for this function:

◆ id()

int AddGCUCmd::id ( ) const
virtual

Returns id of this command.

Returns
ID for this command to be used in menus and toolbars.

Implements GUICommand.

Definition at line 140 of file AddGCUCmd.cc.

140  {
142 }

References ProDeConstants::COMMAND_ADD_GCU.

◆ isEnabled()

bool AddGCUCmd::isEnabled ( )
virtual

Returns true when the command is executable, false when not.

This command is executable when a document is open.

Returns
True, if a document is open.

Reimplemented from EditorCommand.

Definition at line 176 of file AddGCUCmd.cc.

176  {
177  wxDocManager* manager = wxGetApp().docManager();
178  if (manager->GetCurrentView() != NULL) {
179  return true;
180  }
181  return false;
182 }

◆ shortName()

string AddGCUCmd::shortName ( ) const
virtual

Returns short version of the command name.

Returns
Short name of the command to be used in the toolbar.

Reimplemented from GUICommand.

Definition at line 163 of file AddGCUCmd.cc.

163  {
165 }

References ProDeConstants::CMD_SNAME_ADD_GCU.

Member Data Documentation

◆ OP_PORT_NAME

const std::string AddGCUCmd::OP_PORT_NAME = "pc"
staticprivate

Name for the jump/call operand port.

Definition at line 57 of file AddGCUCmd.hh.

Referenced by Do().

◆ OPNAME_CALL

const std::string AddGCUCmd::OPNAME_CALL = "call"
staticprivate

Name string for the call operation.

Definition at line 61 of file AddGCUCmd.hh.

Referenced by Do().

◆ OPNAME_JUMP

const std::string AddGCUCmd::OPNAME_JUMP = "jump"
staticprivate

Name string for the jump operation.

Definition at line 59 of file AddGCUCmd.hh.

Referenced by Do().

◆ RA_PORT_NAME

const std::string AddGCUCmd::RA_PORT_NAME = "ra"
staticprivate

Name for the return address port.

Definition at line 55 of file AddGCUCmd.hh.

Referenced by Do().


The documentation for this class was generated from the following files:
WxConversion::toWxString
static wxString toWxString(const std::string &source)
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
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
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
EditorCommand::EditorCommand
EditorCommand(std::string name, wxWindow *parent=NULL)
Definition: EditorCommand.cc:42
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
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
TTAMachine::ExecutionPipeline::addPortRead
void addPortRead(int operand, int start, int duration)
Definition: ExecutionPipeline.cc:141
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
AddGCUCmd::AddGCUCmd
AddGCUCmd()
Definition: AddGCUCmd.cc:66
MDFDocument
Definition: MDFDocument.hh:51
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
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
InformationDialog
Definition: InformationDialog.hh:42
ProDeConstants::CMD_NAME_ADD_GCU
static const std::string CMD_NAME_ADD_GCU
Command name for the "Add Global Control Unit" command.
Definition: ProDeConstants.hh:105
AddGCUCmd::OPNAME_JUMP
static const std::string OPNAME_JUMP
Name string for the jump operation.
Definition: AddGCUCmd.hh:59
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