OpenASIP 2.2
Loading...
Searching...
No Matches
Classes | Functions
tceasm.cc File Reference
#include <iostream>
#include "tce_config.h"
#include "CmdLineOptions.hh"
#include "Assembler.hh"
#include "ADFSerializer.hh"
#include "Machine.hh"
#include "Binary.hh"
#include "TPEFWriter.hh"
#include "FileSystem.hh"
#include "BinaryStream.hh"
Include dependency graph for tceasm.cc:

Go to the source code of this file.

Classes

class  AsmCmdLineOptions
 

Functions

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

Detailed Description

TCE paraller assembler commandline client.

Author
Mikael Lepist� 2005 (tmlepist-no.spam-cs.tut.fi)
Note
rating: red

Definition in file tceasm.cc.

Function Documentation

◆ main()

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

Definition at line 83 of file tceasm.cc.

83 {
84
86 Machine* machine = NULL;
87
88 try {
89 options.parse(argv, argc);
90 } catch (const ParserStopRequest& e) {
91 return EXIT_SUCCESS;
92 } catch (IllegalCommandLine &e) {
93 std::cerr << "Error: Illegal commandline: "
94 << e.errorMessage() << "\n\n";
96 return 1;
97 }
98
99 if (options.numberOfArguments() != 2) {
100 std::cerr << "Error: Illegal number of parameters.\n\n";
102 return 1;
103 }
104
105 // find out which parameter was adf file
106 ADFSerializer machineReader;
107 machineReader.setSourceFile(options.argument(1));
108
109 std::string adfFileName = options.argument(1);
110 std::string asmFileName = options.argument(2);
111
112 try {
113 machine = machineReader.readMachine();
114 } catch ( ... ) {
115 std::cerr << "Error: " << adfFileName << " is not valid ADF file.\n\n";
117 return 1;
118 }
119
120 if (!FileSystem::fileIsReadable(asmFileName)) {
121 std::cerr << "Error: cannot read " << asmFileName << std::endl;
122 return 2;
123 }
124
125 // generate default output file name:
126 // file.name.ending -> file.name.tpef
127 // justafile -> justafile.tpef
128 std::string::size_type dotPosition = asmFileName.rfind('.');
129 std::string genOutputFileName;
130
131 std::string outputFileName;
132
133 if (dotPosition != std::string::npos) {
134 genOutputFileName = asmFileName.substr(0, dotPosition);
135 } else {
136 genOutputFileName = asmFileName;
137 }
138
139 genOutputFileName += ".tpef";
140
141 outputFileName = options.outputFile();
142
143 if (outputFileName == "") {
144 outputFileName = genOutputFileName;
145 };
146
147 BinaryStream asmFile(asmFileName);
148
149 Assembler assembler(asmFile, *machine);
150
151 // if there was failure during compilation
152 bool failure = false;
153
154 try {
155 Binary* compiledTPEF = assembler.compile();
156
157 if (options.printWarnings()) {
158 for (const CompilerMessage& message : assembler.warnings()) {
159 std::cerr << message.toString() << std::endl;
160 }
161 }
162
163 try {
164 BinaryStream tpefStream(outputFileName);
165
166 TPEFWriter::instance().writeBinary(tpefStream, compiledTPEF);
167
168 } catch (Exception& e) {
169 // if error during the TPEF writing to file.
170 delete compiledTPEF;
171 compiledTPEF = NULL;
172
173 CompileError error(
174 __FILE__, __LINE__, __func__,
175 "Problems while writing Binary to file: " +
177
178 error.setCause(e);
179
180 throw error;
181 }
182
183 } catch (CompileError& e) {
184 std::cerr << "Error while compiling file: " << asmFileName << std::endl
185 << e.errorMessage() << std::endl;
186 failure = true;
187
188 } catch (Exception& e) {
189 std::cerr << "Strange exception while compiling file: " << asmFileName << std::endl
190 << e.errorMessage() << std::endl;
191 failure = true;
192
193 } catch ( ... ) {
194 std::cerr << "Unknown exception!\n";
195 failure = true;
196 }
197
198 // back to the nature!
199 delete machine;
200 machine = NULL;
201
202 if (failure) {
203 return 1;
204 } else {
205 return 0;
206 }
207}
#define __func__
static std::string outputFileName(const std::string &adfFile)
Definition CreateBEM.cc:77
TTAMachine::Machine * machine
the architecture definition of the estimated processor
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
TTAMachine::Machine * readMachine()
void parse(char *argv[], int argc)
virtual std::string argument(int index) const
virtual int numberOfArguments() const
std::string errorMessage() const
Definition Exception.cc:123
static bool fileIsReadable(const std::string fileName)
virtual void printHelp() const
void writeBinary(BinaryStream &stream, const Binary *bin) const
static const BinaryWriter & instance()
Definition TPEFWriter.cc:70
void setSourceFile(const std::string &fileName)

References __func__, CmdLineParser::argument(), Assembler::compile(), Exception::errorMessage(), FileSystem::fileIsReadable(), TPEF::TPEFWriter::instance(), machine, CmdLineParser::numberOfArguments(), options, outputFileName(), CmdLineOptions::parse(), MachInfoCmdLineOptions::printHelp(), ADFSerializer::readMachine(), Exception::setCause(), XMLSerializer::setSourceFile(), Assembler::warnings(), and TPEF::BinaryWriter::writeBinary().

Here is the call graph for this function: