OpenASIP 2.2
Loading...
Searching...
No Matches
IDFValidator.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 IDFValidator.cc
26 *
27 * Implementation of IDFValidator class.
28 *
29 * @author Lasse Laasonen 2006 (lasse.laasonen-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <boost/format.hpp>
34#include "IDFValidator.hh"
35#include "Machine.hh"
37
38using namespace TTAMachine;
39using namespace IDF;
40using boost::format;
41
42/**
43 * The constructor.
44 */
48 machine_(machine), idf_(idf) {
49}
50
51
52/**
53 * The destructor.
54 */
57
58
59/**
60 * Validates the IDF by checking that the IDF has an implementation
61 * defined for all the units of the machine.
62 *
63 * @return True if the IDF is valid, otherwise false.
64 */
65bool
73
74
75/**
76 * Returns the number of errors found in the last validation.
77 *
78 * @return The error count.
79 */
80int
82 return errorMessages_.size();
83}
84
85
86/**
87 * Returns an error message by the given index.
88 *
89 * @param index The index.
90 * @exception OutOfRange If the index is negative or not smaller than the
91 * number of errors.
92 */
93std::string
95 if (index < 0 || index >= errorCount()) {
96 throw OutOfRange(__FILE__, __LINE__, __func__);
97 }
98
99 return errorMessages_[index];
100}
101
102/**
103 * Checks that the IDF defines an implementation for each FU in the machine.
104 *
105 * If errors are found, error messages are inserted to the vector of error
106 * messages.
107 */
108void
110
113
114 for (int i = 0; i < fuNav.count(); i++) {
115 const FunctionUnit* fu = fuNav.item(i);
116 if (!idf_.hasFUImplementation(fu->name()) &&
117 !idf_.hasFUGeneration(fu->name())) {
118 format errorMsg(
119 "IDF does not define an implementation for "
120 " function unit %1%.");
121
122 errorMsg % fu->name();
123 errorMessages_.push_back(errorMsg.str());
124 }
125 }
126
127 for (int i = 0; i < idf_.fuImplementationCount(); i++) {
129 if (!fuNav.hasItem(fui.unitName())) {
130 format errorMsg(
131 "IDF defines implementation for unknown "
132 "function unit %1%.");
133
134 errorMsg % fui.unitName();
135 errorMessages_.push_back(errorMsg.str());
136 }
137 }
138}
139
140
141/**
142 * Checks that the IDF defines an implementation for each RF in the machine.
143 *
144 * If errors are found, error messages are inserted to the vector of error
145 * messages.
146 */
147void
149
152
153 for (int i = 0; i < rfNav.count(); i++) {
154 RegisterFile* rf = rfNav.item(i);
155 if (!idf_.hasRFImplementation(rf->name())) {
156 format errorMsg(
157 "IDF does not define an implementation for "
158 "register file %1%.");
159
160 errorMsg % rf->name();
161 errorMessages_.push_back(errorMsg.str());
162 }
163 }
164
165 for (int i = 0; i < idf_.rfImplementationCount(); i++) {
167 if (!rfNav.hasItem(rfi.unitName())) {
168 format errorMsg(
169 "IDF defines implementation for unknown register file %1%.");
170
171 errorMsg % rfi.unitName();
172 errorMessages_.push_back(errorMsg.str());
173 }
174 }
175}
176
177
178/**
179 * Checks that the IDF defines an implementation for each IU in the machine.
180 *
181 * If errors are found, error messages are inserted to the vector of error
182 * messages.
183 */
184void
186
189
190 for (int i = 0; i < iuNav.count(); i++) {
191 ImmediateUnit* iu = iuNav.item(i);
192 if (!idf_.hasIUImplementation(iu->name())) {
193 format errorMsg(
194 "IDF does not define an implementation for "
195 "immediate unit %1%.");
196
197 errorMsg % iu->name();
198 errorMessages_.push_back(errorMsg.str());
199 }
200 }
201
202 for (int i = 0; i < idf_.iuImplementationCount(); i++) {
204 if (!iuNav.hasItem(iui.unitName())) {
205 format errorMsg(
206 "IDF defines implementation for unknown immediate unit %1%.");
207
208 errorMsg % iui.unitName();
209 errorMessages_.push_back(errorMsg.str());
210 }
211 }
212}
213
214
215/**
216 * Static helper function for removing implementations to units that don't
217 * exist in the machine.
218 *
219 * @param idf IDF to remove extraneous implementations from.
220 * @param machine Machine to check the IDF against.
221 */
222void
226
229
232
235
236 for (int i = 0; i < idf.iuImplementationCount(); i++) {
237 const RFImplementationLocation& iui = idf.iuImplementation(i);
238 if (!iuNav.hasItem(iui.unitName())) {
240 }
241 }
242
243 for (int i = 0; i < idf.rfImplementationCount(); i++) {
244 const RFImplementationLocation& rfi = idf.rfImplementation(i);
245 if (!rfNav.hasItem(rfi.unitName())) {
247 }
248 }
249
250 for (int i = 0; i < idf.fuImplementationCount(); i++) {
251 const FUImplementationLocation& fui = idf.fuImplementation(i);
252 if (!fuNav.hasItem(fui.unitName())) {
254 }
255 }
256}
#define __func__
TTAMachine::Machine * machine
the architecture definition of the estimated processor
const IDF::MachineImplementation & idf_
The implementation definition,.
std::string errorMessage(int index) const
void checkRFImplementations()
IDFValidator(const IDF::MachineImplementation &idf, const TTAMachine::Machine &machine)
static void removeUnknownImplementations(IDF::MachineImplementation &idf, const TTAMachine::Machine &machine)
void checkFUImplementations()
const TTAMachine::Machine & machine_
The machine.
StringVector errorMessages_
Vector of error messages.
void checkIUImplementations()
virtual ~IDFValidator()
int errorCount() const
void removeFUImplementation(const std::string &unitName)
RFImplementationLocation & iuImplementation(const std::string &iu) const
RFImplementationLocation & rfImplementation(const std::string &rf) const
bool hasIUImplementation(const std::string &unitName) const
FUImplementationLocation & fuImplementation(const std::string &fu) const
void removeIUImplementation(const std::string &unitName)
bool hasFUGeneration(const std::string &name) const
bool hasRFImplementation(const std::string &unitName) const
void removeRFImplementation(const std::string &unitName)
bool hasFUImplementation(const std::string &unitName) const
virtual TCEString name() const
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual RegisterFileNavigator registerFileNavigator() const
Definition Machine.cc:450
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416