OpenASIP  2.0
InstructionElement.icc
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 InstructionElement.icc
26  *
27  * Inline definitions of InstructionElement and InstructionAnnotation classes.
28  *
29  * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30  *
31  * @note rating: yellow
32  */
33 
34 //////////////////////////////////////////////////////////////////////////////
35 // InstructionAnnotation definition.
36 //////////////////////////////////////////////////////////////////////////////
37 
38 namespace TPEF {
39 
40 /**
41  * Returns the code that identifies this annotation.
42  *
43  * This numeric code is used by applications to recognize annotations that
44  * are ment for it.
45  *
46  * @return Unique identification code.
47  */
48 inline Word
49 InstructionAnnotation::id() const {
50  assert (id_ < 0xFFFFFF); // only 16 million id's
51  return id_;
52 }
53 
54 /**
55  * Gets requested byte of data from annotation.
56  *
57  * @param index Index of requested byte.
58  * @return Value of requested index.
59  */
60 inline Byte
61 InstructionAnnotation::byte(Byte index) const {
62  assert(index < size());
63  return payLoad_[index];
64 }
65 
66 /**
67  * Returns a const reference to the payload byte bector.
68  *
69  * @returns A const reference to the payload byte vector.
70  */
71 inline const std::vector<Byte>&
72 InstructionAnnotation::payload() const {
73  return payLoad_;
74 }
75 
76 /**
77  * Adds a byte to annotation.
78  *
79  * @praram aByte Byte to add.
80  */
81 inline void
82 InstructionAnnotation::addByte(Byte aByte) {
83  assert(size() <= MAX_ANNOTATION_BYTES);
84  payLoad_.push_back(aByte);
85 }
86 
87 /**
88  * Returns size of data.
89  *
90  * @return Size of data.
91  */
92 inline Byte
93 InstructionAnnotation::size() const {
94  return payLoad_.size();
95 }
96 
97 
98 //////////////////////////////////////////////////////////////////////////////
99 // InstructionElement definition.
100 //////////////////////////////////////////////////////////////////////////////
101 
102 /**
103  * Returns true, if instruction element is the first element of instruction.
104  *
105  * @return True if instruction element is the first element of instruction.
106  */
107 inline bool
108 InstructionElement::begin() const {
109  return begin_;
110 }
111 
112 /**
113  * Sets beginning status of instruction element.
114  *
115  * @param isBegin Value that is set to beginning status.
116  */
117 inline void
118 InstructionElement::setBegin(bool isBegin) {
119  begin_ = isBegin;
120 }
121 
122 /**
123  * Returns true, if instruction element is move.
124  *
125  * @return True, if instruction element is move.
126  */
127 inline bool
128 InstructionElement::isMove() const {
129  return isMove_;
130 }
131 
132 /**
133  * Returns true, if instruction element is immediate.
134  *
135  * @return True, if instruction element is immediate.
136  */
137 inline bool
138 InstructionElement::isImmediate() const {
139  return !isMove_;
140 }
141 
142 /**
143  * Returns requested annotation.
144  *
145  * Returned reference to annotation may be edited.
146  *
147  * @param index Index of annotation to return.
148  * @return Pointer to requested annotation.
149  */
150 inline InstructionAnnotation*
151 InstructionElement::annotation(Word index) const {
152  assert(index < annotationCount());
153  return annotations_[index];
154 }
155 
156 
157 /**
158  * Adds an annotation to instruction.
159  *
160  * @param anAnnotation Annotation to add.
161  */
162 inline void
163 InstructionElement::addAnnotation(InstructionAnnotation *anAnnotation) {
164  annotations_.push_back(anAnnotation);
165 }
166 
167 /**
168  * Returns number of annotations that are stored to instruction element.
169  *
170  * @return Number of annotations.
171  */
172 inline Word
173 InstructionElement::annotationCount() const {
174  return annotations_.size();
175 }
176 
177 }