OpenASIP  2.0
Macros | Functions | Variables
LLVMTCE.cc File Reference
#include <iostream>
#include "Application.hh"
#include "LLVMBackend.hh"
#include "LLVMTCECmdLineOptions.hh"
#include "Program.hh"
#include "ADFSerializer.hh"
#include "FileSystem.hh"
#include "InterPassData.hh"
#include "Machine.hh"
#include "CompilerWarnings.hh"
#include <llvm/Support/CommandLine.h>
Include dependency graph for LLVMTCE.cc:

Go to the source code of this file.

Macros

#define __STDC_LIMIT_MACROS
 

Functions

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

Variables

const POP_COMPILER_DIAGS std::string DEFAULT_OUTPUT_FILENAME = "out.tpef"
 
const int DEFAULT_OPT_LEVEL = 2
 

Detailed Description

LLVM/TCE compiler command line interface.

Author
Veli-Pekka Jääskeläinen 2008 (vjaaskel-no.spam-cs.tut.fi)
Note
rating: red

Definition in file LLVMTCE.cc.

Macro Definition Documentation

◆ __STDC_LIMIT_MACROS

#define __STDC_LIMIT_MACROS

Definition at line 46 of file LLVMTCE.cc.

Function Documentation

◆ main()

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

Main function of the CLI.

Checks command line options and runs compiler accordingly.

Parameters
argcArgument count.
argvCommand line arguments.
Returns
Exit status code for the OS.

Definition at line 65 of file LLVMTCE.cc.

65  {
66 
67  Application::initialize(argc, argv);
68 
70 
71  // Parse command line options.
72  try {
73  options->parse(argv, argc);
74  } catch (ParserStopRequest) {
75  return EXIT_SUCCESS;
76  } catch (const IllegalCommandLine& e) {
77  std::cerr << e.errorMessageStack() << std::endl;
78  return EXIT_FAILURE;
79  }
80 
81  if (options->numberOfArguments() != 1) {
82  options->printHelp();
83  return EXIT_FAILURE;
84  }
85 
86  if (options->tempDir() == "") {
88  << "Temporary directory required." << std::endl;
89  options->printHelp();
90  return EXIT_FAILURE;
91  }
92 
94 
97  }
98 
99  // --- Target ADF ---
100  if (!options->isMachineFileDefined()) {
101  std::cerr << "ERROR: No target architecture (.adf) defined."
102  << std::endl;
103 
104  return EXIT_FAILURE;
105  }
106 
107  TTAMachine::Machine* mach = NULL;
108  std::string targetADF = options->machineFile();
109 
110  if (!FileSystem::fileExists(targetADF) ||
111  !FileSystem::fileIsReadable(targetADF) ||
112  FileSystem::fileIsDirectory(targetADF)) {
113 
114  std::cerr << "ERROR: Target architecture file '"
115  << targetADF << "' doesn't exist or isn't readable."
116  << std::endl;
117 
118  return EXIT_FAILURE;
119  }
120 
121  try {
122  ADFSerializer serializer;
123  serializer.setSourceFile(targetADF);
124  mach = serializer.readMachine();
125  } catch (Exception& e) {
126  std::cerr << "Error loading target architecture file '"
127  << targetADF << "':" << std::endl
128  << e.errorMessageStack() << std::endl;
129 
130  return EXIT_FAILURE;
131  }
132 
133  // --- Output file name ---
135  if (options->isOutputFileDefined()) {
136  // Test if output file can be opened
137  outputFileName = options->outputFile();
138  }
141  std::cerr << "Output file '"
142  << outputFileName << "' can not be opened for writing!"
143  << std::endl;
144  return EXIT_FAILURE;
145  }
146 
147  // --- optimization level ---
148  int optLevel = DEFAULT_OPT_LEVEL;
149  if (options->isOptLevelDefined()) {
150  optLevel = options->optLevel();
151  }
152 
153  std::string bytecodeFile = options->argument(1);
154 
155  bool debug = options->debugFlag();
156 
157  //--- check if program was ran in src dir or from install dir ---
158  std::string runPath = std::string(argv[0]);
159 
160  bool useInstalledVersion = Application::isInstalled();
161 
162  // All emulation code which cannot be linked in before last global dce is
163  // executed, for emulation of instructions which are generated during
164  // lowering. Unnecessary functions are removed by the MachineDCE pass.
165  std::string emulationCode;
166  if (options->isStandardEmulationLibDefined()) {
167  emulationCode = options->standardEmulationLib();
168  }
169 
170  // ---- Run compiler ----
171  try {
172  InterPassData* ipData = new InterPassData;
173  int argc = 0;
174  std::string argv = options->getLLVMargv();
176  std::cout << "llvm args = " << argv << std::endl;
177  }
178  // Convert to char**
179  std::vector<char*> argv_array;
180  std::istringstream iss(argv);
181  std::string token;
182  while (iss >> token) {
183  char* arg = new char[token.size() + 1];
184  copy(token.begin(), token.end(), arg);
185  arg[token.size()] = '\0';
186  argv_array.push_back(arg);
187  argc++;
188  }
189  argv_array.push_back(0);
190  llvm::cl::ParseCommandLineOptions(
191  argc, argv_array.data(), "llvm flags\n");
192 
193  LLVMBackend compiler(useInstalledVersion, options->tempDir());
194  TTAProgram::Program* seqProg =
195  compiler.compile(
196  bytecodeFile, emulationCode, *mach, optLevel, debug, ipData);
197 
199  delete seqProg;
200  seqProg = NULL;
201 
202  delete ipData;
203  ipData = NULL;
204 
205  } catch (const CompileError& e) {
206  // CompilerErrors are related to the user program input and
207  // should be communicated to the programmer in a clean fashion.
208  Application::errorStream() << e.errorMessage() << std::endl;
209  } catch (const Exception& e) {
210  // Assume other Exceptions are due to like lack of more
211  // user friendly CompilerError or actual internal compiler errors.
212  std::cerr << "Error compiling '" << bytecodeFile << "':" << std::endl
213  << e.errorMessageStack() << std::endl;
214 
215  return EXIT_FAILURE;
216  }
217 
218  delete mach;
219  mach = NULL;
220 
221  return EXIT_SUCCESS;
222 }

