OpenASIP  2.0
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
IDFValidator Class Reference

#include <IDFValidator.hh>

Collaboration diagram for IDFValidator:
Collaboration graph

Public Member Functions

 IDFValidator (const IDF::MachineImplementation &idf, const TTAMachine::Machine &machine)
 
virtual ~IDFValidator ()
 
bool validate ()
 
int errorCount () const
 
std::string errorMessage (int index) const
 

Static Public Member Functions

static void removeUnknownImplementations (IDF::MachineImplementation &idf, const TTAMachine::Machine &machine)
 

Private Types

typedef std::vector< std::string > StringVector
 Vector type for string. More...
 

Private Member Functions

void checkFUImplementations ()
 
void checkRFImplementations ()
 
void checkIUImplementations ()
 

Private Attributes

const TTAMachine::Machinemachine_
 The machine. More...
 
const IDF::MachineImplementationidf_
 The implementation definition,. More...
 
StringVector errorMessages_
 Vector of error messages. More...
 

Detailed Description

Validates IDF files.

Definition at line 52 of file IDFValidator.hh.

Member Typedef Documentation

◆ StringVector

typedef std::vector<std::string> IDFValidator::StringVector
private

Vector type for string.

Definition at line 69 of file IDFValidator.hh.

Constructor & Destructor Documentation

◆ IDFValidator()

IDFValidator::IDFValidator ( const IDF::MachineImplementation idf,
const TTAMachine::Machine machine 
)

The constructor.

Definition at line 45 of file IDFValidator.cc.

47  :
48  machine_(machine), idf_(idf) {
49 }

◆ ~IDFValidator()

IDFValidator::~IDFValidator ( )
virtual

The destructor.

Definition at line 55 of file IDFValidator.cc.

55  {
56 }

Member Function Documentation

◆ checkFUImplementations()

void IDFValidator::checkFUImplementations ( )
private

Checks that the IDF defines an implementation for each FU in the machine.

If errors are found, error messages are inserted to the vector of error messages.

Definition at line 109 of file IDFValidator.cc.

109  {
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 }

References TTAMachine::Machine::Navigator< ComponentType >::count(), errorMessages_, IDF::MachineImplementation::fuImplementation(), IDF::MachineImplementation::fuImplementationCount(), TTAMachine::Machine::functionUnitNavigator(), IDF::MachineImplementation::hasFUGeneration(), IDF::MachineImplementation::hasFUImplementation(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), idf_, TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, TTAMachine::Component::name(), and IDF::UnitImplementationLocation::unitName().

Referenced by validate().

Here is the call graph for this function:

◆ checkIUImplementations()

void IDFValidator::checkIUImplementations ( )
private

Checks that the IDF defines an implementation for each IU in the machine.

If errors are found, error messages are inserted to the vector of error messages.

Definition at line 185 of file IDFValidator.cc.

185  {
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 }

References TTAMachine::Machine::Navigator< ComponentType >::count(), errorMessages_, TTAMachine::Machine::Navigator< ComponentType >::hasItem(), IDF::MachineImplementation::hasIUImplementation(), idf_, TTAMachine::Machine::immediateUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), IDF::MachineImplementation::iuImplementation(), IDF::MachineImplementation::iuImplementationCount(), machine_, TTAMachine::Component::name(), and IDF::UnitImplementationLocation::unitName().

Referenced by validate().

Here is the call graph for this function:

◆ checkRFImplementations()

void IDFValidator::checkRFImplementations ( )
private

Checks that the IDF defines an implementation for each RF in the machine.

If errors are found, error messages are inserted to the vector of error messages.

Definition at line 148 of file IDFValidator.cc.

148  {
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 }

References TTAMachine::Machine::Navigator< ComponentType >::count(), errorMessages_, TTAMachine::Machine::Navigator< ComponentType >::hasItem(), IDF::MachineImplementation::hasRFImplementation(), idf_, TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, TTAMachine::Component::name(), TTAMachine::Machine::registerFileNavigator(), IDF::MachineImplementation::rfImplementation(), IDF::MachineImplementation::rfImplementationCount(), and IDF::UnitImplementationLocation::unitName().

Referenced by validate().

