OpenASIP  2.0
RFFactory.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 RFFactory.cc
26  *
27  * Definition of RFFactory 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 "RFFactory.hh"
38 #include "UnitPortFactory.hh"
39 #include "RegisterFile.hh"
40 #include "EditPart.hh"
41 #include "UnitFigure.hh"
42 #include "WxConversion.hh"
43 #include "FUPort.hh"
44 #include "EditPolicyFactory.hh"
45 #include "UnboundedRegisterFile.hh"
46 
47 using std::vector;
48 using namespace TTAMachine;
49 
50 /**
51  * The Constructor.
52  */
54  EditPartFactory(editPolicyFactory) {
55 
56  registerFactory(new UnitPortFactory(editPolicyFactory));
57 }
58 
59 /**
60  * The Destructor.
61  */
63 }
64 
65 /**
66  * Returns an EditPart corresponding to a register file.
67  *
68  * @param component Register file of which to create the EditPart.
69  * @return NULL if the parameter is not an instance of the
70  * RegisterFile class.
71  */
72 EditPart*
74 
75  RegisterFile* rf = dynamic_cast<RegisterFile*>(component);
76 
77  if (rf != NULL) {
78  EditPart* rfEditPart = new EditPart();
79  rfEditPart->setModel(rf);
80 
81  UnitFigure* fig = new UnitFigure();
82  wxString name = WxConversion::toWxString(rf->name().c_str());
83  name.Prepend(_T("RF: "));
84  fig->setName(name);
85  rfEditPart->setFigure(fig);
86 
87  for (int i = 0; i < rf->portCount(); i++) {
88  vector<Factory*>::const_iterator iter;
89  for (iter = factories_.begin(); iter != factories_.end(); iter++) {
90  EditPart* portEditPart =
91  (*iter)->createEditPart(rf->port(i));
92  if (portEditPart != NULL) {
93 
94  EditPolicy* editPolicy =
96 
97  if (editPolicy != NULL) {
98  portEditPart->installEditPolicy(editPolicy);
99  }
100 
101  rfEditPart->addChild(portEditPart);
102  }
103  }
104  }
105 
106  wxString info;
107  if (dynamic_cast<UnboundedRegisterFile*>(rf) != NULL) {
108  info.Append(_T("?"));
109  } else {
110  info.Append(WxConversion::toWxString(rf->numberOfRegisters()));
111  }
112  info.Append(_T("x"));
113  info.Append(WxConversion::toWxString(rf->width()));
114 
115  fig->setInfo(info);
116 
117  rfEditPart->setSelectable(true);
118 
120  if (editPolicy != NULL) {
121  rfEditPart->installEditPolicy(editPolicy);
122  }
123 
124  return rfEditPart;
125 
126  } else {
127  return NULL;
128  }
129 }
RFFactory::RFFactory
RFFactory(EditPolicyFactory &editPolicyFactory)
Definition: RFFactory.cc:53
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
UnboundedRegisterFile
Definition: UnboundedRegisterFile.hh:43
EditPart::setSelectable
void setSelectable(bool selectable)
UnitPortFactory.hh
EditPart::installEditPolicy
void installEditPolicy(EditPolicy *editpolicy)
Definition: EditPart.cc:247
RFFactory.hh
TTAMachine::BaseRegisterFile::numberOfRegisters
virtual int numberOfRegisters() const
EditPartFactory::registerFactory
void registerFactory(Factory *factory)
EditPolicyFactory.hh
EditPart.hh
EditPartFactory
Definition: EditPartFactory.hh:48
UnitFigure::setInfo
void setInfo(const wxString &info)
Definition: UnitFigure.cc:323
UnboundedRegisterFile.hh
EditPart::setModel
void setModel(TTAMachine::MachinePart *model)
TTAMachine::MachinePart
Definition: MachinePart.hh:57
UnitFigure::setName
void setName(const wxString &name)
Definition: UnitFigure.cc:304
EditPolicyFactory::createRFPortEditPolicy
virtual EditPolicy * createRFPortEditPolicy()
EditPolicy
Definition: EditPolicy.hh:47
EditPart
Definition: EditPart.hh:60
TTAMachine::Unit::portCount
virtual int portCount() const
Definition: Unit.cc:135
UnitFigure.hh
UnitPortFactory
Definition: UnitPortFactory.hh:45
TTAMachine::BaseRegisterFile::port
virtual RFPort * port(const std::string &name) const
Definition: BaseRegisterFile.cc:129
UnitFigure
Definition: UnitFigure.hh:46
RegisterFile.hh
FUPort.hh
EditPart::setFigure
void setFigure(Figure *figure)
WxConversion.hh
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
EditPart::addChild
void addChild(EditPart *child)
Definition: EditPart.cc:260
RFFactory::createEditPart
virtual EditPart * createEditPart(TTAMachine::MachinePart *component)
Definition: RFFactory.cc:73
EditPolicyFactory::createRFEditPolicy
virtual EditPolicy * createRFEditPolicy()
TTAMachine
Definition: Assembler.hh:48
RFFactory::~RFFactory
virtual ~RFFactory()
Definition: RFFactory.cc:62
EditPartFactory::editPolicyFactory_
EditPolicyFactory & editPolicyFactory_
Factory which creates edit policies for edit parts.
Definition: EditPartFactory.hh:64
TTAMachine::BaseRegisterFile::width
virtual int width() const
EditPartFactory::factories_
std::vector< Factory * > factories_
Registered factories.
Definition: EditPartFactory.hh:60