OpenASIP  2.0
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"
36 #include "MachineImplementation.hh"
37 
38 using namespace TTAMachine;
39 using namespace IDF;
40 using boost::format;
41 
42 /**
43  * The constructor.
44  */
46  const IDF::MachineImplementation& idf,
48  machine_(machine), idf_(idf) {
49 }
50 
51 
52 /**
53  * The destructor.
54  */
56 }
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  */
65 bool
67  errorMessages_.clear();
71  return errorCount() == 0;
72 }
73 
74 
75 /**
76  * Returns the number of errors found in the last validation.
77  *
78  * @return The error count.
79  */
80 int
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  */
93 std::string
94 IDFValidator::errorMessage(int index) const {
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  */
108 void
110 
111  const Machine::FunctionUnitNavigator fuNav =
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  */
147 void
149 
150  const Machine::RegisterFileNavigator rfNav =
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  */
184 void
186 
187  const Machine::ImmediateUnitNavigator iuNav =
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  */
222 void
225  const TTAMachine::Machine& machine) {
226 
227  const Machine::ImmediateUnitNavigator iuNav =
229 
230  const Machine::RegisterFileNavigator rfNav =
232 
233  const Machine::FunctionUnitNavigator fuNav =
235 
236  for (int i = 0; i < idf.iuImplementationCount(); i++) {
237  const RFImplementationLocation& iui = idf.iuImplementation(i);
238  if (!iuNav.hasItem(iui.unitName())) {
239  idf.removeIUImplementation(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())) {
246  idf.removeRFImplementation(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())) {
253  idf.removeFUImplementation(fui.unitName());
254  }
255  }
256 }
IDF::UnitImplementationLocation
Definition: UnitImplementationLocation.hh:48
IDF::MachineImplementation::removeFUImplementation
void removeFUImplementation(const std::string &unitName)
Definition: MachineImplementation.cc:634
IDFValidator::idf_
const IDF::MachineImplementation & idf_
The implementation definition,.
Definition: IDFValidator.hh:78
IDFValidator::errorCount
int errorCount() const
Definition: IDFValidator.cc:81
IDF::MachineImplementation::hasRFImplementation
bool hasRFImplementation(const std::string &unitName) const
Definition: MachineImplementation.cc:245
IDF::MachineImplementation::removeRFImplementation
void removeRFImplementation(const std::string &unitName)
Definition: MachineImplementation.cc:659
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
IDFValidator::~IDFValidator
virtual ~IDFValidator()
Definition: IDFValidator.cc:55
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
OutOfRange
Definition: Exception.hh:320
IDF::MachineImplementation::iuImplementation
RFImplementationLocation & iuImplementation(const std::string &iu) const
Definition: MachineImplementation.cc:399
IDFValidator::checkRFImplementations
void checkRFImplementations()
Definition: IDFValidator.cc:148
TTAMachine::Machine::Navigator::count
int count() const
IDFValidator::IDFValidator
IDFValidator(const IDF::MachineImplementation &idf, const TTAMachine::Machine &machine)
Definition: IDFValidator.cc:45
IDF::MachineImplementation::hasFUImplementation
bool hasFUImplementation(const std::string &unitName) const
Definition: MachineImplementation.cc:231
IDFValidator::errorMessage
std::string errorMessage(int index) const
Definition: IDFValidator.cc:94
IDFValidator.hh
IDF::MachineImplementation::hasIUImplementation
bool hasIUImplementation(const std::string &unitName) const
Definition: MachineImplementation.cc:259
IDF::MachineImplementation::hasFUGeneration
bool hasFUGeneration(const std::string &name) const
Definition: MachineImplementation.cc:1590
IDF::MachineImplementation::rfImplementation
RFImplementationLocation & rfImplementation(const std::string &rf) const
Definition: MachineImplementation.cc:377
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
IDF::MachineImplementation::removeIUImplementation
void removeIUImplementation(const std::string &unitName)
Definition: MachineImplementation.cc:684
TTAMachine::Machine::immediateUnitNavigator
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition: Machine.cc:416
IDFValidator::machine_
const TTAMachine::Machine & machine_
The machine.
Definition: IDFValidator.hh:76
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
IDFValidator::errorMessages_
StringVector errorMessages_
Vector of error messages.
Definition: IDFValidator.hh:80
__func__
#define __func__
Definition: Application.hh:67
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
IDFValidator::checkIUImplementations
void checkIUImplementations()
Definition: IDFValidator.cc:185
IDF::MachineImplementation::rfImplementationCount
int rfImplementationCount() const
Definition: MachineImplementation.cc:310
IDFValidator::validate
bool validate()
Definition: IDFValidator.cc:66
Machine.hh
IDF::UnitImplementationLocation::unitName
virtual std::string unitName() const
Definition: UnitImplementationLocation.cc:138
IDF::MachineImplementation::iuImplementationCount
int iuImplementationCount() const
Definition: MachineImplementation.cc:321
TTAMachine::Machine::registerFileNavigator
virtual RegisterFileNavigator registerFileNavigator() const
Definition: Machine.cc:450
IDF::MachineImplementation::fuImplementationCount
int fuImplementationCount() const
Definition: MachineImplementation.cc:299
IDFValidator::removeUnknownImplementations
static void removeUnknownImplementations(IDF::MachineImplementation &idf, const TTAMachine::Machine &machine)
Definition: IDFValidator.cc:223
IDFValidator::checkFUImplementations
void checkFUImplementations()
Definition: IDFValidator.cc:109
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
IDF::MachineImplementation::fuImplementation
FUImplementationLocation & fuImplementation(const std::string &fu) const
Definition: MachineImplementation.cc:355
TTAMachine
Definition: Assembler.hh:48
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
IDF::MachineImplementation
Definition: MachineImplementation.hh:54
IDF
Definition: DSDBManager.hh:54
MachineImplementation.hh
TTAMachine::Machine
Definition: Machine.hh:73
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50