FileType fileType,
const std::string &InputFile,
const std::string &OutputFile,
- const std::vector<std::string> &SharedLibs =
- std::vector<std::string>(), unsigned Timeout = 0);
+ const std::vector<std::string> &GCCArgs =
+ std::vector<std::string>(),
+ unsigned Timeout = 0);
/// MakeSharedObject - This compiles the specified file (which is either a .c
/// file or a .s file) into a shared object.
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs =
+ std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0) = 0;
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs =
+ std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs =
+ std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
if (!SharedLibs.empty())
throw ToolExecutionError("LLI currently does not support "
"loading shared libraries.");
+ if (!GCCArgs.empty())
+ throw ToolExecutionError("LLI currently does not support "
+ "GCC Arguments.");
std::vector<const char*> LLIArgs;
LLIArgs.push_back(LLIPath.c_str());
LLIArgs.push_back("-force-interpreter=true");
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &ArgsForGCC,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
OutputAsm(Bytecode, OutputAsmFile);
FileRemover OutFileRemover(OutputAsmFile);
+ std::vector<std::string> GCCArgs(ArgsForGCC);
+ GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end());
+
// Assuming LLC worked, compile the result with GCC and run it.
return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile,
- InputFile, OutputFile, SharedLibs, Timeout);
+ InputFile, OutputFile, GCCArgs, Timeout);
}
/// createLLC - Try to find the LLC executable
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs =
+ std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
- std::vector<std::string>(), unsigned Timeout =0);
+ std::vector<std::string>(),
+ unsigned Timeout =0 );
};
}
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
+ if (!GCCArgs.empty())
+ throw ToolExecutionError("JIT does not support GCC Arguments.");
// Construct a vector of parameters, incorporating those from the command-line
std::vector<const char*> JITArgs;
JITArgs.push_back(LLIPath.c_str());
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &ArgsForGCC,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
sys::Path OutputCFile;
FileRemover CFileRemove(OutputCFile);
+ std::vector<std::string> GCCArgs(ArgsForGCC);
+ GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end());
return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
- InputFile, OutputFile, SharedLibs, Timeout);
+ InputFile, OutputFile, GCCArgs, Timeout);
}
/// createCBE - Try to find the 'llc' executable
FileType fileType,
const std::string &InputFile,
const std::string &OutputFile,
- const std::vector<std::string> &SharedLibs,
- unsigned Timeout) {
+ const std::vector<std::string> &ArgsForGCC,
+ unsigned Timeout ) {
std::vector<const char*> GCCArgs;
GCCArgs.push_back(GCCPath.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) {
sys::Path OutputBinary (ProgramFile+".gcc.exe");
OutputBinary.makeUnique();
GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file...
+
+ // Add any arguments intended for GCC. We locate them here because this is
+ // most likely -L and -l options that need to come before other libraries but
+ // after the source. Other options won't be sensitive to placement on the
+ // command line, so this should be safe.
+ for (unsigned i = 0, e = ArgsForGCC.size(); i != e; ++i)
+ GCCArgs.push_back(ArgsForGCC[i].c_str());
+
GCCArgs.push_back("-lm"); // Hard-code the math library...
GCCArgs.push_back("-O2"); // Optimize the program a bit...
#if defined (HAVE_LINK_R)
#include "llvm/Support/SystemUtils.h"
#include <fstream>
#include <iostream>
+
using namespace llvm;
namespace {
TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
cl::desc("Number of seconds program is allowed to run before it "
"is killed (default is 300s), 0 disables timeout"));
+
+ cl::list<std::string>
+ AdditionalLinkerArgs("Xlinker",
+ cl::desc("Additional arguments to pass to the linker"));
}
namespace llvm {
if (!SharedObj.empty())
SharedObjs.push_back(SharedObj);
- // Actually execute the program!
- int RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
- OutputFile, SharedObjs, TimeoutValue);
+
+ // If this is an LLC or CBE run, then the GCC compiler might get run to
+ // compile the program. If so, we should pass the user's -Xlinker options
+ // as the GCCArgs.
+ int RetVal = 0;
+ if (InterpreterSel == RunLLC || InterpreterSel == RunCBE)
+ RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
+ OutputFile, AdditionalLinkerArgs, SharedObjs,
+ TimeoutValue);
+ else
+ RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
+ OutputFile, std::vector<std::string>(),
+ SharedObjs, TimeoutValue);
if (RetVal == -1) {
std::cerr << "<timeout>";
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
if (!SharedLibs.empty())
throw ToolExecutionError("LLI currently does not support "
"loading shared libraries.");
+ if (!GCCArgs.empty())
+ throw ToolExecutionError("LLI currently does not support "
+ "GCC Arguments.");
std::vector<const char*> LLIArgs;
LLIArgs.push_back(LLIPath.c_str());
LLIArgs.push_back("-force-interpreter=true");
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &ArgsForGCC,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
OutputAsm(Bytecode, OutputAsmFile);
FileRemover OutFileRemover(OutputAsmFile);
+ std::vector<std::string> GCCArgs(ArgsForGCC);
+ GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end());
+
// Assuming LLC worked, compile the result with GCC and run it.
return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile,
- InputFile, OutputFile, SharedLibs, Timeout);
+ InputFile, OutputFile, GCCArgs, Timeout);
}
/// createLLC - Try to find the LLC executable
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs =
+ std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
- std::vector<std::string>(), unsigned Timeout =0);
+ std::vector<std::string>(),
+ unsigned Timeout =0 );
};
}
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
+ if (!GCCArgs.empty())
+ throw ToolExecutionError("JIT does not support GCC Arguments.");
// Construct a vector of parameters, incorporating those from the command-line
std::vector<const char*> JITArgs;
JITArgs.push_back(LLIPath.c_str());
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &ArgsForGCC,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
sys::Path OutputCFile;
FileRemover CFileRemove(OutputCFile);
+ std::vector<std::string> GCCArgs(ArgsForGCC);
+ GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end());
return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
- InputFile, OutputFile, SharedLibs, Timeout);
+ InputFile, OutputFile, GCCArgs, Timeout);
}
/// createCBE - Try to find the 'llc' executable
FileType fileType,
const std::string &InputFile,
const std::string &OutputFile,
- const std::vector<std::string> &SharedLibs,
- unsigned Timeout) {
+ const std::vector<std::string> &ArgsForGCC,
+ unsigned Timeout ) {
std::vector<const char*> GCCArgs;
GCCArgs.push_back(GCCPath.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) {
sys::Path OutputBinary (ProgramFile+".gcc.exe");
OutputBinary.makeUnique();
GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file...
+
+ // Add any arguments intended for GCC. We locate them here because this is
+ // most likely -L and -l options that need to come before other libraries but
+ // after the source. Other options won't be sensitive to placement on the
+ // command line, so this should be safe.
+ for (unsigned i = 0, e = ArgsForGCC.size(); i != e; ++i)
+ GCCArgs.push_back(ArgsForGCC[i].c_str());
+
GCCArgs.push_back("-lm"); // Hard-code the math library...
GCCArgs.push_back("-O2"); // Optimize the program a bit...
#if defined (HAVE_LINK_R)
FileType fileType,
const std::string &InputFile,
const std::string &OutputFile,
- const std::vector<std::string> &SharedLibs =
- std::vector<std::string>(), unsigned Timeout = 0);
+ const std::vector<std::string> &GCCArgs =
+ std::vector<std::string>(),
+ unsigned Timeout = 0);
/// MakeSharedObject - This compiles the specified file (which is either a .c
/// file or a .s file) into a shared object.
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs =
+ std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0) = 0;
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs =
+ std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
+ const std::vector<std::string> &GCCArgs =
+ std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);