OpenASIP 2.2
Loading...
Searching...
No Matches
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}
TTAMachine::Machine * readMachine()
void setSourceFile(const std::string &fileName)

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

Referenced by 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 const&) {
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 == "") {
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}
static Machine * loadMachine(const std::string &adfFile)
Definition CreateBEM.cc:62
static std::string outputFileName(const std::string &adfFile)
Definition CreateBEM.cc:77
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
void writeBinaryEncoding(const BinaryEncoding &bem)
void parse(char *argv[], int argc)
std::string fileName() const
std::string errorMessage() const
Definition Exception.cc:123
int lineNum() const
virtual void printHelp() const
void setDestinationFile(const std::string &fileName)

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}
static std::string fileNameBody(const std::string &fileName)

References FileSystem::fileNameBody().

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

Here is the call graph for this function: