OpenASIP  2.0
Classes | Functions
DictionaryTool.cc File Reference
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "ADFSerializer.hh"
#include "Application.hh"
#include "Machine.hh"
#include "ProgrammabilityValidator.hh"
#include "ProgrammabilityValidatorResults.hh"
#include "CmdLineOptions.hh"
#include "Exception.hh"
#include "Binary.hh"
#include "TPEFWriter.hh"
#include "TPEFProgramFactory.hh"
#include "ProgramWriter.hh"
#include "BinaryStream.hh"
#include "MoveElement.hh"
#include "tce_config.h"
Include dependency graph for DictionaryTool.cc:

Go to the source code of this file.

Classes

class  DictionaryToolCmdLineOptions
 

Functions

int main (int argc, char *argv[])
 

Detailed Description

DictionaryTool main application.

Author
Jari M�ntyneva 2006 (jari.mantyneva-no.spam-tut.fi)
Note
rating: red

Definition in file DictionaryTool.cc.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

The dictionary_tool main function.

Definition at line 162 of file DictionaryTool.cc.

162  {
163 
165 
166  try {
167  options.parse(argv, argc);
168  } catch (ParserStopRequest) {
169  return EXIT_SUCCESS;
170  } catch (const IllegalCommandLine& e) {
171  cerr << e.errorMessage() << endl;
172  return EXIT_FAILURE;
173  }
174 
175  if (options.numberOfArguments() == 0) {
176  options.printHelp();
177  return EXIT_SUCCESS;
178  } else if (options.numberOfArguments() > 1) {
179  cerr << "Illegal number of arguments" << endl;
180  return EXIT_FAILURE;
181  }
182 
183  string adfFileName = options.argument(1);
184 
185  ADFSerializer adfSerializer;
186  adfSerializer.setSourceFile(adfFileName);
187 
188  TTAMachine::Machine* mach;
189 
190  try {
191  mach = adfSerializer.readMachine();
192  } catch (...) {
193  cout.flush();
194  cerr << "Error opening ADF file:" << endl
195  << "- Is the filename correct?" << endl
196  << "- Is the machine legal?" << endl;
197  return EXIT_FAILURE;
198  }
199 
200  ProgrammabilityValidator* validator;
201 
202  try {
203  validator = new ProgrammabilityValidator(*mach);
204  } catch (IllegalMachine& e) {
205  cerr << e.errorMessage() << endl;
206  return EXIT_FAILURE;
207  }
208 
209  ProgrammabilityValidatorResults booleanResults;
210  validator->checkBooleanRegister(booleanResults);
211  if (booleanResults.errorCount() != 0) {
212  for (int i = 0; i < booleanResults.errorCount(); i++) {
214  booleanResults.error(i);
215 
216  cerr << error.second << endl;
217  }
218  cerr << "Execution stopped." << endl;
219  return EXIT_SUCCESS;
220  }
221 
222  bool gcrError = false;
223 
225  TPEF::Binary* binaryProgram = NULL;
226  try {
227  binaryProgram = validator->profile(results);
228  } catch (NotAvailable& e) {
229  cerr << e.errorMessage() << endl;
230  cerr << "Check that all operations are found in OSAL." << endl;
231  cerr << "Create new ones with OSEd." << endl;
232  cerr << "Execution stopped." << endl;
233  return EXIT_FAILURE;
234  } catch (InstanceNotFound& e) {
235  cerr << e.errorMessage() << endl;
236  }
237 
238  if (options.writeBinary()) {
239  string outputFile = adfFileName.append("_profiled.tpef");
240  BinaryStream tpefOut(outputFile);
241  TPEFWriter::instance().writeBinary(tpefOut, binaryProgram);
242  }
243 
244  if (!options.doNotPrintErrors()) {
245  for (int i = 0; i < results.errorCount(); i++) {
247  if (error.first ==
249  OPERATION_MISSING_FROM_THE_PRIMITIVE_OPERATION_SET) {
250  if (options.printPrimitive()) {
251  cerr << error.second << endl;
252  }
253  }
254  else if (error.first ==
256  GLOBAL_CONNECTION_REGISTER_NOT_FOUND) {
257  if (options.printGlobalRegister()) {
258  gcrError = true;
259  cerr << error.second << endl;
260  }
261  }
262  else if (error.first ==
264  MISSING_CONNECTION) {
265  if (options.printMissingConnections()) {
266  cerr << error.second << endl;
267  }
268  }
269  else {
270  cerr << error.second << endl;
271  }
272  }
273  }
274 
275  if (options.printGlobalRegister() && !gcrError) {
276  cout << "* The global connection register in the machine is: "
277  << validator->findGlobalConnectionRegister()->name()
278  << endl;
279  }
280 
281  if (options.printConnections()) {
282  validator->printConnections();
283  }
284 
285  if (options.printRFConnections()) {
286  validator->printRegisterConnections();
287  }
288 
289  return EXIT_SUCCESS;
290 }

