OpenASIP 2.2
Loading...
Searching...
No Matches
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

POP_COMPILER_DIAGS const 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 const&) {
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) {
83 return EXIT_FAILURE;
84 }
85
86 if (options->tempDir() == "") {
88 << "Temporary directory required." << std::endl;
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 compiler.setMachine(*mach);
195 TTAProgram::Program* seqProg =
196 compiler.compile(
197 bytecodeFile, emulationCode, optLevel, debug, ipData);
198
200 delete seqProg;
201 seqProg = NULL;
202
203 delete ipData;
204 ipData = NULL;
205
206 } catch (const CompileError& e) {
207 // CompilerErrors are related to the user program input and
208 // should be communicated to the programmer in a clean fashion.
209 Application::errorStream() << e.errorMessage() << std::endl;
210 } catch (const Exception& e) {
211 // Assume other Exceptions are due to like lack of more
212 // user friendly CompilerError or actual internal compiler errors.
213 std::cerr << "Error compiling '" << bytecodeFile << "':" << std::endl
214 << e.errorMessageStack() << std::endl;
215
216 return EXIT_FAILURE;
217 }
218
219 delete mach;
220 mach = NULL;
221
222 return EXIT_SUCCESS;
223}
static std::string outputFileName(const std::string &adfFile)
Definition CreateBEM.cc:77
const int DEFAULT_OPT_LEVEL
Definition LLVMTCE.cc:53
POP_COMPILER_DIAGS const std::string DEFAULT_OUTPUT_FILENAME
Definition LLVMTCE.cc:52
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
TTAMachine::Machine * readMachine()
static void setCmdLineOptions(CmdLineOptions *options_)
static bool isInstalled()
static const int VERBOSE_LEVEL_INCREASED
Increased verbose level - print information about modules etc.
static void setVerboseLevel(const int level=VERBOSE_LEVEL_DEFAULT)
static std::ostream & errorStream()
static void initialize()
void parse(char *argv[], int argc)
virtual bool isVerboseSwitchDefined() const
virtual bool isVerboseSpamSwitchDefined() const
virtual std::string argument(int index) const
virtual int numberOfArguments() const
std::string errorMessageStack(bool messagesOnly=false) const
Definition Exception.cc:138
std::string errorMessage() const
Definition Exception.cc:123
static bool fileIsReadable(const std::string fileName)
static bool fileIsDirectory(const std::string fileName)
static bool fileIsWritable(const std::string fileName)
static bool fileIsCreatable(const std::string fileName)
static bool fileExists(const std::string fileName)
virtual void printHelp() const
static void writeToTPEF(const TTAProgram::Program &program, const std::string &tpefFileName)
Definition Program.cc:1169
void setSourceFile(const std::string &fileName)

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(), LLVMBackend::setMachine(), 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

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

Definition at line 52 of file LLVMTCE.cc.

Referenced by main().