OpenASIP 2.2
Loading...
Searching...
No Matches
LImmDstRegisterField.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 LImmDstRegisterField.cc
26 *
27 * Implementation of LImmDstRegisterField class.
28 *
29 * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34
36#include "BinaryEncoding.hh"
37#include "MapTools.hh"
38#include "Application.hh"
39#include "ObjectState.hh"
40
41using std::string;
42
44 "dst_reg_field";
45const std::string LImmDstRegisterField::OSKEY_WIDTH = "width";
46const std::string LImmDstRegisterField::OSNAME_IU_DESTINATION = "iu_dst";
47const std::string LImmDstRegisterField::OSKEY_ITEMP = "itemp";
48const std::string LImmDstRegisterField::OSKEY_DST_IU = "iu";
49
50/**
51 * The constructor.
52 *
53 * Registers the field automatically to the given parent.
54 *
55 * @param width Width of the field.
56 * @param parent The parent BinaryEncoding instance.
57 * @exception OutOfRange If the given width is 0 or smaller.
58 */
60 : InstructionField(&parent), width_(width) {
61 if (width < 1) {
62 throw OutOfRange(__FILE__, __LINE__, __func__);
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 * Registers the field automatically to the given parent.
75 *
76 * @param state The ObjectState instance.
77 * @param parent The parent BinaryEncoding instance.
78 * @exception ObjectStateLoadingException If the given ObjectState instance
79 * is erroneous.
80 */
82 const ObjectState* state, BinaryEncoding& parent)
83 : InstructionField(state, &parent), width_(0) {
84 loadState(state);
85 setParent(NULL);
88}
89
90/**
91 * The destructor.
92 */
98
99
100/**
101 * Returns the parent BinaryEncoding instance.
102 *
103 * @return The parent BinaryEncoding instance.
104 */
108 if (parent != NULL) {
109 BinaryEncoding* bem = dynamic_cast<BinaryEncoding*>(parent);
110 assert(bem != NULL);
111 return bem;
112 } else {
113 return NULL;
114 }
115}
116
117
118/**
119 * Sets that the register index of the given immediate unit in the given
120 * instruction template is given in this field.
121 *
122 * @param instructionTemplate The instruction template.
123 * @param immediateUnit The immediate unit.
124 * @exception NotAvailable If index of some other immediate unit is assigned
125 * to this field in the same instruction template.
126 *
127 */
128void
130 const std::string& instructionTemplate, const std::string& immediateUnit) {
133 != immediateUnit) {
134 throw NotAvailable(__FILE__, __LINE__, __func__);
135 } else {
136 destinationMap_.insert(
137 std::pair<string, string>(instructionTemplate, immediateUnit));
138 }
139}
140
141/**
142 * Returns the number of instruction templates that use this destination
143 * register field.
144 *
145 * @return The number of instruction templates.
146 */
147int
151
152
153/**
154 * By the given index, returns an instruction template that uses this
155 * destination register field.
156 *
157 * @param index The index.
158 * @exception OutOfRange If the index is negative or not smaller than the
159 * number of instruction templates.
160 */
161std::string
163 if (index < 0 || index >= instructionTemplateCount()) {
164 throw OutOfRange(__FILE__, __LINE__, __func__);
165 }
166
167 StringMap::const_iterator iter = destinationMap_.begin();
168 for (int i = 0; i < index; i++) {
169 iter++;
170 }
171
172 return iter->first;
173}
174
175/**
176 * Tells whether the field is used by the given instruction template.
177 *
178 * @param instructionTemplate The instruction template.
179 */
180bool
182 const std::string& instructionTemplate) const {
183
185}
186
187
188/**
189 * Returns the name of the immediate unit for which the field is assigned
190 * in the given instruction template.
191 *
192 * @param instructionTemplate Name of the instruction template.
193 * @exception NotAvailable If the field is not used in the given instruction
194 * template.
195 */
196std::string
198 const std::string& instructionTemplate) const {
199 try {
202 } catch (const Exception&) {
203 throw NotAvailable(__FILE__, __LINE__, __func__);
204 }
205}
206
207/**
208 * Returns the width of the field.
209 *
210 * @return The bit width of the field.
211 */
212int
214 return width_;
215}
216
217
218/**
219 * Returns the number of child fields, that is always 0.
220 *
221 * @return 0.
222 */
223int
225 return 0;
226}
227
228
229/**
230 * Saves the state of the object to an ObjectState instance.
231 *
232 * @return The newly created ObjectState instance.
233 */
236
239 state->setAttribute(OSKEY_WIDTH, width());
240
241 // add destinations
242 for (StringMap::const_iterator iter = destinationMap_.begin();
243 iter != destinationMap_.end(); iter++) {
245 state->addChild(dstState);
246 dstState->setAttribute(OSKEY_ITEMP, iter->first);
247 dstState->setAttribute(OSKEY_DST_IU, iter->second);
248 }
249
250 return state;
251}
252
253
254/**
255 * Loads the state of the object from the given ObjectState instance.
256 *
257 * @param state The ObjectState instance.
258 */
259void
261 if (state->name() != OSNAME_LIMM_DST_REGISTER_FIELD) {
262 throw ObjectStateLoadingException(__FILE__, __LINE__, __func__);
263 }
264
266
267 try {
269 for (int i = 0; i < state->childCount(); i++) {
270 ObjectState* child = state->child(i);
271 if (child->name() != OSNAME_IU_DESTINATION) {
273 __FILE__, __LINE__, __func__);
274 }
275 string iTemp = child->stringAttribute(OSKEY_ITEMP);
276 string iu = child->stringAttribute(OSKEY_DST_IU);
277 addDestination(iTemp, iu);
278 }
279 } catch (const Exception& e) {
281 __FILE__, __LINE__, __func__, e.errorMessage());
282 }
283}
#define __func__
#define assert(condition)
void addLongImmDstRegisterField(LImmDstRegisterField &field)
void removeLongImmDstRegisterField(LImmDstRegisterField &field)
std::string errorMessage() const
Definition Exception.cc:123
InstructionField * parent() const
virtual void loadState(const ObjectState *state)
void setParent(InstructionField *parent)
virtual ObjectState * saveState() const
BinaryEncoding * parent() const
std::string instructionTemplate(int index) const
void loadState(const ObjectState *state)
bool usedByInstructionTemplate(const std::string &instructionTemplate) const
StringMap destinationMap_
Maps instruction templates to immediate units.
int width_
Width of the field.
virtual int width() const
static const std::string OSKEY_ITEMP
ObjectState attribute key for the name of the instruction template.
static const std::string OSKEY_DST_IU
ObjectState attribute key for the name of the immediate unit.
static const std::string OSNAME_LIMM_DST_REGISTER_FIELD
ObjectState name for long immediate destination register field.
virtual ObjectState * saveState() const
virtual int childFieldCount() const
static const std::string OSKEY_WIDTH
ObjectState attribute key for the width of the field.
LImmDstRegisterField(int width, BinaryEncoding &parent)
static const std::string OSNAME_IU_DESTINATION
ObjectState name for a immediate unit destination.
void addDestination(const std::string &instructionTemplate, const std::string &immediateUnit)
std::string immediateUnit(const std::string &instructionTemplate) const
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)
static bool containsKey(const MapType &aMap, const KeyType &aKey)
void setName(const std::string &name)
void setAttribute(const std::string &name, const std::string &value)
ObjectState * child(int index) const
void addChild(ObjectState *child)
std::string stringAttribute(const std::string &name) const
int intAttribute(const std::string &name) const
std::string name() const
int childCount() const