OpenASIP  2.0
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 
40 using std::string;
41 
42 const std::string BridgeEncoding::OSNAME_BRIDGE_ENCODING = "bridge_encoding";
43 const 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) {
65  setParent(&parent);
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 
97  setParent(&parent);
98 }
99 
100 /**
101  * The destructor.
102  */
104  SourceField* parent = this->parent();
105  setParent(NULL);
107 }
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  */
133 std::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  */
144 int
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  */
161  ObjectState* state = Encoding::saveState();
164  return state;
165 }
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
ObjectStateLoadingException
Definition: Exception.hh:551
BridgeEncoding::parent
SourceField * parent() const
Definition: BridgeEncoding.cc:116
Encoding::setParent
void setParent(InstructionField *parent)
Definition: Encoding.cc:155
Encoding::parent
InstructionField * parent() const
Definition: Encoding.cc:97
ObjectState
Definition: ObjectState.hh:59
SourceField.hh
ObjectState::setName
void setName(const std::string &name)
BridgeEncoding::OSNAME_BRIDGE_ENCODING
static const std::string OSNAME_BRIDGE_ENCODING
ObjectState name for bridge encoding.
Definition: BridgeEncoding.hh:62
BridgeEncoding.hh
InstructionField
Definition: InstructionField.hh:43
Encoding
Definition: Encoding.hh:46
assert
#define assert(condition)
Definition: Application.hh:86
Encoding::width
virtual int width() const
Definition: Encoding.cc:130
BridgeEncoding::bridge_
std::string bridge_
Name of the bridge.
Definition: BridgeEncoding.hh:68
SourceField::removeBridgeEncoding
void removeBridgeEncoding(BridgeEncoding &encoding)
Definition: SourceField.cc:154
Application.hh
ObjectState.hh
BridgeEncoding::saveState
virtual ObjectState * saveState() const
Definition: BridgeEncoding.cc:160
SourceField::width
virtual int width() const
Definition: SourceField.cc:308
BridgeEncoding::bitPosition
virtual int bitPosition() const
Definition: BridgeEncoding.cc:145
BridgeEncoding::bridgeName
std::string bridgeName() const
Definition: BridgeEncoding.cc:134
Exception
Definition: Exception.hh:54
ObjectState::name
std::string name() const
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
BridgeEncoding::OSKEY_BRIDGE_NAME
static const std::string OSKEY_BRIDGE_NAME
ObjectState attribute key for the name of the bridge.
Definition: BridgeEncoding.hh:64
Encoding::saveState
virtual ObjectState * saveState() const
Definition: Encoding.cc:141
InstructionField::extraBits
int extraBits() const
Definition: InstructionField.cc:229
BinaryEncoding::RIGHT
@ RIGHT
Definition: BinaryEncoding.hh:65
BridgeEncoding::~BridgeEncoding
virtual ~BridgeEncoding()
Definition: BridgeEncoding.cc:103
BridgeEncoding::BridgeEncoding
BridgeEncoding(const std::string &name, unsigned int encoding, unsigned int extraBits, SourceField &parent)
Definition: BridgeEncoding.cc:60
SourceField::addBridgeEncoding
void addBridgeEncoding(BridgeEncoding &encoding)
Definition: SourceField.cc:130
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
SourceField
Definition: SourceField.hh:48