+//===-- ToolRunner.cpp ----------------------------------------------------===//
+//
+// This file implements the interfaces described in the ToolRunner.h file.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "toolrunner"
+#include "llvm/Support/ToolRunner.h"
#include "Support/Debug.h"
#include "Support/FileUtilities.h"
-#include "Support/ToolRunner.h"
+#include <iostream>
+#include <fstream>
//===---------------------------------------------------------------------===//
// LLI Implementation of AbstractIntepreter interface
virtual int ExecuteProgram(const std::string &Bytecode,
- const cl::list<std::string> &Args,
+ const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
- const std::string &SharedLib = "");
+ const std::vector<std::string> &SharedLibs =
+ std::vector<std::string>());
};
int LLI::ExecuteProgram(const std::string &Bytecode,
- const cl::list<std::string> &Args,
+ const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
- const std::string &SharedLib) {
- if (!SharedLib.empty()) {
+ const std::vector<std::string> &SharedLibs) {
+ if (!SharedLibs.empty()) {
std::cerr << "LLI currently does not support loading shared libraries.\n"
<< "Exiting.\n";
exit(1);
std::vector<const char*> LLIArgs;
LLIArgs.push_back(LLIPath.c_str());
- LLIArgs.push_back("-abort-on-exception");
LLIArgs.push_back("-quiet");
LLIArgs.push_back("-force-interpreter=true");
LLIArgs.push_back(Bytecode.c_str());
LLIArgs.push_back(0);
std::cout << "<lli>" << std::flush;
- DEBUG(std::cerr << "\nAbout to run:\n\t";
- for (unsigned i=0, e = LLIArgs.size(); i != e; ++i)
+ DEBUG(std::cerr << "\nAbout to run:\t";
+ for (unsigned i=0, e = LLIArgs.size()-1; i != e; ++i)
std::cerr << " " << LLIArgs[i];
std::cerr << "\n";
);
}
// LLI create method - Try to find the LLI executable
-AbstractInterpreter *createLLItool(const std::string &ProgramPath,
- std::string &Message) {
- std::string LLIPath = FindExecutable("lli", ProgramPath);
+AbstractInterpreter *AbstractInterpreter::createLLI(const std::string &ProgPath,
+ std::string &Message) {
+ std::string LLIPath = FindExecutable("lli", ProgPath);
if (!LLIPath.empty()) {
Message = "Found lli: " + LLIPath + "\n";
return new LLI(LLIPath);
//===----------------------------------------------------------------------===//
// LLC Implementation of AbstractIntepreter interface
//
-int LLC::OutputAsm(const std::string &Bytecode,
- std::string &OutputAsmFile) {
+int LLC::OutputAsm(const std::string &Bytecode, std::string &OutputAsmFile) {
OutputAsmFile = getUniqueFilename(Bytecode+".llc.s");
const char *LLCArgs[] = {
LLCPath.c_str(),
}
int LLC::ExecuteProgram(const std::string &Bytecode,
- const cl::list<std::string> &Args,
+ const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
- const std::string &SharedLib) {
+ const std::vector<std::string> &SharedLibs) {
std::string OutputAsmFile;
if (OutputAsm(Bytecode, OutputAsmFile)) {
}
// Assuming LLC worked, compile the result with GCC and run it.
- int Result = gcc->ExecuteProgram(OutputAsmFile, Args, AsmFile,
- InputFile, OutputFile, SharedLib);
+ int Result = gcc->ExecuteProgram(OutputAsmFile, Args, GCC::AsmFile,
+ InputFile, OutputFile, SharedLibs);
removeFile(OutputAsmFile);
return Result;
}
-/// createLLCtool - Try to find the LLC executable
+/// createLLC - Try to find the LLC executable
///
-LLC *createLLCtool(const std::string &ProgramPath, std::string &Message)
-{
+LLC *AbstractInterpreter::createLLC(const std::string &ProgramPath,
+ std::string &Message) {
std::string LLCPath = FindExecutable("llc", ProgramPath);
if (LLCPath.empty()) {
Message = "Cannot find `llc' in executable directory or PATH!\n";
}
Message = "Found llc: " + LLCPath + "\n";
- GCC *gcc = createGCCtool(ProgramPath, Message);
+ GCC *gcc = GCC::create(ProgramPath, Message);
if (!gcc) {
std::cerr << Message << "\n";
exit(1);
virtual int ExecuteProgram(const std::string &Bytecode,
- const cl::list<std::string> &Args,
+ const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
- const std::string &SharedLib = "");
+ const std::vector<std::string> &SharedLibs =
+ std::vector<std::string>());
};
int JIT::ExecuteProgram(const std::string &Bytecode,
- const cl::list<std::string> &Args,
+ const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
- const std::string &SharedLib) {
+ const std::vector<std::string> &SharedLibs) {
// Construct a vector of parameters, incorporating those from the command-line
std::vector<const char*> JITArgs;
JITArgs.push_back(LLIPath.c_str());
JITArgs.push_back("-quiet");
JITArgs.push_back("-force-interpreter=false");
- if (!SharedLib.empty()) {
+
+ for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i) {
JITArgs.push_back("-load");
- JITArgs.push_back(SharedLib.c_str());
+ JITArgs.push_back(SharedLibs[i].c_str());
}
JITArgs.push_back(Bytecode.c_str());
// Add optional parameters to the running program from Argv
JITArgs.push_back(0);
std::cout << "<jit>" << std::flush;
- DEBUG(std::cerr << "\nAbout to run:\n\t";
- for (unsigned i=0, e = JITArgs.size(); i != e; ++i)
+ DEBUG(std::cerr << "\nAbout to run:\t";
+ for (unsigned i=0, e = JITArgs.size()-1; i != e; ++i)
std::cerr << " " << JITArgs[i];
std::cerr << "\n";
);
InputFile, OutputFile, OutputFile);
}
-/// createJITtool - Try to find the LLI executable
+/// createJIT - Try to find the LLI executable
///
-AbstractInterpreter *createJITtool(const std::string &ProgramPath,
- std::string &Message) {
- std::string LLIPath = FindExecutable("lli", ProgramPath);
+AbstractInterpreter *AbstractInterpreter::createJIT(const std::string &ProgPath,
+ std::string &Message) {
+ std::string LLIPath = FindExecutable("lli", ProgPath);
if (!LLIPath.empty()) {
Message = "Found lli: " + LLIPath + "\n";
return new JIT(LLIPath);
}
int CBE::ExecuteProgram(const std::string &Bytecode,
- const cl::list<std::string> &Args,
+ const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
- const std::string &SharedLib) {
+ const std::vector<std::string> &SharedLibs) {
std::string OutputCFile;
if (OutputC(Bytecode, OutputCFile)) {
std::cerr << "Could not generate C code with `llvm-dis', exiting.\n";
exit(1);
}
- int Result = gcc->ExecuteProgram(OutputCFile, Args, CFile,
- InputFile, OutputFile, SharedLib);
+ int Result = gcc->ExecuteProgram(OutputCFile, Args, GCC::CFile,
+ InputFile, OutputFile, SharedLibs);
removeFile(OutputCFile);
return Result;
}
-/// createCBEtool - Try to find the 'dis' executable
+/// createCBE - Try to find the 'llvm-dis' executable
///
-CBE *createCBEtool(const std::string &ProgramPath, std::string &Message) {
+CBE *AbstractInterpreter::createCBE(const std::string &ProgramPath,
+ std::string &Message) {
std::string DISPath = FindExecutable("llvm-dis", ProgramPath);
if (DISPath.empty()) {
Message =
}
Message = "Found llvm-dis: " + DISPath + "\n";
- GCC *gcc = createGCCtool(ProgramPath, Message);
+ GCC *gcc = GCC::create(ProgramPath, Message);
if (!gcc) {
std::cerr << Message << "\n";
exit(1);
//===---------------------------------------------------------------------===//
// GCC abstraction
//
-// This is not a *real* AbstractInterpreter as it does not accept bytecode
-// files, but only input acceptable to GCC, i.e. C, C++, and assembly files
-//
int GCC::ExecuteProgram(const std::string &ProgramFile,
- const cl::list<std::string> &Args,
+ const std::vector<std::string> &Args,
FileType fileType,
const std::string &InputFile,
const std::string &OutputFile,
- const std::string &SharedLib) {
- std::string OutputBinary = getUniqueFilename(ProgramFile+".gcc.exe");
+ const std::vector<std::string> &SharedLibs) {
std::vector<const char*> GCCArgs;
GCCArgs.push_back(GCCPath.c_str());
- if (!SharedLib.empty()) // Specify the shared library to link in...
- GCCArgs.push_back(SharedLib.c_str());
+
+ // Specify the shared libraries to link in...
+ for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i)
+ GCCArgs.push_back(SharedLibs[i].c_str());
+
+ // Specify -x explicitly in case the extension is wonky
GCCArgs.push_back("-x");
if (fileType == CFile) {
GCCArgs.push_back("c");
}
GCCArgs.push_back(ProgramFile.c_str()); // Specify the input filename...
GCCArgs.push_back("-o");
+ std::string OutputBinary = getUniqueFilename(ProgramFile+".gcc.exe");
GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file...
GCCArgs.push_back("-lm"); // Hard-code the math library...
GCCArgs.push_back("-O2"); // Optimize the program a bit...
+ GCCArgs.push_back("-Wl,-R."); // Search this dir for .so files
GCCArgs.push_back(0); // NULL terminator
std::cout << "<gcc>" << std::flush;
// Now that we have a binary, run it!
std::cout << "<program>" << std::flush;
- DEBUG(std::cerr << "\nAbout to run:\n\t";
- for (unsigned i=0, e = ProgramArgs.size(); i != e; ++i)
+ DEBUG(std::cerr << "\nAbout to run:\t";
+ for (unsigned i=0, e = ProgramArgs.size()-1; i != e; ++i)
std::cerr << " " << ProgramArgs[i];
std::cerr << "\n";
);
return ProgramResult;
}
-int GCC::MakeSharedObject(const std::string &InputFile,
- FileType fileType,
+int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
std::string &OutputFile) {
OutputFile = getUniqueFilename(InputFile+".so");
// Compile the C/asm file into a shared object
};
std::cout << "<gcc>" << std::flush;
- if(RunProgramWithTimeout(GCCPath, GCCArgs, "/dev/null", "/dev/null",
- "/dev/null")) {
+ if (RunProgramWithTimeout(GCCPath, GCCArgs, "/dev/null", "/dev/null",
+ "/dev/null")) {
ProcessFailure(GCCArgs);
- exit(1);
+ return 1;
}
return 0;
}
removeFile(ErrorFilename);
}
-/// createGCCtool - Try to find the `gcc' executable
+/// create - Try to find the `gcc' executable
///
-GCC *createGCCtool(const std::string &ProgramPath, std::string &Message) {
+GCC *GCC::create(const std::string &ProgramPath, std::string &Message) {
std::string GCCPath = FindExecutable("gcc", ProgramPath);
if (GCCPath.empty()) {
Message = "Cannot find `gcc' in executable directory or PATH!\n";