OpenASIP  2.0
BaseFUPort.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 BaseFUPort.cc
26  *
27  * Implementation of BaseFUPort class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 
35 #include "BaseFUPort.hh"
36 #include "FunctionUnit.hh"
37 #include "ObjectState.hh"
38 
39 using std::string;
40 
41 namespace TTAMachine {
42 
43 // initialisation of static data members
44 const string BaseFUPort::OSKEY_WIDTH = "width";
45 
46 /**
47  * The constructor.
48  *
49  * @param name Name of the port.
50  * @param width Bit width of the port.
51  * @param parent The function unit to which the port belongs.
52  * @exception InvalidName If the given name is not a valid component name.
53  * @exception ComponentAlreadyExists If the function unit already has another
54  * port by the same name or another port
55  * that sets operation code.
56  * @exception OutOfRange If the given bit width is less or equal to zero.
57  */
58 BaseFUPort::BaseFUPort(const std::string& name, int width, FunctionUnit& parent)
59  : Port(name, *static_cast<Unit*>(&parent)), width_(width) {
60  if (width <= 0) {
61  string procName = "BaseFUPort::BaseFUPort";
62  throw OutOfRange(__FILE__, __LINE__, procName);
63  }
64 }
65 
66 /**
67  * The constructor.
68  *
69  * Loads the state of the object from the given ObjectState tree.
70  *
71  * @param state The ObjectState tree.
72  * @param Unit The parent unit of the port.
73  * @exception ObjectStateLoadingException If an error occurs while loading
74  * the state.
75  */
76 BaseFUPort::BaseFUPort(const ObjectState* state, Unit& parent)
77  : Port(state, parent) {
79 }
80 
81 /**
82  * The destructor.
83  */
85 }
86 
87 
88 /**
89  * Returns the parent function unit of the port.
90  *
91  * Returns NULL in case not registered to a function unit.
92  *
93  * @return The parent function unit of the port.
94  */
98  FunctionUnit* fu = dynamic_cast<FunctionUnit*>(parentUnit);
99  return fu;
100 }
101 
102 
103 /**
104  * Returns the bit width of the port.
105  *
106  * @return Bit width of the port.
107  */
108 int
110  return width_;
111 }
112 
113 
114 /**
115  * Sets the bit width of the port.
116  *
117  * @param width The new bit width.
118  * @exception OutOfRange If the given bit width is less or equal to zero.
119  */
120 void
122  if (width <= 0) {
123  string procName = "FUPort::setWidth";
124  throw OutOfRange(__FILE__, __LINE__, procName);
125  }
126 
127  width_ = width;
128 }
129 
130 /**
131  * Saves the contents of the function unit port to an ObjectState object.
132  *
133  * @return The newly created ObjectState object.
134  */
137  ObjectState* fuPort = Port::saveState();
138  fuPort->setAttribute(OSKEY_WIDTH, width_);
139  return fuPort;
140 }
141 
142 
143 /**
144  * Loads the state of the function unit port from the given ObjectState
145  * instance.
146  *
147  * @param state The ObjectState instance.
148  * @exception ObjectStateLoadingException If the given ObjectState instance
149  * is invalid or if connections to
150  * socket cannot be made.
151  */
152 void
155  Port::loadState(state);
156 }
157 
158 /**
159  * Loads its state from the given ObjectState instance but does not create
160  * connections to sockets.
161  *
162  * @param state The ObjectState instance.
163  * @exception ObjectStateLoadingException If the given ObjectState instance
164  * is invalid.
165  */
166 void
168  const string procName = "BaseFUPort::loadStateWithoutReferences";
169 
170  try {
172  } catch (const Exception& e) {
174  __FILE__, __LINE__, procName, e.errorMessage());
175  }
176 }
177 }
TTAMachine::BaseFUPort::loadStateWithoutReferences
void loadStateWithoutReferences(const ObjectState *state)
Definition: BaseFUPort.cc:167
TTAMachine::BaseFUPort::width_
int width_
Bit width of the port.
Definition: BaseFUPort.hh:70
TTAMachine::BaseFUPort::BaseFUPort
BaseFUPort(const std::string &name, int width, FunctionUnit &parent)
Definition: BaseFUPort.cc:58
TTAMachine::Port::saveState
virtual ObjectState * saveState() const
Definition: Port.cc:404
ObjectStateLoadingException
Definition: Exception.hh:551
TTAMachine::BaseFUPort::parentUnit
FunctionUnit * parentUnit() const
Definition: BaseFUPort.cc:96
TTAMachine::BaseFUPort::~BaseFUPort
virtual ~BaseFUPort()
Definition: BaseFUPort.cc:84
OutOfRange
Definition: Exception.hh:320
ObjectState
Definition: ObjectState.hh:59
BaseFUPort.hh
TTAMachine::Port::loadState
virtual void loadState(const ObjectState *state)
Definition: Port.cc:459
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::BaseFUPort::loadState
virtual void loadState(const ObjectState *state)
Definition: BaseFUPort.cc:153
TTAMachine::Unit
Definition: Unit.hh:51
TTAMachine::Port
Definition: Port.hh:54
ObjectState.hh
TTAMachine::BaseFUPort::setWidth
void setWidth(int width)
Definition: BaseFUPort.cc:121
Exception
Definition: Exception.hh:54
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
TTAMachine::BaseFUPort::saveState
virtual ObjectState * saveState() const
Definition: BaseFUPort.cc:136
TTAMachine::BaseFUPort::OSKEY_WIDTH
static const std::string OSKEY_WIDTH
ObjectState attribute key for bit width of the port.
Definition: BaseFUPort.hh:60
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
TTAMachine
Definition: Assembler.hh:48
TTAMachine::BaseFUPort::width
virtual int width() const
Definition: BaseFUPort.cc:109
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
FunctionUnit.hh
TTAMachine::Port::parentUnit
Unit * parentUnit() const