Here is the call graph for this function:

◆ errorCount()

int IDFValidator::errorCount ( ) const

Returns the number of errors found in the last validation.

Returns
The error count.

Definition at line 81 of file IDFValidator.cc.

81  {
82  return errorMessages_.size();
83 }

References errorMessages_.

Referenced by errorMessage(), ProcessorImplementationWindow::onGenerateProcessor(), ProcessorImplementationWindow::onLoadIDF(), validate(), and validateIdf().

◆ errorMessage()

std::string IDFValidator::errorMessage ( int  index) const

Returns an error message by the given index.

Parameters
indexThe index.
Exceptions
OutOfRangeIf the index is negative or not smaller than the number of errors.

Definition at line 94 of file IDFValidator.cc.

94  {
95  if (index < 0 || index >= errorCount()) {
96  throw OutOfRange(__FILE__, __LINE__, __func__);
97  }
98 
99  return errorMessages_[index];
100 }

References __func__, errorCount(), and errorMessages_.

Referenced by ProGe::ProGeUI::generateProcessor(), ProcessorImplementationWindow::onGenerateProcessor(), ProcessorImplementationWindow::onLoadIDF(), and validateIdf().

Here is the call graph for this function:

◆ removeUnknownImplementations()

void IDFValidator::removeUnknownImplementations ( IDF::MachineImplementation idf,
const TTAMachine::Machine machine 
)
static

Static helper function for removing implementations to units that don't exist in the machine.

Parameters
idfIDF to remove extraneous implementations from.
machineMachine to check the IDF against.

Definition at line 223 of file IDFValidator.cc.

225  {
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 }

References IDF::MachineImplementation::fuImplementation(), IDF::MachineImplementation::fuImplementationCount(), TTAMachine::Machine::functionUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), TTAMachine::Machine::immediateUnitNavigator(), IDF::MachineImplementation::iuImplementation(), IDF::MachineImplementation::iuImplementationCount(), machine, TTAMachine::Machine::registerFileNavigator(), IDF::MachineImplementation::removeFUImplementation(), IDF::MachineImplementation::removeIUImplementation(), IDF::MachineImplementation::removeRFImplementation(), IDF::MachineImplementation::rfImplementation(), IDF::MachineImplementation::rfImplementationCount(), and IDF::UnitImplementationLocation::unitName().

Referenced by ProcessorImplementationWindow::onLoadIDF().

Here is the call graph for this function:

◆ validate()

bool IDFValidator::validate ( )

Validates the IDF by checking that the IDF has an implementation defined for all the units of the machine.

Returns
True if the IDF is valid, otherwise false.

Definition at line 66 of file IDFValidator.cc.

66  {
67  errorMessages_.clear();
71  return errorCount() == 0;
72 }

References checkFUImplementations(), checkIUImplementations(), checkRFImplementations(), errorCount(), and errorMessages_.

Referenced by ProGe::ProGeUI::generateProcessor(), ProcessorImplementationWindow::onGenerateProcessor(), ProcessorImplementationWindow::onLoadIDF(), and validateIdf().

Here is the call graph for this function:

Member Data Documentation

◆ errorMessages_

StringVector IDFValidator::errorMessages_
private

Vector of error messages.

Definition at line 80 of file IDFValidator.hh.

Referenced by checkFUImplementations(), checkIUImplementations(), checkRFImplementations(), errorCount(), errorMessage(), and validate().

◆ idf_

const IDF::MachineImplementation& IDFValidator::idf_
private

The implementation definition,.

Definition at line 78 of file IDFValidator.hh.

Referenced by checkFUImplementations(), checkIUImplementations(), and checkRFImplementations().

◆ machine_

const TTAMachine::Machine& IDFValidator::machine_
private

The machine.

Definition at line 76 of file IDFValidator.hh.

Referenced by checkFUImplementations(), checkIUImplementations(), and checkRFImplementations().


The documentation for this class was generated from the following files:
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
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
IDF::MachineImplementation::hasFUImplementation
bool hasFUImplementation(const std::string &unitName) const
Definition: MachineImplementation.cc:231
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
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::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::Machine::Navigator
Definition: Machine.hh:186
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50