[llvm] r183908 - Reduce sys::Path usage in bugpoint.

Rafael Espindola rafael.espindola at gmail.com
Thu Jun 13 08:47:11 PDT 2013


Author: rafael
Date: Thu Jun 13 10:47:11 2013
New Revision: 183908

URL: http://llvm.org/viewvc/llvm-project?rev=183908&view=rev
Log:
Reduce sys::Path usage in bugpoint.

Modified:
    llvm/trunk/tools/bugpoint/ToolRunner.cpp

Modified: llvm/trunk/tools/bugpoint/ToolRunner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ToolRunner.cpp?rev=183908&r1=183907&r2=183908&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/ToolRunner.cpp (original)
+++ llvm/trunk/tools/bugpoint/ToolRunner.cpp Thu Jun 13 10:47:11 2013
@@ -53,18 +53,19 @@ namespace {
 /// RunProgramWithTimeout - This function provides an alternate interface
 /// to the sys::Program::ExecuteAndWait interface.
 /// @see sys::Program::ExecuteAndWait
-static int RunProgramWithTimeout(const sys::Path &ProgramPath,
+static int RunProgramWithTimeout(StringRef ProgramPath,
                                  const char **Args,
-                                 const sys::Path &StdInFile,
-                                 const sys::Path &StdOutFile,
-                                 const sys::Path &StdErrFile,
+                                 StringRef StdInFile,
+                                 StringRef StdOutFile,
+                                 StringRef StdErrFile,
                                  unsigned NumSeconds = 0,
                                  unsigned MemoryLimit = 0,
                                  std::string *ErrMsg = 0) {
+  const sys::Path P[3] = { sys::Path(StdInFile), sys::Path(StdOutFile),
+                           sys::Path(StdErrFile) };
   const sys::Path* redirects[3];
-  redirects[0] = &StdInFile;
-  redirects[1] = &StdOutFile;
-  redirects[2] = &StdErrFile;
+  for (int I = 0; I < 3; ++I)
+    redirects[I] = &P[I];
 
 #if 0 // For debug purposes
   {
@@ -75,8 +76,8 @@ static int RunProgramWithTimeout(const s
   }
 #endif
 
-  return sys::ExecuteAndWait(ProgramPath, Args, 0, redirects, NumSeconds,
-                             MemoryLimit, ErrMsg);
+  return sys::ExecuteAndWait(sys::Path(ProgramPath), Args, 0, redirects,
+                             NumSeconds, MemoryLimit, ErrMsg);
 }
 
 /// RunProgramRemotelyWithTimeout - This function runs the given program
@@ -85,17 +86,18 @@ static int RunProgramWithTimeout(const s
 /// fails. Remote client is required to return 255 if it failed or program exit
 /// code otherwise.
 /// @see sys::Program::ExecuteAndWait
-static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath,
+static int RunProgramRemotelyWithTimeout(StringRef RemoteClientPath,
                                          const char **Args,
-                                         const sys::Path &StdInFile,
-                                         const sys::Path &StdOutFile,
-                                         const sys::Path &StdErrFile,
+                                         StringRef StdInFile,
+                                         StringRef StdOutFile,
+                                         StringRef StdErrFile,
                                          unsigned NumSeconds = 0,
                                          unsigned MemoryLimit = 0) {
+  const sys::Path P[3] = { sys::Path(StdInFile), sys::Path(StdOutFile),
+                           sys::Path(StdErrFile) };
   const sys::Path* redirects[3];
-  redirects[0] = &StdInFile;
-  redirects[1] = &StdOutFile;
-  redirects[2] = &StdErrFile;
+  for (int I = 0; I < 3; ++I)
+    redirects[I] = &P[I];
 
 #if 0 // For debug purposes
   {
@@ -107,8 +109,8 @@ static int RunProgramRemotelyWithTimeout
 #endif
 
   // Run the program remotely with the remote client
-  int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, 0, redirects,
-                                       NumSeconds, MemoryLimit);
+  int ReturnCode = sys::ExecuteAndWait(sys::Path(RemoteClientPath), Args, 0,
+                                       redirects, NumSeconds, MemoryLimit);
 
   // Has the remote client fail?
   if (255 == ReturnCode) {
@@ -119,7 +121,7 @@ static int RunProgramRemotelyWithTimeout
     OS << "\n";
 
     // The error message is in the output file, let's print it out from there.
-    std::ifstream ErrorFile(StdOutFile.c_str());
+    std::ifstream ErrorFile(StdOutFile);
     if (ErrorFile) {
       std::copy(std::istreambuf_iterator<char>(ErrorFile),
                 std::istreambuf_iterator<char>(),
@@ -133,7 +135,7 @@ static int RunProgramRemotelyWithTimeout
   return ReturnCode;
 }
 
-static std::string ProcessFailure(sys::Path ProgPath, const char** Args,
+static std::string ProcessFailure(StringRef ProgPath, const char** Args,
                                   unsigned Timeout = 0,
                                   unsigned MemoryLimit = 0) {
   std::ostringstream OS;
@@ -149,8 +151,8 @@ static std::string ProcessFailure(sys::P
     errs() << "Error making unique filename: " << ErrMsg << "\n";
     exit(1);
   }
-  RunProgramWithTimeout(ProgPath, Args, sys::Path(""), ErrorFilename,
-                        ErrorFilename, Timeout, MemoryLimit);
+  RunProgramWithTimeout(ProgPath, Args, "", ErrorFilename.str(),
+                        ErrorFilename.str(), Timeout, MemoryLimit);
   // FIXME: check return code ?
 
   // Print out the error messages generated by GCC if possible...
@@ -228,8 +230,8 @@ int LLI::ExecuteProgram(const std::strin
           errs() << " " << LLIArgs[i];
         errs() << "\n";
         );
-  return RunProgramWithTimeout(sys::Path(LLIPath), &LLIArgs[0],
-      sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
+  return RunProgramWithTimeout(LLIPath, &LLIArgs[0],
+      InputFile, OutputFile, OutputFile,
       Timeout, MemoryLimit, Error);
 }
 
@@ -304,10 +306,10 @@ void CustomCompiler::compileProgram(cons
   for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i)
     ProgramArgs.push_back(CompilerArgs[i].c_str());
 
-  if (RunProgramWithTimeout( sys::Path(CompilerCommand), &ProgramArgs[0],
-                             sys::Path(), sys::Path(), sys::Path(),
+  if (RunProgramWithTimeout(CompilerCommand, &ProgramArgs[0],
+                             "", "", "",
                              Timeout, MemoryLimit, Error))
-    *Error = ProcessFailure(sys::Path(CompilerCommand), &ProgramArgs[0],
+    *Error = ProcessFailure(CompilerCommand, &ProgramArgs[0],
                            Timeout, MemoryLimit);
 }
 
@@ -362,9 +364,9 @@ int CustomExecutor::ExecuteProgram(const
     ProgramArgs.push_back(Args[i].c_str());
 
   return RunProgramWithTimeout(
-    sys::Path(ExecutionCommand),
-    &ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile),
-    sys::Path(OutputFile), Timeout, MemoryLimit, Error);
+    ExecutionCommand,
+    &ProgramArgs[0], InputFile, OutputFile,
+    OutputFile, Timeout, MemoryLimit, Error);
 }
 
 // Tokenize the CommandLine to the command and the args to allow
@@ -476,10 +478,10 @@ GCC::FileType LLC::OutputCode(const std:
           errs() << " " << LLCArgs[i];
         errs() << "\n";
         );
-  if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0],
-                            sys::Path(), sys::Path(), sys::Path(),
+  if (RunProgramWithTimeout(LLCPath, &LLCArgs[0],
+                            "", "", "",
                             Timeout, MemoryLimit))
-    Error = ProcessFailure(sys::Path(LLCPath), &LLCArgs[0],
+    Error = ProcessFailure(LLCPath, &LLCArgs[0],
                            Timeout, MemoryLimit);
   return UseIntegratedAssembler ? GCC::ObjectFile : GCC::AsmFile;
 }
@@ -602,8 +604,8 @@ int JIT::ExecuteProgram(const std::strin
         errs() << "\n";
         );
   DEBUG(errs() << "\nSending output to " << OutputFile << "\n");
-  return RunProgramWithTimeout(sys::Path(LLIPath), &JITArgs[0],
-      sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
+  return RunProgramWithTimeout(LLIPath, &JITArgs[0],
+      InputFile, OutputFile, OutputFile,
       Timeout, MemoryLimit, Error);
 }
 
@@ -711,9 +713,8 @@ int GCC::ExecuteProgram(const std::strin
           errs() << " " << GCCArgs[i];
         errs() << "\n";
         );
-  if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(),
-        sys::Path())) {
-    *Error = ProcessFailure(GCCPath, &GCCArgs[0]);
+  if (RunProgramWithTimeout(GCCPath.str(), &GCCArgs[0], "", "", "")) {
+    *Error = ProcessFailure(GCCPath.str(), &GCCArgs[0]);
     return -1;
   }
 
@@ -767,9 +768,9 @@ int GCC::ExecuteProgram(const std::strin
 
   if (RemoteClientPath.isEmpty()) {
     DEBUG(errs() << "<run locally>");
-    int ExitCode = RunProgramWithTimeout(OutputBinary, &ProgramArgs[0],
-        sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
-        Timeout, MemoryLimit, Error);
+    int ExitCode = RunProgramWithTimeout(OutputBinary.str(), &ProgramArgs[0],
+                                         InputFile, OutputFile, OutputFile,
+                                         Timeout, MemoryLimit, Error);
     // Treat a signal (usually SIGSEGV) or timeout as part of the program output
     // so that crash-causing miscompilation is handled seamlessly.
     if (ExitCode < -1) {
@@ -781,9 +782,9 @@ int GCC::ExecuteProgram(const std::strin
     return ExitCode;
   } else {
     outs() << "<run remotely>"; outs().flush();
-    return RunProgramRemotelyWithTimeout(sys::Path(RemoteClientPath),
-        &ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile),
-        sys::Path(OutputFile), Timeout, MemoryLimit);
+    return RunProgramRemotelyWithTimeout(RemoteClientPath.str(),
+        &ProgramArgs[0], InputFile, OutputFile,
+        OutputFile, Timeout, MemoryLimit);
   }
 }
 
@@ -861,9 +862,8 @@ int GCC::MakeSharedObject(const std::str
           errs() << " " << GCCArgs[i];
         errs() << "\n";
         );
-  if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(),
-                            sys::Path())) {
-    Error = ProcessFailure(GCCPath, &GCCArgs[0]);
+  if (RunProgramWithTimeout(GCCPath.str(), &GCCArgs[0], "", "", "")) {
+    Error = ProcessFailure(GCCPath.str(), &GCCArgs[0]);
     return 1;
   }
   return 0;





More information about the llvm-commits mailing list