OpenASIP 2.2
Loading...
Searching...
No Matches
BridgeEncoding.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 BridgeEncoding.cc
26 *
27 * Implementation of BridgeEncoding 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 "BridgeEncoding.hh"
36#include "SourceField.hh"
37#include "Application.hh"
38#include "ObjectState.hh"
39
40using std::string;
41
42const std::string BridgeEncoding::OSNAME_BRIDGE_ENCODING = "bridge_encoding";
43const std::string BridgeEncoding::OSKEY_BRIDGE_NAME = "bridge_name";
44
45
46/**
47 * The constructor.
48 *
49 * Creates an encoding for the given bridge and registers it into the given
50 * source field.
51 *
52 * @param name Name of the bridge.
53 * @param encoding The encoding.
54 * @param extraBits The number of extra (zero) bits in the encoding.
55 * @param parent The parent source field.
56 * @exception ObjectAlreadyExists If the parent source field has an encoding
57 * for this bridge already or if the encoding
58 * is ambiguous with some other encoding.
59 */
61 const std::string& name, unsigned int encoding, unsigned int extraBits,
62 SourceField& parent)
63 : Encoding(encoding, extraBits, NULL), bridge_(name) {
66}
67
68/**
69 * The constructor.
70 *
71 * Loads the state of the object from the given ObjectState instance.
72 *
73 * @param state The ObjectState instance.
74 * @param parent The parent source field.
75 * @exception ObjectStateLoadingException If an error occurs while loading
76 * the state.
77 * @exception ObjectAlreadyExists If the parent source field has an encoding
78 * for this bridge already or if the encoding
79 * is ambiguous with some other encoding.
80 */
82 : Encoding(state, NULL), bridge_("") {
83 const string procName = "BridgeEncoding::BridgeEncoding";
84
85 if (state->name() != OSNAME_BRIDGE_ENCODING) {
86 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
87 }
88
89 try {
91 } catch (const Exception& exception) {
93 __FILE__, __LINE__, procName, exception.errorMessage());
94 }
95
98}
99
100/**
101 * The destructor.
102 */
108
109
110/**
111 * Returns the parent source field.
112 *
113 * @return The parent source field.
114 */
118 if (parent != NULL) {
119 SourceField* sField = dynamic_cast<SourceField*>(parent);
120 assert(sField != NULL);
121 return sField;
122 } else {
123 return NULL;
124 }
125}
126
127
128/**
129 * Returns the name of the bridge.
130 *
131 * @return The name of the bridge.
132 */
133std::string
135 return bridge_;
136}
137
138
139/**
140 * Returns the position of the bridge encoding within the source field.
141 *
142 * @return The position.
143 */
144int
146 if (parent()->componentIDPosition() == BinaryEncoding::RIGHT) {
147 return 0;
148 } else {
149 return parent()->width() - parent()->extraBits() - width();
150 }
151}
152
153
154/**
155 * Saves the state of the object to an ObjectState instance.
156 *
157 * @return The newly created ObjectState instance.
158 */
164 return state;
165}
#define assert(condition)
static const std::string OSNAME_BRIDGE_ENCODING
ObjectState name for bridge encoding.
virtual int bitPosition() const
virtual ~BridgeEncoding()
std::string bridge_
Name of the bridge.
std::string bridgeName() const
SourceField * parent() const
static const std::string OSKEY_BRIDGE_NAME
ObjectState attribute key for the name of the bridge.
BridgeEncoding(const std::string &name, unsigned int encoding, unsigned int extraBits, SourceField &parent)
virtual ObjectState * saveState() const
virtual ObjectState * saveState() const
Definition Encoding.cc:141
InstructionField * parent() const
Definition Encoding.cc:97
virtual int width() const
Definition Encoding.cc:130
void setParent(InstructionField *parent)
Definition Encoding.cc:155
std::string errorMessage() const
Definition Exception.cc:123
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
void addBridgeEncoding(BridgeEncoding &encoding)
virtual int width() const
void removeBridgeEncoding(BridgeEncoding &encoding)