References CmdLineParser::argument(), ProgrammabilityValidator::checkBooleanRegister(), ProgrammabilityValidatorResults::error(), ProgrammabilityValidatorResults::errorCount(), Exception::errorMessage(), ProgrammabilityValidator::findGlobalConnectionRegister(), TTAMachine::Component::name(), CmdLineParser::numberOfArguments(), options, CmdLineOptions::parse(), ProgrammabilityValidator::printConnections(), MachInfoCmdLineOptions::printHelp(), ProgrammabilityValidator::printRegisterConnections(), ProgrammabilityValidator::profile(), ADFSerializer::readMachine(), and XMLSerializer::setSourceFile().

Here is the call graph for this function:
MachInfoCmdLineOptions::printHelp
virtual void printHelp() const
Definition: MachInfoCmdLineOptions.cc:89
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
ParserStopRequest
Definition: Exception.hh:491
XMLSerializer::setSourceFile
void setSourceFile(const std::string &fileName)
Definition: XMLSerializer.cc:115
ProgrammabilityValidator::printConnections
void printConnections()
Definition: ProgrammabilityValidator.cc:1766
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
ProgrammabilityValidatorResults
Definition: ProgrammabilityValidatorResults.hh:46
TPEF::Binary
Definition: Binary.hh:49
TPEF::BinaryStream
Definition: BinaryStream.hh:59
IllegalCommandLine
Definition: Exception.hh:438
ProgrammabilityValidator::profile
TPEF::Binary * profile(ProgrammabilityValidatorResults &results)
Definition: ProgrammabilityValidator.cc:269
ProgrammabilityValidatorResults::error
Error error(int index) const
Definition: ProgrammabilityValidatorResults.cc:70
NotAvailable
Definition: Exception.hh:728
ProgrammabilityValidator::findGlobalConnectionRegister
const RegisterFile * findGlobalConnectionRegister()
Definition: ProgrammabilityValidator.cc:1789
ProgrammabilityValidator::checkBooleanRegister
bool checkBooleanRegister(ProgrammabilityValidatorResults &results)
Definition: ProgrammabilityValidator.cc:361
ADFSerializer
Definition: ADFSerializer.hh:49
ProgrammabilityValidator
Definition: ProgrammabilityValidator.hh:75
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
CmdLineOptions::parse
void parse(char *argv[], int argc)
Definition: CmdLineOptions.cc:107
DictionaryToolCmdLineOptions
Definition: DictionaryTool.cc:67
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
IllegalMachine
Definition: Exception.hh:878
ADFSerializer::readMachine
TTAMachine::Machine * readMachine()
Definition: ADFSerializer.cc:275
ProgrammabilityValidatorResults::errorCount
int errorCount() const
Definition: ProgrammabilityValidatorResults.cc:56
CmdLineParser::argument
virtual std::string argument(int index) const
InstanceNotFound
Definition: Exception.hh:304
TTAMachine::Machine
Definition: Machine.hh:73
ProgrammabilityValidatorResults::Error
std::pair< ProgrammabilityValidator::ErrorCode, std::string > Error
Typedef for an error (error code + error message).
Definition: ProgrammabilityValidatorResults.hh:50
ProgrammabilityValidator::printRegisterConnections
void printRegisterConnections()
Definition: ProgrammabilityValidator.cc:1356