References CmdLineParser::argument(), LLVMBackend::compile(), DEFAULT_OPT_LEVEL, DEFAULT_OUTPUT_FILENAME, Exception::errorMessage(), Exception::errorMessageStack(), Application::errorStream(), FileSystem::fileExists(), FileSystem::fileIsCreatable(), FileSystem::fileIsDirectory(), FileSystem::fileIsReadable(), FileSystem::fileIsWritable(), Application::initialize(), Application::isInstalled(), CmdLineOptions::isVerboseSpamSwitchDefined(), CmdLineOptions::isVerboseSwitchDefined(), CmdLineParser::numberOfArguments(), options, outputFileName(), CmdLineOptions::parse(), MachInfoCmdLineOptions::printHelp(), ADFSerializer::readMachine(), Application::setCmdLineOptions(), XMLSerializer::setSourceFile(), Application::setVerboseLevel(), Application::VERBOSE_LEVEL_INCREASED, and TTAProgram::Program::writeToTPEF().

Here is the call graph for this function:

Variable Documentation

◆ DEFAULT_OPT_LEVEL

const int DEFAULT_OPT_LEVEL = 2

Definition at line 53 of file LLVMTCE.cc.

Referenced by main().

◆ DEFAULT_OUTPUT_FILENAME

const POP_COMPILER_DIAGS std::string DEFAULT_OUTPUT_FILENAME = "out.tpef"

Definition at line 52 of file LLVMTCE.cc.

Referenced by main().

TTAProgram::Program
Definition: Program.hh:63
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
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
Application::setVerboseLevel
static void setVerboseLevel(const int level=VERBOSE_LEVEL_DEFAULT)
Definition: Application.hh:186
Application::setCmdLineOptions
static void setCmdLineOptions(CmdLineOptions *options_)
Definition: Application.cc:381
CompileError
Definition: Exception.hh:1019
IllegalCommandLine
Definition: Exception.hh:438
FileSystem::fileIsCreatable
static bool fileIsCreatable(const std::string fileName)
Definition: FileSystem.cc:123
FileSystem::fileIsDirectory
static bool fileIsDirectory(const std::string fileName)
FileSystem::fileIsWritable
static bool fileIsWritable(const std::string fileName)
ADFSerializer
Definition: ADFSerializer.hh:49
InterPassData
Definition: InterPassData.hh:48
Exception::errorMessageStack
std::string errorMessageStack(bool messagesOnly=false) const
Definition: Exception.cc:138
CmdLineOptions::isVerboseSwitchDefined
virtual bool isVerboseSwitchDefined() const
Definition: CmdLineOptions.cc:300
Exception
Definition: Exception.hh:54
Application::VERBOSE_LEVEL_INCREASED
static const int VERBOSE_LEVEL_INCREASED
Increased verbose level - print information about modules etc.
Definition: Application.hh:224
LLVMTCECmdLineOptions
Definition: LLVMTCECmdLineOptions.hh:48
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
DEFAULT_OPT_LEVEL
const int DEFAULT_OPT_LEVEL
Definition: LLVMTCE.cc:53
Application::isInstalled
static bool isInstalled()
Definition: Application.cc:522
Application::errorStream
static std::ostream & errorStream()
Definition: Application.cc:171
FileSystem::fileExists
static bool fileExists(const std::string fileName)
Application::initialize
static void initialize()
Definition: Application.cc:99
TTAProgram::Program::writeToTPEF
static void writeToTPEF(const TTAProgram::Program &program, const std::string &tpefFileName)
Definition: Program.cc:1169
ADFSerializer::readMachine
TTAMachine::Machine * readMachine()
Definition: ADFSerializer.cc:275
LLVMBackend
Definition: LLVMBackend.hh:63
FileSystem::fileIsReadable
static bool fileIsReadable(const std::string fileName)
CmdLineParser::argument
virtual std::string argument(int index) const
DEFAULT_OUTPUT_FILENAME
const POP_COMPILER_DIAGS std::string DEFAULT_OUTPUT_FILENAME
Definition: LLVMTCE.cc:52
TTAMachine::Machine
Definition: Machine.hh:73
CmdLineOptions::isVerboseSpamSwitchDefined
virtual bool isVerboseSpamSwitchDefined() const
Definition: CmdLineOptions.cc:310