OpenASIP 2.2
Loading...
Searching...
No Matches
CreateBEM.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 CreateBEM.cc
26 *
27 * Implements the main function of createbem application which creates a
28 * binary encoding map.
29 *
30 * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#include <iostream>
35#include <string>
36
38#include "BEMSerializer.hh"
39#include "BEMGenerator.hh"
40#include "BinaryEncoding.hh"
41#include "Machine.hh"
42#include "ADFSerializer.hh"
43#include "FileSystem.hh"
44
45using std::cerr;
46using std::endl;
47using std::string;
48
49using namespace TTAMachine;
50
51
52/**
53 * Loads the given ADF file and creates a Machine instance from it.
54 *
55 * @param adfFile The ADF file.
56 * @return The newly created Machine instance.
57 * @exception SerializerException If an error occurs while reading the file.
58 * @exception ObjectStateLoadingException If an error occurs while loading
59 * the state of Machine instance.
60 */
61static Machine*
62loadMachine(const std::string& adfFile) {
63 ADFSerializer serializer;
64 serializer.setSourceFile(adfFile);
65 return serializer.readMachine();
66}
67
68/**
69 * Generates the name of the output file from the given ADF file name.
70 *
71 * The generated name has same body but .bem suffix.
72 *
73 * @param adfFile The name of the ADF file.
74 * @return The name of the output file.
75 */
76static std::string
77outputFileName(const std::string& adfFile) {
78 string file = FileSystem::fileNameBody(adfFile);
79 return file + ".bem";
80}
81
82
83/**
84 * The main function.
85 */
86int main(int argc, char* argv[]) {
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}
int main(int argc, char *argv[])
Definition CreateBEM.cc:86
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
TTAMachine::Machine * readMachine()
BinaryEncoding * generate()
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
static std::string fileNameBody(const std::string &fileName)
virtual void printHelp() const
void setSourceFile(const std::string &fileName)
void setDestinationFile(const std::string &fileName)