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