OpenASIP 2.2
Loading...
Searching...
No Matches
PortCode.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2014 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 PortCode.cc
26 *
27 * Implementation of PortCode class.
28 *
29 * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30 * @author Pekka Jääskeläinen 2014
31 * @note rating: red
32 */
33
34#include "PortCode.hh"
35#include "ObjectState.hh"
36#include "MathTools.hh"
37
38const std::string PortCode::OSNAME_PORT_CODE = "port_code";
39const std::string PortCode::OSKEY_UNIT_NAME = "unit_name";
40const std::string PortCode::OSKEY_ENCODING = "encoding";
41const std::string PortCode::OSKEY_EXTRA_BITS = "extra_bits";
42const std::string PortCode::OSKEY_INDEX_WIDTH = "index_width";
43const std::string PortCode::OSKEY_MAX_INDEX = "max-index";
44
45/**
46 * The constructor.
47 *
48 * Creates a port code with port ID.
49 *
50 * @param unitName Name of the unit.
51 * @param encoding The encoding.
52 * @param extraBits The number of extra bits in the encoding.
53 * @param indexWidth The width of the register index.
54 * @exception OutOfRange If the some of the given values is negative.
55 */
57 const std::string& unitName, unsigned int encoding,
58 unsigned int extraBits, int indexWidth)
59 : unitName_(unitName),
60 encoding_(encoding),
61 extraBits_(extraBits),
62 indexWidth_(indexWidth),
63 hasEncoding_(true),
64 parent_(NULL),
65 maxRegIndex_(0) {
66 if (indexWidth_ < 0) {
67 throw OutOfRange(__FILE__, __LINE__, __func__);
68 }
69}
70
71/**
72 * The constructor.
73 *
74 * Creates a port code without port ID.
75 *
76 * @param unitName Name of the unit.
77 * @param indexWidth The width of the register index.
78 * @exception OutOfRange If the some of the given values is negative.
79 */
80PortCode::PortCode(const std::string& unitName, int indexWidth)
81 : unitName_(unitName),
82 encoding_(0),
83 extraBits_(0),
84 indexWidth_(indexWidth),
85 hasEncoding_(false),
86 parent_(NULL),
87 maxRegIndex_(0) {
88 if (indexWidth_ < 0) {
89 throw OutOfRange(__FILE__, __LINE__, __func__);
90 }
91}
92
93/**
94 * The constructor.
95 *
96 * Loads the state of the object from the given ObjectState instance.
97 *
98 * @param state The ObjectState instance.
99 * @exception ObjectStateLoadingException If the given ObjectState instance
100 * is erroneous.
101 */
103 : unitName_(""),
104 encoding_(0),
105 extraBits_(0),
106 indexWidth_(0),
107 hasEncoding_(false),
108 parent_(NULL),
109 maxRegIndex_(0) {
110 try {
112 if (state->hasAttribute(OSKEY_MAX_INDEX))
114 if (state->hasAttribute(OSKEY_ENCODING)) {
117 hasEncoding_ = true;
118 }
119 if (state->hasAttribute(OSKEY_INDEX_WIDTH)) {
121 }
122 } catch (const Exception&) {
123 throw ObjectStateLoadingException(__FILE__, __LINE__, __func__);
124 }
125}
126
127/**
128 * The destructor.
129 */
132
133
134/**
135 * Returns the name of the unit.
136 *
137 * @return The name of the unit.
138 */
139std::string
141 return unitName_;
142}
143
144
145/**
146 * Tells whether the port code has an encoding (port ID).
147 *
148 * @return True if the port code has an encoding, otherwise false.
149 */
150bool
152 return hasEncoding_;
153}
154
155
156/**
157 * Returns the encoding.
158 *
159 * @return The encoding.
160 * @exception NotAvailable If the port code does not have an encoding
161 * (port ID).
162 */
163unsigned int
165 if (!hasEncoding()) {
166 throw NotAvailable(__FILE__, __LINE__, __func__);
167 }
168 return encoding_;
169}
170
171/**
172 * Returns the number of extra bits in the encoding.
173 *
174 * @return The number of extra bits.
175 */
176unsigned int
178 return extraBits_;
179}
180
181
182/**
183 * Returns the width of the whole port code (portID + opcode).
184 *
185 * @return The width.
186 */
187int
189 if (hasEncoding()) {
191 indexWidth();
192 } else {
193 return indexWidth();
194 }
195}
196
197
198/**
199 * Returns the width of the encoding (port ID).
200 *
201 * @return The width of the encoding.
202 */
203int
205 return width() - indexWidth();
206}
207
208
209/**
210 * Returns the width of the register index (opcode).
211 *
212 * @return The width of the register index.
213 */
214int
216 return indexWidth_;
217}
218
219
220/**
221 * Returns the parent socket code table.
222 *
223 * @return The parent socket code table.
224 */
227 return parent_;
228}
229
230
231/**
232 * Saves the state of the object to an ObjectState instance.
233 *
234 * @return The newly created ObjectState instance.
235 */
240 if (hasEncoding()) {
243 }
246 return state;
247}
248
249
250/**
251 * Sets the parent socket code table pointer.
252 *
253 * @param parent The parent pointer.
254 */
255void
#define __func__
find Finds info of the inner loops in the false
static unsigned int bitLength(long unsigned int number)
bool hasAttribute(const std::string &name) const
void setAttribute(const std::string &name, const std::string &value)
std::string stringAttribute(const std::string &name) const
int intAttribute(const std::string &name) const
virtual ObjectState * saveState() const
Definition PortCode.cc:237
static const std::string OSNAME_PORT_CODE
ObjectState name for PortCode.
Definition PortCode.hh:67
virtual ~PortCode()
Definition PortCode.cc:130
std::string unitName_
Name of the unit.
Definition PortCode.hh:89
unsigned int encoding_
The encoding.
Definition PortCode.hh:91
static const std::string OSKEY_INDEX_WIDTH
ObjectState attribute key for the widht of register index.
Definition PortCode.hh:75
static const std::string OSKEY_EXTRA_BITS
ObjectState attribute key for the number of extra bits.
Definition PortCode.hh:73
unsigned int extraBits_
The number of extra bits in the encoding.
Definition PortCode.hh:93
std::string unitName() const
Definition PortCode.cc:140
bool hasEncoding() const
Definition PortCode.cc:151
int indexWidth() const
Definition PortCode.cc:215
static const std::string OSKEY_ENCODING
ObjectState attribute key for the encoding.
Definition PortCode.hh:71
PortCode(const std::string &unitName, unsigned int encoding, unsigned int extraBits, int indexWidth)
Definition PortCode.cc:56
bool hasEncoding_
Tells whether the port code has an encoding.
Definition PortCode.hh:97
SocketCodeTable * parent() const
Definition PortCode.cc:226
int encodingWidth() const
Definition PortCode.cc:204
static const std::string OSKEY_UNIT_NAME
ObjectState attribute key for the name of the unit.
Definition PortCode.hh:69
unsigned int extraBits() const
Definition PortCode.cc:177
unsigned maxRegIndex_
In case this is set to non-zero, the whole width of the index field is not used because the number of...
Definition PortCode.hh:104
int width() const
Definition PortCode.cc:188
void setParent(SocketCodeTable *parent)
Definition PortCode.cc:256
SocketCodeTable * parent_
The parent socket code table.
Definition PortCode.hh:99
int indexWidth_
The width of the register index in the port code.
Definition PortCode.hh:95
static const std::string OSKEY_MAX_INDEX
ObjectState attribute key for the max-index attribute.
Definition PortCode.hh:77
unsigned int encoding() const
Definition PortCode.cc:164