OpenASIP  2.0
FUPortCode.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 FUPortCode.cc
26  *
27  * Implementation of FUPortCode class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include "FUPortCode.hh"
34 #include "SocketCodeTable.hh"
35 #include "MathTools.hh"
36 #include "ObjectState.hh"
37 
38 using std::string;
39 
40 const std::string FUPortCode::OSNAME_FU_PORT_CODE = "fu_port_code";
41 const std::string FUPortCode::OSKEY_PORT_NAME = "port";
42 const std::string FUPortCode::OSKEY_OPERATION_NAME = "operation";
43 
44 /**
45  * The constructor.
46  *
47  * Creates an encoding for a FU port and registers it into a socket code
48  * table. The port is identified by a name string and by the name of its
49  * function unit.
50  *
51  * @param fu Name of the function unit.
52  * @param port Name of the port.
53  * @param encoding The encoding.
54  * @param extraBits The number of extra (zero) bits in the encoding.
55  * @param parent The parent socket code table.
56  * @exception ObjectAlreadyExists If the given socket code table already has
57  * a code for the same port or if the encoding
58  * is ambiguous with another encoding in the
59  * same socket code table.
60  * @exception OutOfRange If some of the given values is out of range.
61  */
63  const std::string& fu, const std::string& port, unsigned int encoding,
64  unsigned int extraBits, SocketCodeTable& parent)
65  : PortCode(fu, encoding, extraBits, 0), port_(port), opName_("") {
66  parent.addFUPortCode(*this);
67  setParent(&parent);
68 }
69 
70 /**
71  * The constructor.
72  *
73  * Creates an encoding for a FU port and registers it into a socket code
74  * table. The port is identified by a name string, the operation carried by
75  * it and the name of the parent function unit.
76  *
77  * @param fu Name of the function unit.
78  * @param port Name of the port.
79  * @param operation Name of the operation carried by the port.
80  * @param encoding The encoding for the port + operation.
81  * @param extraBits The number of extra zero bits in the encoding.
82  * @param parent The parent socket code table.
83  * @exception ObjectAlreadyExists If the given socket code table already has
84  * a code for this port and the operation
85  * carried or if the encoding is ambiguous
86  * with another encoding in the same socket
87  * code table.
88  * @exception OutOfRange If some of the given values is out of range.
89  */
91  const std::string& fu, const std::string& port,
92  const std::string& operation, unsigned int encoding, unsigned int extraBits,
93  SocketCodeTable& parent)
94  : PortCode(fu, encoding, extraBits, 0), port_(port), opName_(operation) {
95  parent.addFUPortCode(*this);
96  setParent(&parent);
97 }
98 
99 /**
100  * The constructor.
101  *
102  * Loads the state of the object from the given ObjectState tree.
103  *
104  * @param state The ObjectState tree.
105  * @param parent The parent socket code table.
106  * @exception ObjectStateLoadingException If an error occurs while loading
107  * the state.
108  * @exception ObjectAlreadyExists If the given socket code table already has
109  * a code for this port and the operation
110  * carried or if the encoding is ambiguous
111  * with another encoding in the same socket
112  * code table.
113  */
115  : PortCode(state), port_(""), opName_("") {
116  const string procName = "FUPortCode::FUPortCode";
117 
118  if (state->name() != OSNAME_FU_PORT_CODE) {
119  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
120  }
121 
122  if (state->hasAttribute(OSKEY_OPERATION_NAME)) {
124  }
126 
127  parent.addFUPortCode(*this);
128  setParent(&parent);
129 }
130 
131 /**
132  * The destructor.
133  */
135  SocketCodeTable* parent = this->parent();
136  setParent(NULL);
137  parent->removeFUPortCode(*this);
138 }
139 
140 
141 /**
142  * Returns the name of the port.
143  *
144  * @return The name of the port.
145  */
146 std::string
148  return port_;
149 }
150 
151 
152 /**
153  * Returns the name of the operation.
154  *
155  * @return The name of the operation.
156  * @exception InstanceNotFound If this control code identifies a plain FU
157  * port without operation.
158  */
159 std::string
161  if (opName_ == "") {
162  const string procName = "FUPortCode::operationName";
163  throw InstanceNotFound(__FILE__, __LINE__, procName);
164  }
165 
166  return opName_;
167 }
168 
169 /**
170  * Tells whether this control code identifies also one of the operations
171  * carried by the FU port.
172  *
173  * @return True if the control code identifies an operation, otherwise false.
174  */
175 bool
177  return opName_ != "";
178 }
179 
180 
181 /**
182  * Saves the state of the object to an ObjectState tree.
183  *
184  * @return The newly created ObjectState tree.
185  */
188  ObjectState* state = PortCode::saveState();
191  if (hasOperation()) {
193  }
194  return state;
195 }
ObjectState::hasAttribute
bool hasAttribute(const std::string &name) const
Definition: ObjectState.cc:205
FUPortCode::operationName
std::string operationName() const
Definition: FUPortCode.cc:160
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
PortCode
Definition: PortCode.hh:45
ObjectStateLoadingException
Definition: Exception.hh:551
FUPortCode::FUPortCode
FUPortCode(const std::string &fu, const std::string &port, unsigned int encoding, unsigned int extraBits, SocketCodeTable &parent)
Definition: FUPortCode.cc:62
SocketCodeTable.hh
ObjectState
Definition: ObjectState.hh:59
FUPortCode::OSNAME_FU_PORT_CODE
static const std::string OSNAME_FU_PORT_CODE
ObjectState name for FU port code.
Definition: FUPortCode.hh:66
ObjectState::setName
void setName(const std::string &name)
SocketCodeTable
Definition: SocketCodeTable.hh:68
FUPortCode::OSKEY_OPERATION_NAME
static const std::string OSKEY_OPERATION_NAME
ObjectState attribute key for the name of the operation.
Definition: FUPortCode.hh:70
FUPortCode::port_
std::string port_
Name of the port.
Definition: FUPortCode.hh:74
FUPortCode::saveState
virtual ObjectState * saveState() const
Definition: FUPortCode.cc:187
ObjectState.hh
ObjectState::name
std::string name() const
PortCode::setParent
void setParent(SocketCodeTable *parent)
Definition: PortCode.cc:256
FUPortCode::opName_
std::string opName_
Name of the operation.
Definition: FUPortCode.hh:76
SocketCodeTable::addFUPortCode
void addFUPortCode(FUPortCode &code)
Definition: SocketCodeTable.cc:249
FUPortCode::hasOperation
bool hasOperation() const
Definition: FUPortCode.cc:176
FUPortCode::~FUPortCode
virtual ~FUPortCode()
Definition: FUPortCode.cc:134
PortCode::parent
SocketCodeTable * parent() const
Definition: PortCode.cc:226
MathTools.hh
FUPortCode.hh
FUPortCode::OSKEY_PORT_NAME
static const std::string OSKEY_PORT_NAME
ObjectState attribute key for the name of the port.
Definition: FUPortCode.hh:68
PortCode::saveState
virtual ObjectState * saveState() const
Definition: PortCode.cc:237
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
InstanceNotFound
Definition: Exception.hh:304
FUPortCode::portName
std::string portName() const
Definition: FUPortCode.cc:147
SocketCodeTable::removeFUPortCode
void removeFUPortCode(FUPortCode &code)
Definition: SocketCodeTable.cc:283