OpenASIP  2.0
GCUFactory.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 GCUFactory.cc
26  *
27  * Definition of GCUFactory class.
28  *
29  * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: yellow
31  * @note reviewed Jul 14 2004 by jm, ll, jn, am
32  */
33 
34 #include <string>
35 #include <vector>
36 
37 #include "WxConversion.hh"
38 #include "GCUFactory.hh"
39 #include "UnitPortFactory.hh"
40 #include "ControlUnit.hh"
41 #include "EditPart.hh"
42 #include "UnitFigure.hh"
43 #include "FUPort.hh"
44 #include "SpecialRegisterPort.hh"
45 #include "EditPolicyFactory.hh"
46 #include "HWOperation.hh"
47 
48 using std::vector;
49 using namespace TTAMachine;
50 
51 /**
52  * The Constructor.
53  */
55  EditPartFactory(editPolicyFactory) {
56  registerFactory(new UnitPortFactory(editPolicyFactory));
57 }
58 
59 /**
60  * The Destructor.
61  */
63 }
64 
65 /**
66  * Returns an EditPart corresponding to a global control unit.
67  *
68  * @param component Global control unit of which to create the EditPart.
69  * @return NULL if the parameter is not an instance of the
70  * ControlUnit class.
71  */
72 EditPart*
74 
75  ControlUnit* gcu = dynamic_cast<ControlUnit*>(component);
76 
77  if (gcu != NULL) {
78  EditPart* gcuEditPart = new EditPart();
79  gcuEditPart->setModel(gcu);
80 
81  UnitFigure* fig = new UnitFigure();
82  wxString name = WxConversion::toWxString(gcu->name());
83  name.Prepend(_T("GCU: "));
84  fig->setName(name);
85  gcuEditPart->setFigure(fig);
86 
87  // Create editparts of operation ports.
88  for (int i = 0; i < gcu->operationPortCount(); i++) {
89  vector<Factory*>::const_iterator iter;
90  for (iter = factories_.begin(); iter != factories_.end(); iter++) {
91  EditPart* portEditPart =
92  (*iter)->createEditPart(gcu->operationPort(i));
93  if (portEditPart != NULL) {
94  EditPolicy* portEditPolicy =
96  if (portEditPolicy != NULL) {
97  portEditPart->installEditPolicy(portEditPolicy);
98  }
99  gcuEditPart->addChild(portEditPart);
100  }
101  }
102  }
103 
104  // Create editparts of special register ports.
105  for (int i = 0; i < gcu->specialRegisterPortCount(); i++) {
106  vector<Factory*>::const_iterator iter;
107  for (iter = factories_.begin(); iter != factories_.end(); iter++) {
108  EditPart* portEditPart =
109  (*iter)->createEditPart(gcu->specialRegisterPort(i));
110  if (portEditPart != NULL) {
111  EditPolicy* portEditPolicy =
113  if (portEditPolicy != NULL) {
114  portEditPart->installEditPolicy(portEditPolicy);
115  }
116  gcuEditPart->addChild(portEditPart);
117  }
118  }
119  }
120 
121  wxString operations = _T("{ ");
122  for (int i = 0; i < gcu->operationCount(); i++) {
123  if (i > 0) {
124  operations.Append(_T(", "));
125  }
126  operations.Append(
128  }
129  operations.Append(_T(" }"));
130 
131  fig->setInfo(operations);
132 
133  gcuEditPart->setSelectable(true);
134 
136  if (editPolicy != NULL) {
137  gcuEditPart->installEditPolicy(editPolicy);
138  }
139 
140  return gcuEditPart;
141 
142  } else {
143  return NULL;
144  }
145 }
EditPolicyFactory::createGCUEditPolicy
virtual EditPolicy * createGCUEditPolicy()
EditPolicyFactory
Definition: EditPolicyFactory.hh:46
WxConversion::toWxString
static wxString toWxString(const std::string &source)
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
EditPart::setSelectable
void setSelectable(bool selectable)
UnitPortFactory.hh
EditPart::installEditPolicy
void installEditPolicy(EditPolicy *editpolicy)
Definition: EditPart.cc:247
EditPolicyFactory::createFUPortEditPolicy
virtual EditPolicy * createFUPortEditPolicy()
EditPartFactory::registerFactory
void registerFactory(Factory *factory)
EditPolicyFactory.hh
HWOperation.hh
TTAMachine::HWOperation::name
const std::string & name() const
Definition: HWOperation.cc:141
EditPart.hh
TTAMachine::ControlUnit
Definition: ControlUnit.hh:50
TTAMachine::ControlUnit::specialRegisterPort
SpecialRegisterPort * specialRegisterPort(int index) const
Definition: ControlUnit.cc:211
EditPartFactory
Definition: EditPartFactory.hh:48
UnitFigure::setInfo
void setInfo(const wxString &info)
Definition: UnitFigure.cc:323
TTAMachine::ControlUnit::specialRegisterPortCount
int specialRegisterPortCount() const
Definition: ControlUnit.cc:185
EditPolicyFactory::createSRPortEditPolicy
virtual EditPolicy * createSRPortEditPolicy()
EditPart::setModel
void setModel(TTAMachine::MachinePart *model)
TTAMachine::MachinePart
Definition: MachinePart.hh:57
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
UnitFigure::setName
void setName(const wxString &name)
Definition: UnitFigure.cc:304
EditPolicy
Definition: EditPolicy.hh:47
EditPart
Definition: EditPart.hh:60
TTAMachine::FunctionUnit::operationPortCount
virtual int operationPortCount() const
Definition: FunctionUnit.cc:182
GCUFactory.hh
UnitFigure.hh
UnitPortFactory
Definition: UnitPortFactory.hh:45
UnitFigure
Definition: UnitFigure.hh:46
FUPort.hh
ControlUnit.hh
GCUFactory::~GCUFactory
virtual ~GCUFactory()
Definition: GCUFactory.cc:62
SpecialRegisterPort.hh
EditPart::setFigure
void setFigure(Figure *figure)
WxConversion.hh
GCUFactory::createEditPart
virtual EditPart * createEditPart(TTAMachine::MachinePart *component)
Definition: GCUFactory.cc:73
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
EditPart::addChild
void addChild(EditPart *child)
Definition: EditPart.cc:260
TTAMachine::FunctionUnit::operationPort
virtual FUPort * operationPort(const std::string &name) const
Definition: FunctionUnit.cc:224
TTAMachine
Definition: Assembler.hh:48
EditPartFactory::editPolicyFactory_
EditPolicyFactory & editPolicyFactory_
Factory which creates edit policies for edit parts.
Definition: EditPartFactory.hh:64
GCUFactory::GCUFactory
GCUFactory(EditPolicyFactory &editPolicyFactory)
Definition: GCUFactory.cc:54
EditPartFactory::factories_
std::vector< Factory * > factories_
Registered factories.
Definition: EditPartFactory.hh:60