OpenASIP  2.0
NOPEncoding.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 NOPEncoding.cc
26  *
27  * Implementation of NOPEncoding class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include "NOPEncoding.hh"
34 #include "SourceField.hh"
35 #include "Application.hh"
36 #include "ObjectState.hh"
37 
38 using std::string;
39 
40 const std::string NOPEncoding::OSNAME_NOP_ENCODING = "nop_encoding";
41 
42 /**
43  * The constructor.
44  *
45  * Registers the encoding automatically to the parent src/dst field.
46  *
47  * @param encoding The encoding for inline immediates.
48  * @param extraBits The number of extra bits in the encoding.
49  * @param parent The parent src/dst field.
50  * @exception ObjectAlreadyExists If the given parent field has a NOP
51  * encoding already or if the encoding is
52  * ambiguous with some other encoding in the
53  * parent field.
54  */
56  unsigned int encoding, unsigned int extraBits, SlotField& parent)
57  : Encoding(encoding, extraBits, NULL) {
59  setParent(&parent);
60 }
61 
62 /**
63  * The constructor.
64  *
65  * Loads the state of the object from the given ObjectState instance.
66  *
67  * @param state The ObjectState instance.
68  * @param parent The parent field.
69  * @exception ObjectAlreadyExists If the given parent field has a NOP
70  * encoding already or if the encoding is
71  * ambiguous with some other
72  * encoding in the parent field.
73  * @exception ObjectStateLoadingException If the given ObjectState instance
74  * is erroneous.
75  */
77  : Encoding(state, NULL) {
78  const string procName = "NOPEncoding::NOPEncoding";
79 
80  if (state->name() != OSNAME_NOP_ENCODING) {
81  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
82  }
83 
85  setParent(&parent);
86 }
87 
88 /**
89  * The destructor.
90  */
92  SlotField* oldParent = parent();
93  assert(oldParent != NULL);
94  setParent(NULL);
95  oldParent->unsetNoOperationEncoding();
96 }
97 
98 
99 /**
100  * Returns the parent source field.
101  *
102  * @return The parent.
103  */
104 SlotField*
107  if (parent != NULL) {
108  SlotField* sField = dynamic_cast<SlotField*>(parent);
109  assert(sField != NULL);
110  return sField;
111  } else {
112  return NULL;
113  }
114 }
115 
116 
117 /**
118  * Returns the position of the encoding within the source field.
119  *
120  * @return The position of the encoding.
121  */
122 int
124  if (parent()->componentIDPosition() == BinaryEncoding::LEFT) {
125  return parent()->width() - parent()->extraBits() - width();
126  } else {
127  return 0;
128  }
129 }
130 
131 
132 /**
133  * Saves the state of the object to an ObjectState instance.
134  *
135  * @return The newly created ObjectState instance.
136  */
139  ObjectState* state = Encoding::saveState();
141  return state;
142 }
NOPEncoding::NOPEncoding
NOPEncoding(unsigned int encoding, unsigned int extraBits, SlotField &parent)
Definition: NOPEncoding.cc:55
NOPEncoding::saveState
virtual ObjectState * saveState() const
Definition: NOPEncoding.cc:138
ObjectStateLoadingException
Definition: Exception.hh:551
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)
InstructionField
Definition: InstructionField.hh:43
NOPEncoding::~NOPEncoding
virtual ~NOPEncoding()
Definition: NOPEncoding.cc:91
Encoding
Definition: Encoding.hh:46
SlotField::setNoOperationEncoding
void setNoOperationEncoding(NOPEncoding &encoding)
Definition: SlotField.cc:234
assert
#define assert(condition)
Definition: Application.hh:86
NOPEncoding::parent
SlotField * parent() const
Definition: NOPEncoding.cc:105
Encoding::width
virtual int width() const
Definition: Encoding.cc:130
Application.hh
BinaryEncoding::LEFT
@ LEFT
Definition: BinaryEncoding.hh:64
ObjectState.hh
SlotField::width
virtual int width() const
Definition: SlotField.cc:307
NOPEncoding.hh
SlotField::unsetNoOperationEncoding
void unsetNoOperationEncoding()
Definition: SlotField.cc:253
ObjectState::name
std::string name() const
Encoding::saveState
virtual ObjectState * saveState() const
Definition: Encoding.cc:141
InstructionField::extraBits
int extraBits() const
Definition: InstructionField.cc:229
SlotField
Definition: SlotField.hh:58
NOPEncoding::OSNAME_NOP_ENCODING
static const std::string OSNAME_NOP_ENCODING
ObjectState name for NOP encoding.
Definition: NOPEncoding.hh:57
NOPEncoding::bitPosition
virtual int bitPosition() const
Definition: NOPEncoding.cc:123