OpenASIP 2.2
Loading...
Searching...
No Matches
AnnotatedInstructionElement.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 AnnotatedInstructionElement.cc
26 *
27 * Implementation of AnnotatedInstructionElement class.
28 *
29 * @author Pekka Jääskeläinen 2006 (pekka.jaaskelainen-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <utility> // std::pair
34
36#include "MapTools.hh"
37#include "TCEString.hh"
38
39namespace TTAProgram {
40
41/////////////////////////////////////////////////////////////////////////////
42// AnnotatedInstructionElement
43/////////////////////////////////////////////////////////////////////////////
44
45/**
46 * Constructor.
47 */
50
51/**
52 * Destructor.
53 */
56
57/**
58 * Adds an annotation to the instruction element.
59 *
60 * @param annotation The annotation to add.
61 */
62void
64 const ProgramAnnotation& annotation) {
65 annotations_.insert(
66 std::pair<ProgramAnnotation::Id, ProgramAnnotation>(
68}
69
70/**
71 * Sets an annotation to the instruction element as the sole annotation of
72 * that type.
73 *
74 * Removes all annotations with the same type before adding the annotation.
75 *
76 * @param annotation The annotation to set.
77 */
78void
80 const ProgramAnnotation& annotation) {
81
82 // hmm.. does multimap::erase(key) remove *all* elements with the given
83 // key, or just first found?
84 // multimap::erase(key) returns the number of elements removed as
85 // size_type, so it erases all matching elements
86 annotations_.erase(annotation.id());
87 annotations_.insert(
88 std::pair<ProgramAnnotation::Id, ProgramAnnotation>(
90}
91
92/**
93 * Returns the annotation at the given index (and id).
94 *
95 * @param index The index of the annotation.
96 * @param id The id of the annotation (optional).
97 * @exception OutOfRange If the index is out of range.
98 */
101 int index, ProgramAnnotation::Id id) const {
102 std::pair<AnnotationIndex::const_iterator,
103 AnnotationIndex::const_iterator> range(
104 annotations_.end(), annotations_.end());
105
107 // set the iterators to point to the set of elements with the given id
108 range = annotations_.equal_range(id);
109 else
110 // go through all elements
111 range = std::make_pair(annotations_.begin(), annotations_.end());
112
113 AnnotationIndex::const_iterator i = range.first;
114 for (int counter = 0; counter < index; ++counter) {
115 ++i;
116 if (i == annotations_.end())
117 break;
118 }
119
120 if (i == annotations_.end())
121 throw OutOfRange(__FILE__, __LINE__, __func__);
122
123 return (*i).second;
124}
125
126/**
127 * Returns the count of annotations (with the given id).
128 *
129 * @param id The id of the annotations to count (optional).
130 * @return The count of annotations (with the given id).
131 */
132int
135 return static_cast<int>(annotations_.count(id));
136 else
137 return static_cast<int>(annotations_.size());
138}
139
140/**
141 * Removes all annotations (with the given id).
142 *
143 * @param id The id of the annotations to remove (optional).
144 */
145void
147
149 annotations_.clear();
150 }
151 AnnotationIndex::iterator i = annotations_.find(id);
152 while (i != annotations_.end()) {
153 annotations_.erase(i);
154 i = annotations_.find(id);
155 }
156}
157
158/**
159 * Returns true in case there's at least one annotation with the given id.
160 *
161 * @param id An annotation id.
162 * @return True in case there's at least one annotation with the given id.
163 */
164bool
168
169/**
170 * Returns true in case there's at least one annotation with the given id
171 * and the given data.
172 */
173bool
175 ProgramAnnotation::Id id, const TCEString& data) const {
176
177 auto range = annotations_.equal_range(id);
178 for (auto i = range.first; i != range.second; i++) {
179 if (i->second.stringValue() == data) {
180 return true;
181 }
182 }
183 return false;
184}
185
186
187/**
188 * Copies annotations from another annotated element.
189 *
190 * Possible old annotations are deleted.
191 */
192void
197
198} // namespace TTAProgram
#define __func__
void removeAnnotations(ProgramAnnotation::Id id=ProgramAnnotation::ANN_UNDEF_ID)
void copyAnnotationsFrom(const AnnotatedInstructionElement &other)
int annotationCount(ProgramAnnotation::Id id=ProgramAnnotation::ANN_UNDEF_ID) const
void setAnnotation(const ProgramAnnotation &annotation)
bool hasAnnotation(ProgramAnnotation::Id id, const TCEString &data) const
ProgramAnnotation annotation(int index, ProgramAnnotation::Id id=ProgramAnnotation::ANN_UNDEF_ID) const
AnnotationIndex annotations_
container for annotations
void addAnnotation(const ProgramAnnotation &annotation)
bool hasAnnotations(ProgramAnnotation::Id id=ProgramAnnotation::ANN_UNDEF_ID) const
ProgramAnnotation::Id id() const
Id
the ID in TPEF is 24 bits, here enum
@ ANN_UNDEF_ID
an illegal annotation ID (the id is only 24 bits, this has more meaningful bits)