Initialize X86 DataLayout based on the Triple only.
[oota-llvm.git] / tools / bugpoint / ToolRunner.cpp
index e1c995f519e0c8e484aa48c2d0331367bddee1e6..a28b2856f1e9cf0683e95ab91ace29c52b6f936a 100644 (file)
@@ -62,7 +62,7 @@ static int RunProgramWithTimeout(StringRef ProgramPath,
                                  StringRef StdErrFile,
                                  unsigned NumSeconds = 0,
                                  unsigned MemoryLimit = 0,
-                                 std::string *ErrMsg = 0) {
+                                 std::string *ErrMsg = nullptr) {
   const StringRef *Redirects[3] = { &StdInFile, &StdOutFile, &StdErrFile };
 
 #if 0 // For debug purposes
@@ -74,7 +74,7 @@ static int RunProgramWithTimeout(StringRef ProgramPath,
   }
 #endif
 
-  return sys::ExecuteAndWait(ProgramPath, Args, 0, Redirects,
+  return sys::ExecuteAndWait(ProgramPath, Args, nullptr, Redirects,
                              NumSeconds, MemoryLimit, ErrMsg);
 }
 
@@ -103,7 +103,7 @@ static int RunProgramRemotelyWithTimeout(StringRef RemoteClientPath,
 #endif
 
   // Run the program remotely with the remote client
-  int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, 0,
+  int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, nullptr,
                                        Redirects, NumSeconds, MemoryLimit);
 
   // Has the remote client fail?
@@ -142,12 +142,20 @@ static std::string ProcessFailure(StringRef ProgPath, const char** Args,
   // Rerun the compiler, capturing any error messages to print them.
   SmallString<128> ErrorFilename;
   int ErrorFD;
-  error_code EC = sys::fs::createTemporaryFile(
+  std::error_code EC = sys::fs::createTemporaryFile(
       "bugpoint.program_error_messages", "", ErrorFD, ErrorFilename);
   if (EC) {
     errs() << "Error making unique filename: " << EC.message() << "\n";
     exit(1);
   }
+
+#ifdef _WIN32
+  // Close ErrorFD immediately, or it couldn't be reopened on Win32.
+  // FIXME: We may have an option in openFileForWrite(), not to use ResultFD
+  // but to close it.
+  delete new raw_fd_ostream(ErrorFD, true);
+#endif
+
   RunProgramWithTimeout(ProgPath, Args, "", ErrorFilename.str(),
                         ErrorFilename.str(), Timeout, MemoryLimit);
   // FIXME: check return code ?
@@ -219,7 +227,7 @@ int LLI::ExecuteProgram(const std::string &Bitcode,
   // Add optional parameters to the running program from Argv
   for (unsigned i=0, e = Args.size(); i != e; ++i)
     LLIArgs.push_back(Args[i].c_str());
-  LLIArgs.push_back(0);
+  LLIArgs.push_back(nullptr);
 
   outs() << "<lli>"; outs().flush();
   DEBUG(errs() << "\nAbout to run:\t";
@@ -277,7 +285,7 @@ AbstractInterpreter *AbstractInterpreter::createLLI(const char *Argv0,
   }
 
   Message = "Cannot find `lli' in executable directory!\n";
-  return 0;
+  return nullptr;
 }
 
 //===---------------------------------------------------------------------===//
@@ -328,7 +336,7 @@ void CustomCompiler::compileProgram(const std::string &Bitcode,
   for (std::size_t i = 0; i < CompilerArgs.size(); ++i)
     ProgramArgs.push_back(CompilerArgs.at(i).c_str());
   ProgramArgs.push_back(Bitcode.c_str());
-  ProgramArgs.push_back(0);
+  ProgramArgs.push_back(nullptr);
 
   // Add optional parameters to the running program from Argv
   for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i)
@@ -385,7 +393,7 @@ int CustomExecutor::ExecuteProgram(const std::string &Bitcode,
   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(0);
+  ProgramArgs.push_back(nullptr);
 
   // Add optional parameters to the running program from Argv
   for (unsigned i = 0, e = Args.size(); i != e; ++i)
@@ -448,7 +456,7 @@ AbstractInterpreter *AbstractInterpreter::createCustomCompiler(
   std::vector<std::string> Args;
   lexCommand(Message, CompileCommandLine, CmdPath, Args);
   if (CmdPath.empty())
-    return 0;
+    return nullptr;
 
   return new CustomCompiler(CmdPath, Args);
 }
@@ -464,7 +472,7 @@ AbstractInterpreter *AbstractInterpreter::createCustomExecutor(
   std::vector<std::string> Args;
   lexCommand(Message, ExecCommandLine, CmdPath, Args);
   if (CmdPath.empty())
-    return 0;
+    return nullptr;
 
   return new CustomExecutor(CmdPath, Args);
 }
@@ -478,7 +486,7 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
   const char *Suffix = (UseIntegratedAssembler ? ".llc.o" : ".llc.s");
 
   SmallString<128> UniqueFile;
-  error_code EC =
+  std::error_code EC =
       sys::fs::createUniqueFile(Bitcode + "-%%%%%%%" + Suffix, UniqueFile);
   if (EC) {
     errs() << "Error making unique filename: " << EC.message() << "\n";
@@ -499,7 +507,7 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
   if (UseIntegratedAssembler)
     LLCArgs.push_back("-filetype=obj");
 
-  LLCArgs.push_back (0);
+  LLCArgs.push_back (nullptr);
 
   outs() << (UseIntegratedAssembler ? "<llc-ia>" : "<llc>");
   outs().flush();
@@ -559,7 +567,7 @@ LLC *AbstractInterpreter::createLLC(const char *Argv0,
       PrependMainExecutablePath("llc", Argv0, (void *)(intptr_t) & createLLC);
   if (LLCPath.empty()) {
     Message = "Cannot find `llc' in executable directory!\n";
-    return 0;
+    return nullptr;
   }
 
   GCC *gcc = GCC::create(Message, GCCBinary, GCCArgs);
@@ -625,7 +633,7 @@ int JIT::ExecuteProgram(const std::string &Bitcode,
   // Add optional parameters to the running program from Argv
   for (unsigned i=0, e = Args.size(); i != e; ++i)
     JITArgs.push_back(Args[i].c_str());
-  JITArgs.push_back(0);
+  JITArgs.push_back(nullptr);
 
   outs() << "<jit>"; outs().flush();
   DEBUG(errs() << "\nAbout to run:\t";
@@ -651,7 +659,7 @@ AbstractInterpreter *AbstractInterpreter::createJIT(const char *Argv0,
   }
 
   Message = "Cannot find `lli' in executable directory!\n";
-  return 0;
+  return nullptr;
 }
 
 //===---------------------------------------------------------------------===//
@@ -715,7 +723,7 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
   GCCArgs.push_back("-o");
 
   SmallString<128> OutputBinary;
-  error_code EC =
+  std::error_code EC =
       sys::fs::createUniqueFile(ProgramFile + "-%%%%%%%.gcc.exe", OutputBinary);
   if (EC) {
     errs() << "Error making unique filename: " << EC.message() << "\n";
@@ -737,7 +745,7 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
 #endif
   if (TargetTriple.getArch() == Triple::sparc)
     GCCArgs.push_back("-mcpu=v9");
-  GCCArgs.push_back(0);                    // NULL terminator
+  GCCArgs.push_back(nullptr);                    // NULL terminator
 
   outs() << "<gcc>"; outs().flush();
   DEBUG(errs() << "\nAbout to run:\t";
@@ -786,7 +794,7 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
   // Add optional parameters to the running program from Argv
   for (unsigned i = 0, e = Args.size(); i != e; ++i)
     ProgramArgs.push_back(Args[i].c_str());
-  ProgramArgs.push_back(0);                // NULL terminator
+  ProgramArgs.push_back(nullptr);                // NULL terminator
 
   // Now that we have a binary, run it!
   outs() << "<program>"; outs().flush();
@@ -825,7 +833,7 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
                           const std::vector<std::string> &ArgsForGCC,
                           std::string &Error) {
   SmallString<128> UniqueFilename;
-  error_code EC = sys::fs::createUniqueFile(
+  std::error_code EC = sys::fs::createUniqueFile(
       InputFile + "-%%%%%%%" + LTDL_SHLIB_EXT, UniqueFilename);
   if (EC) {
     errs() << "Error making unique filename: " << EC.message() << "\n";
@@ -885,7 +893,7 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
   // 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(0);                    // NULL terminator
+  GCCArgs.push_back(nullptr);                    // NULL terminator
 
 
 
@@ -910,7 +918,7 @@ GCC *GCC::create(std::string &Message,
   std::string GCCPath = sys::FindProgramByName(GCCBinary);
   if (GCCPath.empty()) {
     Message = "Cannot find `"+ GCCBinary +"' in PATH!\n";
-    return 0;
+    return nullptr;
   }
 
   std::string RemoteClientPath;