OpenASIP 2.2
Loading...
Searching...
No Matches
ImmediateSlotField.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 ImmediateSlotField.cc
26 *
27 * Implementation of ImmediateSlotField 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 "Application.hh"
36#include "ImmediateSlotField.hh"
37#include "BinaryEncoding.hh"
38#include "ObjectState.hh"
39
40using std::string;
41
43 "imm_slot_field";
44const std::string ImmediateSlotField::OSKEY_NAME = "name";
45const std::string ImmediateSlotField::OSKEY_WIDTH = "width";
46
47/**
48 * The constructor.
49 *
50 * @param name Name of the immediate slot programmed by this field.
51 * @param width Bit width of the field.
52 * @parent The parent binary encoding map.
53 * @exception OutOfRange If the bit width is smaller than 1.
54 * @exception ObjectAlreadyExists If the parent binary encoding already has
55 * an immediate slot with the given name.
56 */
58 const std::string& name, int width, BinaryEncoding& parent)
59 : InstructionField(&parent), name_(name), width_(width) {
60 if (width < 1) {
61 const string procName = "ImmediateSlotField::ImmediateSlotField";
62 throw OutOfRange(__FILE__, __LINE__, procName);
63 }
64
65 setParent(NULL);
68}
69
70/**
71 * The constructor.
72 *
73 * Loads the state of the object from the given ObjectState instance.
74 *
75 * @param state The ObjectState instance.
76 * @exception ObjectStateLoadingException If an error occurs while loading
77 * the state.
78 */
80 const ObjectState* state, BinaryEncoding& parent)
81 : InstructionField(state, &parent), name_(""), width_(0) {
82 loadState(state);
83 setParent(NULL);
86}
87
88/**
89 * The destructor.
90 */
92 BinaryEncoding* parent = this->parent();
93 assert(parent != NULL);
94 setParent(NULL);
96}
97
98
99/**
100 * Returns the parent binary encoding map.
101 *
102 * @return The parent binary encoding map.
103 */
107 if (parent == NULL) {
108 return NULL;
109 } else {
110 BinaryEncoding* bemParent = dynamic_cast<BinaryEncoding*>(parent);
111 assert(bemParent != NULL);
112 return bemParent;
113 }
114}
115
116
117/**
118 * Returns the name of the immediate slot programmed by this field.
119 *
120 * @return The name of the immediate slot.
121 */
122std::string
124 return name_;
125}
126
127
128/**
129 * Sets the name of the immediate slot programmed by this field.
130 *
131 * @param name The name.
132 * @exception ObjectAlreadyExists If the parent binary encoding has an
133 * immediate slot field for the given
134 * immediate slot already.
135 */
136void
137ImmediateSlotField::setName(const std::string& name) {
138 if (name == this->name()) {
139 return;
140 }
141
142 if (parent()->hasImmediateSlot(name)) {
143 const string procName = "ImmediateSlotField::setName";
144 throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
145 } else {
146 name_ = name;
147 }
148}
149
150/**
151 * Returns 0 always since immediate slot does not have any child fields.
152 *
153 * @return 0.
154 */
155int
157 return 0;
158}
159
160
161/**
162 * Returns the bit width of the field.
163 *
164 * @return The bit width.
165 */
166int
168 return width_;
169}
170
171
172/**
173 * Sets the bit width of the field.
174 *
175 * @param width The new bit width.
176 * @exception OutOfRange If the given width is smaller than 1.
177 */
178void
180 if (width < 1) {
181 const string procName = "ImmediateSlotField::setWidth";
182 throw OutOfRange(__FILE__, __LINE__, procName);
183 }
184 width_ = width;
185}
186
187/**
188 * Saves the state of the object to an ObjectState instance.
189 *
190 * @return The newly created ObjectState instance.
191 */
200
201
202/**
203 * Loads the state of the object from the given ObjectState instance.
204 *
205 * @param state The ObjectState instance.
206 * @exception ObjectStateLoadingException If an error occurs while loading
207 * the state.
208 */
209void
211 const string procName = "ImmediateSlotField::loadState";
212
213 if (state->name() != OSNAME_IMMEDIATE_SLOT_FIELD) {
214 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
215 }
216
218
219 try {
222 } catch (const Exception&) {
223 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
224 }
225}
#define assert(condition)
void addImmediateSlot(ImmediateSlotField &slot)
void removeImmediateSlot(ImmediateSlotField &slot)
virtual ObjectState * saveState() const
virtual int width() const
std::string name() const
int width_
The bit width of the field.
static const std::string OSNAME_IMMEDIATE_SLOT_FIELD
ObjectState name for immediate slot field.
static const std::string OSKEY_NAME
ObjectState attribute key for the name of the immediate slot.
std::string name_
Name of the immediate slot.
static const std::string OSKEY_WIDTH
ObjectState attribute key for the width of the field.
virtual int childFieldCount() const
ImmediateSlotField(const std::string &name, int width, BinaryEncoding &parent)
BinaryEncoding * parent() const
void setName(const std::string &name)
virtual void loadState(const ObjectState *state)
InstructionField * parent() const
virtual void loadState(const ObjectState *state)
void setParent(InstructionField *parent)
virtual ObjectState * saveState() 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
int intAttribute(const std::string &name) const
std::string name() const