OpenASIP  2.0
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";
101  options.printHelp();
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";
116  options.printHelp();
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 }

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

Here is the call graph for this function:
MachInfoCmdLineOptions::printHelp
virtual void printHelp() const
Definition: MachInfoCmdLineOptions.cc:89
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
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
TPEF::Binary
Definition: Binary.hh:49
TPEF::BinaryStream
Definition: BinaryStream.hh:59
CompileError
Definition: Exception.hh:1019
IllegalCommandLine
Definition: Exception.hh:438
AsmCmdLineOptions
Definition: tceasm.cc:52
CompilerMessage
Definition: AssemblyParserDiagnostic.hh:46
ADFSerializer
Definition: ADFSerializer.hh:49
__func__
#define __func__
Definition: Application.hh:67
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
ADFSerializer::readMachine
TTAMachine::Machine * readMachine()
Definition: ADFSerializer.cc:275
Assembler
Definition: Assembler.hh:55
FileSystem::fileIsReadable
static bool fileIsReadable(const std::string fileName)
CmdLineParser::argument
virtual std::string argument(int index) const
TTAMachine::Machine
Definition: Machine.hh:73