OpenASIP  2.0
Functions
CreateBEM.cc File Reference
#include <iostream>
#include <string>
#include "BEMGeneratorCmdLineOptions.hh"
#include "BEMSerializer.hh"
#include "BEMGenerator.hh"
#include "BinaryEncoding.hh"
#include "Machine.hh"
#include "ADFSerializer.hh"
#include "FileSystem.hh"
Include dependency graph for CreateBEM.cc:

Go to the source code of this file.

Functions

static MachineloadMachine (const std::string &adfFile)
 
static std::string outputFileName (const std::string &adfFile)
 
int main (int argc, char *argv[])
 

Detailed Description

Implements the main function of createbem application which creates a binary encoding map.

Author
Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
Note
rating: red

Definition in file CreateBEM.cc.

Function Documentation

◆ loadMachine()

static Machine* loadMachine ( const std::string &  adfFile)
static

Loads the given ADF file and creates a Machine instance from it.

Parameters
adfFileThe ADF file.
Returns
The newly created Machine instance.
Exceptions
SerializerExceptionIf an error occurs while reading the file.
ObjectStateLoadingExceptionIf an error occurs while loading the state of Machine instance.

Definition at line 62 of file CreateBEM.cc.

62  {
63  ADFSerializer serializer;
64  serializer.setSourceFile(adfFile);
65  return serializer.readMachine();
66 }

References ADFSerializer::readMachine(), and XMLSerializer::setSourceFile().

Referenced by GenerateProcessor::generateProcessor(), and main().

Here is the call graph for this function:

◆ main()

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

The main function.

Definition at line 86 of file CreateBEM.cc.

86  {
88  try {
89  options.parse(argv, argc);
90  } catch (ParserStopRequest) {
91  return EXIT_SUCCESS;
92  } catch (const IllegalCommandLine& exception) {
93  cerr << exception.errorMessage() << endl;
94  return EXIT_FAILURE;
95  }
96 
97  string adfFile = options.adfFile();
98  string outputFile = options.outputFile();
99  if (adfFile == "") {
100  options.printHelp();
101  return EXIT_FAILURE;
102  }
103 
104  Machine* mach = NULL;
105  try {
106  mach = loadMachine(adfFile);
107  } catch (const Exception& e) {
108  cerr << "Error while loading machine from adf:" << endl
109  << e.fileName() << ", line: " << e.lineNum() << endl
110  << e.errorMessage() << endl;
111  return EXIT_FAILURE;
112  }
113 
114  BEMGenerator generator(*mach);
115  BinaryEncoding* bem = generator.generate();
116 
117  BEMSerializer serializer;
118 
119  if (outputFile == "") {
120  outputFile = outputFileName(adfFile);
121  }
122 
123  serializer.setDestinationFile(outputFile);
124  serializer.writeBinaryEncoding(*bem);
125 
126  delete mach;
127  delete bem;
128 
129  return EXIT_SUCCESS;
130 }

References Exception::errorMessage(), Exception::fileName(), BEMGenerator::generate(), Exception::lineNum(), loadMachine(), options, outputFileName(), CmdLineOptions::parse(), MachInfoCmdLineOptions::printHelp(), XMLSerializer::setDestinationFile(), and BEMSerializer::writeBinaryEncoding().

Here is the call graph for this function:

◆ outputFileName()

static std::string outputFileName ( const std::string &  adfFile)
static

Generates the name of the output file from the given ADF file name.

The generated name has same body but .bem suffix.

Parameters
adfFileThe name of the ADF file.
Returns
The name of the output file.

Definition at line 77 of file CreateBEM.cc.

77  {
78  string file = FileSystem::fileNameBody(adfFile);
79  return file + ".bem";
80 }

References FileSystem::fileNameBody().

Referenced by main(), and SOPCBuilderFileGenerator::writeProjectFiles().

Here is the call graph for this function:
BEMGeneratorCmdLineOptions
Definition: BEMGeneratorCmdLineOptions.hh:42
MachInfoCmdLineOptions::printHelp
virtual void printHelp() const
Definition: MachInfoCmdLineOptions.cc:89
BinaryEncoding
Definition: BinaryEncoding.hh:61
Exception::lineNum
int lineNum() const
loadMachine
static Machine * loadMachine(const std::string &adfFile)
Definition: CreateBEM.cc:62
ParserStopRequest
Definition: Exception.hh:491
XMLSerializer::setSourceFile
void setSourceFile(const std::string &fileName)
Definition: XMLSerializer.cc:115
outputFileName
static std::string outputFileName(const std::string &adfFile)
Definition: CreateBEM.cc:77
IllegalCommandLine
Definition: Exception.hh:438
BEMSerializer
Definition: BEMSerializer.hh:43
BEMGenerator
Definition: BEMGenerator.hh:61
Exception::fileName
std::string fileName() const
ADFSerializer
Definition: ADFSerializer.hh:49
XMLSerializer::setDestinationFile
void setDestinationFile(const std::string &fileName)
Definition: XMLSerializer.cc:142
Exception
Definition: Exception.hh:54
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
CmdLineOptions::parse
void parse(char *argv[], int argc)
Definition: CmdLineOptions.cc:107
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
BEMSerializer::writeBinaryEncoding
void writeBinaryEncoding(const BinaryEncoding &bem)
Definition: BEMSerializer.cc:272
ADFSerializer::readMachine
TTAMachine::Machine * readMachine()
Definition: ADFSerializer.cc:275
FileSystem::fileNameBody
static std::string fileNameBody(const std::string &fileName)
Definition: FileSystem.cc:291
TTAMachine::Machine
Definition: Machine.hh:73