OpenASIP 2.2
Loading...
Searching...
No Matches
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
38using std::string;
39
40const std::string FUPortCode::OSNAME_FU_PORT_CODE = "fu_port_code";
41const std::string FUPortCode::OSKEY_PORT_NAME = "port";
42const 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);
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);
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
124 }
126
127 parent.addFUPortCode(*this);
129}
130
131/**
132 * The destructor.
133 */
139
140
141/**
142 * Returns the name of the port.
143 *
144 * @return The name of the port.
145 */
146std::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 */
159std::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 */
175bool
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 */
191 if (hasOperation()) {
193 }
194 return state;
195}
static const std::string OSNAME_FU_PORT_CODE
ObjectState name for FU port code.
Definition FUPortCode.hh:66
std::string portName() const
static const std::string OSKEY_OPERATION_NAME
ObjectState attribute key for the name of the operation.
Definition FUPortCode.hh:70
FUPortCode(const std::string &fu, const std::string &port, unsigned int encoding, unsigned int extraBits, SocketCodeTable &parent)
Definition FUPortCode.cc:62
std::string opName_
Name of the operation.
Definition FUPortCode.hh:76
virtual ObjectState * saveState() const
virtual ~FUPortCode()
std::string operationName() const
bool hasOperation() const
static const std::string OSKEY_PORT_NAME
ObjectState attribute key for the name of the port.
Definition FUPortCode.hh:68
std::string port_
Name of the port.
Definition FUPortCode.hh:74
bool hasAttribute(const std::string &name) const
void setName(const std::string &name)
void setAttribute(const std::string &name, const std::string &value)
std::string stringAttribute(const std::string &name) const
std::string name() const
virtual ObjectState * saveState() const
Definition PortCode.cc:237
SocketCodeTable * parent() const
Definition PortCode.cc:226
void setParent(SocketCodeTable *parent)
Definition PortCode.cc:256
void addFUPortCode(FUPortCode &code)
void removeFUPortCode(FUPortCode &code)