OpenASIP 2.2
Loading...
Searching...
No Matches
ResourceVectorSet.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 ResourceVectorSet.cc
26 *
27 * Definition of ResourceVectorSet class.
28 *
29 * @author Pekka J��skel�inen 2006 (pekka.jaaskelainen-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <algorithm>
34
35#include "ResourceVectorSet.hh"
36#include "Application.hh"
37#include "ExecutionPipeline.hh"
38#include "PipelineElement.hh"
39#include "HWOperation.hh"
40#include "StringTools.hh"
41#include "AssocTools.hh"
42#include "FunctionUnit.hh"
43
44namespace TTAMachine {
45
46/**
47 * Builds the resource vectors for the given FU.
48 *
49 * Resource vectors are built for all operations in the FU.
50 *
51 * @param functionUnit The function unit to build the resource vectors for.
52 * @exception InvalidData In case the function unit is incomplete to build
53 * resource vectors for (e.g., missing operand-port bindings).
54 */
56 const TTAMachine::FunctionUnit& functionUnit)
57 : width_(0) {
58 try {
59 // add the port usages of each operation and resource usages
60 for (int i = 0; i < functionUnit.operationCount(); ++i) {
61 const TTAMachine::HWOperation* op = functionUnit.operation(i);
62 ResourceVector* rv =
63 new ResourceVector(*op->pipeline());
65 width_ = std::max(width_, rv->width());
66 }
67 } catch (const Exception& e) {
68 InvalidData io(
69 __FILE__, __LINE__, __func__,
70 "Error building the resource vectors");
71 io.setCause(e);
72 throw io;
73 }
74}
75
76/**
77 * Destructor.
78 */
82
83/**
84 * Returns the resource vector associated with the given operation.
85 *
86 * @param operationName The operation name.
87 * @return The resource vector.
88 * @exception KeyNotFound If the operation is not found.
89 */
90const ResourceVector&
91ResourceVectorSet::resourceVector(const std::string& operationName) const {
92 const std::string opName = StringTools::stringToUpper(operationName);
93 if (!AssocTools::containsKey(vectors_, opName)) {
94 std::string message = "No resource vector found for operation " +
95 operationName + ".";
96 throw KeyNotFound(
97 __FILE__, __LINE__, __func__, message);
98 }
99 return *(*vectors_.find(opName)).second;
100}
101
102/**
103 * Returns the count of resource vectors in the set.
104 *
105 * @return The count.
106 */
107std::size_t
109 return vectors_.size();
110}
111
112/**
113 * Returns the resource vector at the given index.
114 *
115 * @param index The index.
116 * @return The resource vector.
117 */
118const ResourceVector&
119ResourceVectorSet::resourceVector(std::size_t index) const {
120
121 int counter = index;
122 for (ResourceVectorIndex::const_iterator i = vectors_.begin();
123 i != vectors_.end(); ++i) {
124 if (counter == 0)
125 return *((*i).second);
126 --counter;
127 }
128 // should never get here
129 return *((*vectors_.end()).second);
130}
131
132/**
133 * Returns the name of the operation of the resource vector at the given index.
134 *
135 * @param index The index.
136 * @return The operation name.
137 */
138std::string
139ResourceVectorSet::operationName(std::size_t index) const {
140
141 int counter = index;
142 for (ResourceVectorIndex::const_iterator i = vectors_.begin();
143 i != vectors_.end(); ++i) {
144 if (counter == 0)
145 return (*i).first;
146 --counter;
147 }
148 // should never get here
149 return (*vectors_.end()).first;
150}
151
152/**
153 * Returns the index of the operation with the given name.
154 *
155 * @param operationName The name of the operation.
156 * @return Index of the operation.
157 * @exception KeyNotFound If the operation is not found.
158 */
159std::size_t
160ResourceVectorSet::operationIndex(const std::string& operationName) const {
161 int counter = 0;
162 for (ResourceVectorIndex::const_iterator i = vectors_.begin();
163 i != vectors_.end(); ++i) {
164 if ((*i).first == operationName)
165 return counter;
166 ++counter;
167 }
168 throw KeyNotFound(__FILE__, __LINE__, __func__, "Operation not found.");
169}
170
171/**
172 * Returns the width of the longest resource vector in the resource vector set.
173 *
174 * @return The width.
175 */
176std::size_t
178 return width_;
179}
180
181
182/**
183 * Compares two ResourceVectorSets.
184 *
185 * @param rightHand Right hand operand.
186 * @return True is the two sets match false otherwise.
187 */
188bool
190
191 if (resourceVectorCount() != rightHand.resourceVectorCount()) {
192 return false;
193 }
194 ResourceVectorIndex::const_iterator iter = vectors_.begin();
195 for (; iter != vectors_.end(); iter++) {
196 try {
197 if (!((*(*iter).second) ==
198 rightHand.resourceVector((*iter).first))) {
199 return false;
200 }
201 } catch (KeyNotFound& e) {
202 return false;
203 }
204 }
205 return true;
206}
207}
#define __func__
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
static void deleteAllValues(ContainerType &aMap)
void setCause(const Exception &cause)
Definition Exception.cc:75
static std::string stringToUpper(const std::string &source)
virtual HWOperation * operation(const std::string &name) const
virtual int operationCount() const
ExecutionPipeline * pipeline() const
const std::string & name() const
bool operator==(const ResourceVectorSet &rightHand) const
const ResourceVector & resourceVector(const std::string &operationName) const
std::size_t resourceVectorCount() const
ResourceVectorSet(const TTAMachine::FunctionUnit &functionUnit)
ResourceVectorIndex vectors_
Storage for the resource vectors.
std::size_t operationIndex(const std::string &operationName) const
std::string operationName(std::size_t index) const
std::size_t width_
Width of the longest resource vector.
std::size_t width() const