|
@@ -53,13 +53,14 @@ cl::opt<std::string>
|
|
/// RunProgramWithTimeout - This function provides an alternate interface
|
|
/// RunProgramWithTimeout - This function provides an alternate interface
|
|
/// to the sys::Program::ExecuteAndWait interface.
|
|
/// to the sys::Program::ExecuteAndWait interface.
|
|
/// @see sys::Program::ExecuteAndWait
|
|
/// @see sys::Program::ExecuteAndWait
|
|
-static int RunProgramWithTimeout(StringRef ProgramPath, const char **Args,
|
|
|
|
- StringRef StdInFile, StringRef StdOutFile,
|
|
|
|
- StringRef StdErrFile, unsigned NumSeconds = 0,
|
|
|
|
|
|
+static int RunProgramWithTimeout(StringRef ProgramPath,
|
|
|
|
+ ArrayRef<StringRef> Args, StringRef StdInFile,
|
|
|
|
+ StringRef StdOutFile, StringRef StdErrFile,
|
|
|
|
+ unsigned NumSeconds = 0,
|
|
unsigned MemoryLimit = 0,
|
|
unsigned MemoryLimit = 0,
|
|
std::string *ErrMsg = nullptr) {
|
|
std::string *ErrMsg = nullptr) {
|
|
Optional<StringRef> Redirects[3] = {StdInFile, StdOutFile, StdErrFile};
|
|
Optional<StringRef> Redirects[3] = {StdInFile, StdOutFile, StdErrFile};
|
|
- return sys::ExecuteAndWait(ProgramPath, Args, nullptr, Redirects, NumSeconds,
|
|
|
|
|
|
+ return sys::ExecuteAndWait(ProgramPath, Args, None, Redirects, NumSeconds,
|
|
MemoryLimit, ErrMsg);
|
|
MemoryLimit, ErrMsg);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -69,24 +70,22 @@ static int RunProgramWithTimeout(StringRef ProgramPath, const char **Args,
|
|
/// fails. Remote client is required to return 255 if it failed or program exit
|
|
/// fails. Remote client is required to return 255 if it failed or program exit
|
|
/// code otherwise.
|
|
/// code otherwise.
|
|
/// @see sys::Program::ExecuteAndWait
|
|
/// @see sys::Program::ExecuteAndWait
|
|
-static int RunProgramRemotelyWithTimeout(StringRef RemoteClientPath,
|
|
|
|
- const char **Args, StringRef StdInFile,
|
|
|
|
- StringRef StdOutFile,
|
|
|
|
- StringRef StdErrFile,
|
|
|
|
- unsigned NumSeconds = 0,
|
|
|
|
- unsigned MemoryLimit = 0) {
|
|
|
|
|
|
+static int RunProgramRemotelyWithTimeout(
|
|
|
|
+ StringRef RemoteClientPath, ArrayRef<StringRef> Args, StringRef StdInFile,
|
|
|
|
+ StringRef StdOutFile, StringRef StdErrFile, unsigned NumSeconds = 0,
|
|
|
|
+ unsigned MemoryLimit = 0) {
|
|
Optional<StringRef> Redirects[3] = {StdInFile, StdOutFile, StdErrFile};
|
|
Optional<StringRef> Redirects[3] = {StdInFile, StdOutFile, StdErrFile};
|
|
|
|
|
|
// Run the program remotely with the remote client
|
|
// Run the program remotely with the remote client
|
|
- int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, nullptr,
|
|
|
|
- Redirects, NumSeconds, MemoryLimit);
|
|
|
|
|
|
+ int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, None, Redirects,
|
|
|
|
+ NumSeconds, MemoryLimit);
|
|
|
|
|
|
// Has the remote client fail?
|
|
// Has the remote client fail?
|
|
if (255 == ReturnCode) {
|
|
if (255 == ReturnCode) {
|
|
std::ostringstream OS;
|
|
std::ostringstream OS;
|
|
OS << "\nError running remote client:\n ";
|
|
OS << "\nError running remote client:\n ";
|
|
- for (const char **Arg = Args; *Arg; ++Arg)
|
|
|
|
- OS << " " << *Arg;
|
|
|
|
|
|
+ for (StringRef Arg : Args)
|
|
|
|
+ OS << " " << Arg.str();
|
|
OS << "\n";
|
|
OS << "\n";
|
|
|
|
|
|
// The error message is in the output file, let's print it out from there.
|
|
// The error message is in the output file, let's print it out from there.
|
|
@@ -105,12 +104,12 @@ static int RunProgramRemotelyWithTimeout(StringRef RemoteClientPath,
|
|
return ReturnCode;
|
|
return ReturnCode;
|
|
}
|
|
}
|
|
|
|
|
|
-static Error ProcessFailure(StringRef ProgPath, const char **Args,
|
|
|
|
|
|
+static Error ProcessFailure(StringRef ProgPath, ArrayRef<StringRef> Args,
|
|
unsigned Timeout = 0, unsigned MemoryLimit = 0) {
|
|
unsigned Timeout = 0, unsigned MemoryLimit = 0) {
|
|
std::ostringstream OS;
|
|
std::ostringstream OS;
|
|
OS << "\nError running tool:\n ";
|
|
OS << "\nError running tool:\n ";
|
|
- for (const char **Arg = Args; *Arg; ++Arg)
|
|
|
|
- OS << " " << *Arg;
|
|
|
|
|
|
+ for (StringRef Arg : Args)
|
|
|
|
+ OS << " " << Arg.str();
|
|
OS << "\n";
|
|
OS << "\n";
|
|
|
|
|
|
// Rerun the compiler, capturing any error messages to print them.
|
|
// Rerun the compiler, capturing any error messages to print them.
|
|
@@ -171,7 +170,7 @@ Expected<int> LLI::ExecuteProgram(const std::string &Bitcode,
|
|
const std::vector<std::string> &CCArgs,
|
|
const std::vector<std::string> &CCArgs,
|
|
const std::vector<std::string> &SharedLibs,
|
|
const std::vector<std::string> &SharedLibs,
|
|
unsigned Timeout, unsigned MemoryLimit) {
|
|
unsigned Timeout, unsigned MemoryLimit) {
|
|
- std::vector<const char *> LLIArgs;
|
|
|
|
|
|
+ std::vector<StringRef> LLIArgs;
|
|
LLIArgs.push_back(LLIPath.c_str());
|
|
LLIArgs.push_back(LLIPath.c_str());
|
|
LLIArgs.push_back("-force-interpreter=true");
|
|
LLIArgs.push_back("-force-interpreter=true");
|
|
|
|
|
|
@@ -179,18 +178,17 @@ Expected<int> LLI::ExecuteProgram(const std::string &Bitcode,
|
|
e = SharedLibs.end();
|
|
e = SharedLibs.end();
|
|
i != e; ++i) {
|
|
i != e; ++i) {
|
|
LLIArgs.push_back("-load");
|
|
LLIArgs.push_back("-load");
|
|
- LLIArgs.push_back((*i).c_str());
|
|
|
|
|
|
+ LLIArgs.push_back(*i);
|
|
}
|
|
}
|
|
|
|
|
|
// Add any extra LLI args.
|
|
// Add any extra LLI args.
|
|
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
|
|
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
|
|
- LLIArgs.push_back(ToolArgs[i].c_str());
|
|
|
|
|
|
+ LLIArgs.push_back(ToolArgs[i]);
|
|
|
|
|
|
- LLIArgs.push_back(Bitcode.c_str());
|
|
|
|
|
|
+ LLIArgs.push_back(Bitcode);
|
|
// Add optional parameters to the running program from Argv
|
|
// Add optional parameters to the running program from Argv
|
|
for (unsigned i = 0, e = Args.size(); i != e; ++i)
|
|
for (unsigned i = 0, e = Args.size(); i != e; ++i)
|
|
- LLIArgs.push_back(Args[i].c_str());
|
|
|
|
- LLIArgs.push_back(nullptr);
|
|
|
|
|
|
+ LLIArgs.push_back(Args[i]);
|
|
|
|
|
|
outs() << "<lli>";
|
|
outs() << "<lli>";
|
|
outs().flush();
|
|
outs().flush();
|
|
@@ -198,7 +196,7 @@ Expected<int> LLI::ExecuteProgram(const std::string &Bitcode,
|
|
for (unsigned i = 0, e = LLIArgs.size() - 1; i != e; ++i) errs()
|
|
for (unsigned i = 0, e = LLIArgs.size() - 1; i != e; ++i) errs()
|
|
<< " " << LLIArgs[i];
|
|
<< " " << LLIArgs[i];
|
|
errs() << "\n";);
|
|
errs() << "\n";);
|
|
- return RunProgramWithTimeout(LLIPath, &LLIArgs[0], InputFile, OutputFile,
|
|
|
|
|
|
+ return RunProgramWithTimeout(LLIPath, LLIArgs, InputFile, OutputFile,
|
|
OutputFile, Timeout, MemoryLimit);
|
|
OutputFile, Timeout, MemoryLimit);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -285,22 +283,20 @@ public:
|
|
Error CustomCompiler::compileProgram(const std::string &Bitcode,
|
|
Error CustomCompiler::compileProgram(const std::string &Bitcode,
|
|
unsigned Timeout, unsigned MemoryLimit) {
|
|
unsigned Timeout, unsigned MemoryLimit) {
|
|
|
|
|
|
- std::vector<const char *> ProgramArgs;
|
|
|
|
|
|
+ std::vector<StringRef> ProgramArgs;
|
|
ProgramArgs.push_back(CompilerCommand.c_str());
|
|
ProgramArgs.push_back(CompilerCommand.c_str());
|
|
|
|
|
|
for (std::size_t i = 0; i < CompilerArgs.size(); ++i)
|
|
for (std::size_t i = 0; i < CompilerArgs.size(); ++i)
|
|
ProgramArgs.push_back(CompilerArgs.at(i).c_str());
|
|
ProgramArgs.push_back(CompilerArgs.at(i).c_str());
|
|
- ProgramArgs.push_back(Bitcode.c_str());
|
|
|
|
- ProgramArgs.push_back(nullptr);
|
|
|
|
|
|
+ ProgramArgs.push_back(Bitcode);
|
|
|
|
|
|
// Add optional parameters to the running program from Argv
|
|
// Add optional parameters to the running program from Argv
|
|
for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i)
|
|
for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i)
|
|
ProgramArgs.push_back(CompilerArgs[i].c_str());
|
|
ProgramArgs.push_back(CompilerArgs[i].c_str());
|
|
|
|
|
|
- if (RunProgramWithTimeout(CompilerCommand, &ProgramArgs[0], "", "", "",
|
|
|
|
- Timeout, MemoryLimit))
|
|
|
|
- return ProcessFailure(CompilerCommand, &ProgramArgs[0], Timeout,
|
|
|
|
- MemoryLimit);
|
|
|
|
|
|
+ if (RunProgramWithTimeout(CompilerCommand, ProgramArgs, "", "", "", Timeout,
|
|
|
|
+ MemoryLimit))
|
|
|
|
+ return ProcessFailure(CompilerCommand, ProgramArgs, Timeout, MemoryLimit);
|
|
return Error::success();
|
|
return Error::success();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -336,19 +332,18 @@ Expected<int> CustomExecutor::ExecuteProgram(
|
|
const std::vector<std::string> &SharedLibs, unsigned Timeout,
|
|
const std::vector<std::string> &SharedLibs, unsigned Timeout,
|
|
unsigned MemoryLimit) {
|
|
unsigned MemoryLimit) {
|
|
|
|
|
|
- std::vector<const char *> ProgramArgs;
|
|
|
|
- ProgramArgs.push_back(ExecutionCommand.c_str());
|
|
|
|
|
|
+ std::vector<StringRef> ProgramArgs;
|
|
|
|
+ ProgramArgs.push_back(ExecutionCommand);
|
|
|
|
|
|
for (std::size_t i = 0; i < ExecutorArgs.size(); ++i)
|
|
for (std::size_t i = 0; i < ExecutorArgs.size(); ++i)
|
|
- ProgramArgs.push_back(ExecutorArgs.at(i).c_str());
|
|
|
|
- ProgramArgs.push_back(Bitcode.c_str());
|
|
|
|
- ProgramArgs.push_back(nullptr);
|
|
|
|
|
|
+ ProgramArgs.push_back(ExecutorArgs[i]);
|
|
|
|
+ ProgramArgs.push_back(Bitcode);
|
|
|
|
|
|
// Add optional parameters to the running program from Argv
|
|
// Add optional parameters to the running program from Argv
|
|
for (unsigned i = 0, e = Args.size(); i != e; ++i)
|
|
for (unsigned i = 0, e = Args.size(); i != e; ++i)
|
|
- ProgramArgs.push_back(Args[i].c_str());
|
|
|
|
|
|
+ ProgramArgs.push_back(Args[i]);
|
|
|
|
|
|
- return RunProgramWithTimeout(ExecutionCommand, &ProgramArgs[0], InputFile,
|
|
|
|
|
|
+ return RunProgramWithTimeout(ExecutionCommand, ProgramArgs, InputFile,
|
|
OutputFile, OutputFile, Timeout, MemoryLimit);
|
|
OutputFile, OutputFile, Timeout, MemoryLimit);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -463,31 +458,28 @@ Expected<CC::FileType> LLC::OutputCode(const std::string &Bitcode,
|
|
exit(1);
|
|
exit(1);
|
|
}
|
|
}
|
|
OutputAsmFile = UniqueFile.str();
|
|
OutputAsmFile = UniqueFile.str();
|
|
- std::vector<const char *> LLCArgs;
|
|
|
|
- LLCArgs.push_back(LLCPath.c_str());
|
|
|
|
|
|
+ std::vector<StringRef> LLCArgs;
|
|
|
|
+ LLCArgs.push_back(LLCPath);
|
|
|
|
|
|
// Add any extra LLC args.
|
|
// Add any extra LLC args.
|
|
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
|
|
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
|
|
- LLCArgs.push_back(ToolArgs[i].c_str());
|
|
|
|
|
|
+ LLCArgs.push_back(ToolArgs[i]);
|
|
|
|
|
|
LLCArgs.push_back("-o");
|
|
LLCArgs.push_back("-o");
|
|
- LLCArgs.push_back(OutputAsmFile.c_str()); // Output to the Asm file
|
|
|
|
- LLCArgs.push_back(Bitcode.c_str()); // This is the input bitcode
|
|
|
|
|
|
+ LLCArgs.push_back(OutputAsmFile); // Output to the Asm file
|
|
|
|
+ LLCArgs.push_back(Bitcode); // This is the input bitcode
|
|
|
|
|
|
if (UseIntegratedAssembler)
|
|
if (UseIntegratedAssembler)
|
|
LLCArgs.push_back("-filetype=obj");
|
|
LLCArgs.push_back("-filetype=obj");
|
|
|
|
|
|
- LLCArgs.push_back(nullptr);
|
|
|
|
-
|
|
|
|
outs() << (UseIntegratedAssembler ? "<llc-ia>" : "<llc>");
|
|
outs() << (UseIntegratedAssembler ? "<llc-ia>" : "<llc>");
|
|
outs().flush();
|
|
outs().flush();
|
|
LLVM_DEBUG(errs() << "\nAbout to run:\t";
|
|
LLVM_DEBUG(errs() << "\nAbout to run:\t";
|
|
for (unsigned i = 0, e = LLCArgs.size() - 1; i != e; ++i) errs()
|
|
for (unsigned i = 0, e = LLCArgs.size() - 1; i != e; ++i) errs()
|
|
<< " " << LLCArgs[i];
|
|
<< " " << LLCArgs[i];
|
|
errs() << "\n";);
|
|
errs() << "\n";);
|
|
- if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], "", "", "", Timeout,
|
|
|
|
- MemoryLimit))
|
|
|
|
- return ProcessFailure(LLCPath, &LLCArgs[0], Timeout, MemoryLimit);
|
|
|
|
|
|
+ if (RunProgramWithTimeout(LLCPath, LLCArgs, "", "", "", Timeout, MemoryLimit))
|
|
|
|
+ return ProcessFailure(LLCPath, LLCArgs, Timeout, MemoryLimit);
|
|
return UseIntegratedAssembler ? CC::ObjectFile : CC::AsmFile;
|
|
return UseIntegratedAssembler ? CC::ObjectFile : CC::AsmFile;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -581,23 +573,22 @@ Expected<int> JIT::ExecuteProgram(const std::string &Bitcode,
|
|
const std::vector<std::string> &SharedLibs,
|
|
const std::vector<std::string> &SharedLibs,
|
|
unsigned Timeout, unsigned MemoryLimit) {
|
|
unsigned Timeout, unsigned MemoryLimit) {
|
|
// Construct a vector of parameters, incorporating those from the command-line
|
|
// Construct a vector of parameters, incorporating those from the command-line
|
|
- std::vector<const char *> JITArgs;
|
|
|
|
|
|
+ std::vector<StringRef> JITArgs;
|
|
JITArgs.push_back(LLIPath.c_str());
|
|
JITArgs.push_back(LLIPath.c_str());
|
|
JITArgs.push_back("-force-interpreter=false");
|
|
JITArgs.push_back("-force-interpreter=false");
|
|
|
|
|
|
// Add any extra LLI args.
|
|
// Add any extra LLI args.
|
|
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
|
|
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
|
|
- JITArgs.push_back(ToolArgs[i].c_str());
|
|
|
|
|
|
+ JITArgs.push_back(ToolArgs[i]);
|
|
|
|
|
|
for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i) {
|
|
for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i) {
|
|
JITArgs.push_back("-load");
|
|
JITArgs.push_back("-load");
|
|
- JITArgs.push_back(SharedLibs[i].c_str());
|
|
|
|
|
|
+ JITArgs.push_back(SharedLibs[i]);
|
|
}
|
|
}
|
|
JITArgs.push_back(Bitcode.c_str());
|
|
JITArgs.push_back(Bitcode.c_str());
|
|
// Add optional parameters to the running program from Argv
|
|
// Add optional parameters to the running program from Argv
|
|
for (unsigned i = 0, e = Args.size(); i != e; ++i)
|
|
for (unsigned i = 0, e = Args.size(); i != e; ++i)
|
|
- JITArgs.push_back(Args[i].c_str());
|
|
|
|
- JITArgs.push_back(nullptr);
|
|
|
|
|
|
+ JITArgs.push_back(Args[i]);
|
|
|
|
|
|
outs() << "<jit>";
|
|
outs() << "<jit>";
|
|
outs().flush();
|
|
outs().flush();
|
|
@@ -606,7 +597,7 @@ Expected<int> JIT::ExecuteProgram(const std::string &Bitcode,
|
|
<< " " << JITArgs[i];
|
|
<< " " << JITArgs[i];
|
|
errs() << "\n";);
|
|
errs() << "\n";);
|
|
LLVM_DEBUG(errs() << "\nSending output to " << OutputFile << "\n");
|
|
LLVM_DEBUG(errs() << "\nSending output to " << OutputFile << "\n");
|
|
- return RunProgramWithTimeout(LLIPath, &JITArgs[0], InputFile, OutputFile,
|
|
|
|
|
|
+ return RunProgramWithTimeout(LLIPath, JITArgs, InputFile, OutputFile,
|
|
OutputFile, Timeout, MemoryLimit);
|
|
OutputFile, Timeout, MemoryLimit);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -630,15 +621,15 @@ AbstractInterpreter::createJIT(const char *Argv0, std::string &Message,
|
|
// CC abstraction
|
|
// CC abstraction
|
|
//
|
|
//
|
|
|
|
|
|
-static bool IsARMArchitecture(std::vector<const char *> Args) {
|
|
|
|
- for (std::vector<const char *>::const_iterator I = Args.begin(),
|
|
|
|
- E = Args.end();
|
|
|
|
- I != E; ++I) {
|
|
|
|
- if (StringRef(*I).equals_lower("-arch")) {
|
|
|
|
- ++I;
|
|
|
|
- if (I != E && StringRef(*I).startswith_lower("arm"))
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
|
|
+static bool IsARMArchitecture(std::vector<StringRef> Args) {
|
|
|
|
+ for (size_t I = 0; I < Args.size(); ++I) {
|
|
|
|
+ if (!Args[I].equals_lower("-arch"))
|
|
|
|
+ continue;
|
|
|
|
+ ++I;
|
|
|
|
+ if (I == Args.size())
|
|
|
|
+ break;
|
|
|
|
+ if (Args[I].startswith_lower("arm"))
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
return false;
|
|
return false;
|
|
@@ -651,9 +642,9 @@ Expected<int> CC::ExecuteProgram(const std::string &ProgramFile,
|
|
const std::string &OutputFile,
|
|
const std::string &OutputFile,
|
|
const std::vector<std::string> &ArgsForCC,
|
|
const std::vector<std::string> &ArgsForCC,
|
|
unsigned Timeout, unsigned MemoryLimit) {
|
|
unsigned Timeout, unsigned MemoryLimit) {
|
|
- std::vector<const char *> CCArgs;
|
|
|
|
|
|
+ std::vector<StringRef> CCArgs;
|
|
|
|
|
|
- CCArgs.push_back(CCPath.c_str());
|
|
|
|
|
|
+ CCArgs.push_back(CCPath);
|
|
|
|
|
|
if (TargetTriple.getArch() == Triple::x86)
|
|
if (TargetTriple.getArch() == Triple::x86)
|
|
CCArgs.push_back("-m32");
|
|
CCArgs.push_back("-m32");
|
|
@@ -661,7 +652,7 @@ Expected<int> CC::ExecuteProgram(const std::string &ProgramFile,
|
|
for (std::vector<std::string>::const_iterator I = ccArgs.begin(),
|
|
for (std::vector<std::string>::const_iterator I = ccArgs.begin(),
|
|
E = ccArgs.end();
|
|
E = ccArgs.end();
|
|
I != E; ++I)
|
|
I != E; ++I)
|
|
- CCArgs.push_back(I->c_str());
|
|
|
|
|
|
+ CCArgs.push_back(*I);
|
|
|
|
|
|
// Specify -x explicitly in case the extension is wonky
|
|
// Specify -x explicitly in case the extension is wonky
|
|
if (fileType != ObjectFile) {
|
|
if (fileType != ObjectFile) {
|
|
@@ -680,7 +671,7 @@ Expected<int> CC::ExecuteProgram(const std::string &ProgramFile,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- CCArgs.push_back(ProgramFile.c_str()); // Specify the input filename.
|
|
|
|
|
|
+ CCArgs.push_back(ProgramFile); // Specify the input filename.
|
|
|
|
|
|
CCArgs.push_back("-x");
|
|
CCArgs.push_back("-x");
|
|
CCArgs.push_back("none");
|
|
CCArgs.push_back("none");
|
|
@@ -693,20 +684,19 @@ Expected<int> CC::ExecuteProgram(const std::string &ProgramFile,
|
|
errs() << "Error making unique filename: " << EC.message() << "\n";
|
|
errs() << "Error making unique filename: " << EC.message() << "\n";
|
|
exit(1);
|
|
exit(1);
|
|
}
|
|
}
|
|
- CCArgs.push_back(OutputBinary.c_str()); // Output to the right file...
|
|
|
|
|
|
+ CCArgs.push_back(OutputBinary); // Output to the right file...
|
|
|
|
|
|
// Add any arguments intended for CC. We locate them here because this is
|
|
// Add any arguments intended for CC. We locate them here because this is
|
|
// most likely -L and -l options that need to come before other libraries but
|
|
// 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
|
|
// after the source. Other options won't be sensitive to placement on the
|
|
// command line, so this should be safe.
|
|
// command line, so this should be safe.
|
|
for (unsigned i = 0, e = ArgsForCC.size(); i != e; ++i)
|
|
for (unsigned i = 0, e = ArgsForCC.size(); i != e; ++i)
|
|
- CCArgs.push_back(ArgsForCC[i].c_str());
|
|
|
|
|
|
+ CCArgs.push_back(ArgsForCC[i]);
|
|
|
|
|
|
CCArgs.push_back("-lm"); // Hard-code the math library...
|
|
CCArgs.push_back("-lm"); // Hard-code the math library...
|
|
CCArgs.push_back("-O2"); // Optimize the program a bit...
|
|
CCArgs.push_back("-O2"); // Optimize the program a bit...
|
|
if (TargetTriple.getArch() == Triple::sparc)
|
|
if (TargetTriple.getArch() == Triple::sparc)
|
|
CCArgs.push_back("-mcpu=v9");
|
|
CCArgs.push_back("-mcpu=v9");
|
|
- CCArgs.push_back(nullptr); // NULL terminator
|
|
|
|
|
|
|
|
outs() << "<CC>";
|
|
outs() << "<CC>";
|
|
outs().flush();
|
|
outs().flush();
|
|
@@ -714,30 +704,30 @@ Expected<int> CC::ExecuteProgram(const std::string &ProgramFile,
|
|
for (unsigned i = 0, e = CCArgs.size() - 1; i != e; ++i) errs()
|
|
for (unsigned i = 0, e = CCArgs.size() - 1; i != e; ++i) errs()
|
|
<< " " << CCArgs[i];
|
|
<< " " << CCArgs[i];
|
|
errs() << "\n";);
|
|
errs() << "\n";);
|
|
- if (RunProgramWithTimeout(CCPath, &CCArgs[0], "", "", ""))
|
|
|
|
- return ProcessFailure(CCPath, &CCArgs[0]);
|
|
|
|
|
|
+ if (RunProgramWithTimeout(CCPath, CCArgs, "", "", ""))
|
|
|
|
+ return ProcessFailure(CCPath, CCArgs);
|
|
|
|
|
|
- std::vector<const char *> ProgramArgs;
|
|
|
|
|
|
+ std::vector<StringRef> ProgramArgs;
|
|
|
|
|
|
// Declared here so that the destructor only runs after
|
|
// Declared here so that the destructor only runs after
|
|
// ProgramArgs is used.
|
|
// ProgramArgs is used.
|
|
std::string Exec;
|
|
std::string Exec;
|
|
|
|
|
|
if (RemoteClientPath.empty())
|
|
if (RemoteClientPath.empty())
|
|
- ProgramArgs.push_back(OutputBinary.c_str());
|
|
|
|
|
|
+ ProgramArgs.push_back(OutputBinary);
|
|
else {
|
|
else {
|
|
- ProgramArgs.push_back(RemoteClientPath.c_str());
|
|
|
|
- ProgramArgs.push_back(RemoteHost.c_str());
|
|
|
|
|
|
+ ProgramArgs.push_back(RemoteClientPath);
|
|
|
|
+ ProgramArgs.push_back(RemoteHost);
|
|
if (!RemoteUser.empty()) {
|
|
if (!RemoteUser.empty()) {
|
|
ProgramArgs.push_back("-l");
|
|
ProgramArgs.push_back("-l");
|
|
- ProgramArgs.push_back(RemoteUser.c_str());
|
|
|
|
|
|
+ ProgramArgs.push_back(RemoteUser);
|
|
}
|
|
}
|
|
if (!RemotePort.empty()) {
|
|
if (!RemotePort.empty()) {
|
|
ProgramArgs.push_back("-p");
|
|
ProgramArgs.push_back("-p");
|
|
- ProgramArgs.push_back(RemotePort.c_str());
|
|
|
|
|
|
+ ProgramArgs.push_back(RemotePort);
|
|
}
|
|
}
|
|
if (!RemoteExtra.empty()) {
|
|
if (!RemoteExtra.empty()) {
|
|
- ProgramArgs.push_back(RemoteExtra.c_str());
|
|
|
|
|
|
+ ProgramArgs.push_back(RemoteExtra);
|
|
}
|
|
}
|
|
|
|
|
|
// Full path to the binary. We need to cd to the exec directory because
|
|
// Full path to the binary. We need to cd to the exec directory because
|
|
@@ -747,13 +737,12 @@ Expected<int> CC::ExecuteProgram(const std::string &ProgramFile,
|
|
Exec += env_pwd;
|
|
Exec += env_pwd;
|
|
Exec += "; ./";
|
|
Exec += "; ./";
|
|
Exec += OutputBinary.c_str();
|
|
Exec += OutputBinary.c_str();
|
|
- ProgramArgs.push_back(Exec.c_str());
|
|
|
|
|
|
+ ProgramArgs.push_back(Exec);
|
|
}
|
|
}
|
|
|
|
|
|
// Add optional parameters to the running program from Argv
|
|
// Add optional parameters to the running program from Argv
|
|
for (unsigned i = 0, e = Args.size(); i != e; ++i)
|
|
for (unsigned i = 0, e = Args.size(); i != e; ++i)
|
|
- ProgramArgs.push_back(Args[i].c_str());
|
|
|
|
- ProgramArgs.push_back(nullptr); // NULL terminator
|
|
|
|
|
|
+ ProgramArgs.push_back(Args[i]);
|
|
|
|
|
|
// Now that we have a binary, run it!
|
|
// Now that we have a binary, run it!
|
|
outs() << "<program>";
|
|
outs() << "<program>";
|
|
@@ -769,7 +758,7 @@ Expected<int> CC::ExecuteProgram(const std::string &ProgramFile,
|
|
if (RemoteClientPath.empty()) {
|
|
if (RemoteClientPath.empty()) {
|
|
LLVM_DEBUG(errs() << "<run locally>");
|
|
LLVM_DEBUG(errs() << "<run locally>");
|
|
std::string Error;
|
|
std::string Error;
|
|
- int ExitCode = RunProgramWithTimeout(OutputBinary.str(), &ProgramArgs[0],
|
|
|
|
|
|
+ int ExitCode = RunProgramWithTimeout(OutputBinary.str(), ProgramArgs,
|
|
InputFile, OutputFile, OutputFile,
|
|
InputFile, OutputFile, OutputFile,
|
|
Timeout, MemoryLimit, &Error);
|
|
Timeout, MemoryLimit, &Error);
|
|
// Treat a signal (usually SIGSEGV) or timeout as part of the program output
|
|
// Treat a signal (usually SIGSEGV) or timeout as part of the program output
|
|
@@ -783,7 +772,7 @@ Expected<int> CC::ExecuteProgram(const std::string &ProgramFile,
|
|
} else {
|
|
} else {
|
|
outs() << "<run remotely>";
|
|
outs() << "<run remotely>";
|
|
outs().flush();
|
|
outs().flush();
|
|
- return RunProgramRemotelyWithTimeout(RemoteClientPath, &ProgramArgs[0],
|
|
|
|
|
|
+ return RunProgramRemotelyWithTimeout(RemoteClientPath, ProgramArgs,
|
|
InputFile, OutputFile, OutputFile,
|
|
InputFile, OutputFile, OutputFile,
|
|
Timeout, MemoryLimit);
|
|
Timeout, MemoryLimit);
|
|
}
|
|
}
|
|
@@ -801,9 +790,9 @@ Error CC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|
}
|
|
}
|
|
OutputFile = UniqueFilename.str();
|
|
OutputFile = UniqueFilename.str();
|
|
|
|
|
|
- std::vector<const char *> CCArgs;
|
|
|
|
|
|
+ std::vector<StringRef> CCArgs;
|
|
|
|
|
|
- CCArgs.push_back(CCPath.c_str());
|
|
|
|
|
|
+ CCArgs.push_back(CCPath);
|
|
|
|
|
|
if (TargetTriple.getArch() == Triple::x86)
|
|
if (TargetTriple.getArch() == Triple::x86)
|
|
CCArgs.push_back("-m32");
|
|
CCArgs.push_back("-m32");
|
|
@@ -811,7 +800,7 @@ Error CC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|
for (std::vector<std::string>::const_iterator I = ccArgs.begin(),
|
|
for (std::vector<std::string>::const_iterator I = ccArgs.begin(),
|
|
E = ccArgs.end();
|
|
E = ccArgs.end();
|
|
I != E; ++I)
|
|
I != E; ++I)
|
|
- CCArgs.push_back(I->c_str());
|
|
|
|
|
|
+ CCArgs.push_back(*I);
|
|
|
|
|
|
// Compile the C/asm file into a shared object
|
|
// Compile the C/asm file into a shared object
|
|
if (fileType != ObjectFile) {
|
|
if (fileType != ObjectFile) {
|
|
@@ -819,7 +808,7 @@ Error CC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|
CCArgs.push_back(fileType == AsmFile ? "assembler" : "c");
|
|
CCArgs.push_back(fileType == AsmFile ? "assembler" : "c");
|
|
}
|
|
}
|
|
CCArgs.push_back("-fno-strict-aliasing");
|
|
CCArgs.push_back("-fno-strict-aliasing");
|
|
- CCArgs.push_back(InputFile.c_str()); // Specify the input filename.
|
|
|
|
|
|
+ CCArgs.push_back(InputFile); // Specify the input filename.
|
|
CCArgs.push_back("-x");
|
|
CCArgs.push_back("-x");
|
|
CCArgs.push_back("none");
|
|
CCArgs.push_back("none");
|
|
if (TargetTriple.getArch() == Triple::sparc)
|
|
if (TargetTriple.getArch() == Triple::sparc)
|
|
@@ -843,7 +832,7 @@ Error CC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|
CCArgs.push_back("-mcpu=v9");
|
|
CCArgs.push_back("-mcpu=v9");
|
|
|
|
|
|
CCArgs.push_back("-o");
|
|
CCArgs.push_back("-o");
|
|
- CCArgs.push_back(OutputFile.c_str()); // Output to the right filename.
|
|
|
|
|
|
+ CCArgs.push_back(OutputFile); // Output to the right filename.
|
|
CCArgs.push_back("-O2"); // Optimize the program a bit.
|
|
CCArgs.push_back("-O2"); // Optimize the program a bit.
|
|
|
|
|
|
// Add any arguments intended for CC. We locate them here because this is
|
|
// Add any arguments intended for CC. We locate them here because this is
|
|
@@ -851,8 +840,7 @@ Error CC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|
// after the source. Other options won't be sensitive to placement on the
|
|
// after the source. Other options won't be sensitive to placement on the
|
|
// command line, so this should be safe.
|
|
// command line, so this should be safe.
|
|
for (unsigned i = 0, e = ArgsForCC.size(); i != e; ++i)
|
|
for (unsigned i = 0, e = ArgsForCC.size(); i != e; ++i)
|
|
- CCArgs.push_back(ArgsForCC[i].c_str());
|
|
|
|
- CCArgs.push_back(nullptr); // NULL terminator
|
|
|
|
|
|
+ CCArgs.push_back(ArgsForCC[i]);
|
|
|
|
|
|
outs() << "<CC>";
|
|
outs() << "<CC>";
|
|
outs().flush();
|
|
outs().flush();
|
|
@@ -860,8 +848,8 @@ Error CC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|
for (unsigned i = 0, e = CCArgs.size() - 1; i != e; ++i) errs()
|
|
for (unsigned i = 0, e = CCArgs.size() - 1; i != e; ++i) errs()
|
|
<< " " << CCArgs[i];
|
|
<< " " << CCArgs[i];
|
|
errs() << "\n";);
|
|
errs() << "\n";);
|
|
- if (RunProgramWithTimeout(CCPath, &CCArgs[0], "", "", ""))
|
|
|
|
- return ProcessFailure(CCPath, &CCArgs[0]);
|
|
|
|
|
|
+ if (RunProgramWithTimeout(CCPath, CCArgs, "", "", ""))
|
|
|
|
+ return ProcessFailure(CCPath, CCArgs);
|
|
return Error::success();
|
|
return Error::success();
|
|
}
|
|
}
|
|
|
|
|