use early exits to reduce indentation.
[oota-llvm.git] / tools / bugpoint / ToolRunner.cpp
index 01afc20bad0b424bca7f526ea08e3d7656f353f5..645776eafdb9d051d3d0c4071f10691bc7d5f956 100644 (file)
 
 #define DEBUG_TYPE "toolrunner"
 #include "ToolRunner.h"
-#include "llvm/Config/config.h"   // for HAVE_LINK_R
 #include "llvm/System/Program.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Config/config.h"   // for HAVE_LINK_R
 #include <fstream>
 #include <sstream>
 using namespace llvm;
@@ -198,14 +199,15 @@ int LLI::ExecuteProgram(const std::string &Bitcode,
                         const std::vector<std::string> &SharedLibs,
                         unsigned Timeout,
                         unsigned MemoryLimit) {
-  if (!SharedLibs.empty())
-    throw ToolExecutionError("LLI currently does not support "
-                             "loading shared libraries.");
-
   std::vector<const char*> LLIArgs;
   LLIArgs.push_back(LLIPath.c_str());
   LLIArgs.push_back("-force-interpreter=true");
 
+  for (std::vector<std::string>::const_iterator i = SharedLibs.begin(), e = SharedLibs.end(); i != e; ++i) {
+    LLIArgs.push_back("-load");
+    LLIArgs.push_back((*i).c_str());
+  }
+
   // Add any extra LLI args.
   for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
     LLIArgs.push_back(ToolArgs[i].c_str());
@@ -232,7 +234,7 @@ AbstractInterpreter *AbstractInterpreter::createLLI(const char *Argv0,
                                                     std::string &Message,
                                      const std::vector<std::string> *ToolArgs) {
   std::string LLIPath =
-    FindExecutable("lli", Argv0, (void *)(intptr_t)&createLLI).toString();
+    FindExecutable("lli", Argv0, (void *)(intptr_t)&createLLI).str();
   if (!LLIPath.empty()) {
     Message = "Found lli: " + LLIPath + "\n";
     return new LLI(LLIPath, ToolArgs);
@@ -332,7 +334,7 @@ AbstractInterpreter *AbstractInterpreter::createCustom(
     pos = ExecCommandLine.find_first_of(delimiters, lastPos);
   }
 
-  std::string CmdPath = sys::Program::FindProgramByName(Command).toString();
+  std::string CmdPath = sys::Program::FindProgramByName(Command).str();
   if (CmdPath.empty()) {
     Message = 
       std::string("Cannot find '") + Command + 
@@ -366,7 +368,6 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
 
   LLCArgs.push_back ("-o");
   LLCArgs.push_back (OutputAsmFile.c_str()); // Output to the Asm file
-  LLCArgs.push_back ("-f");                  // Overwrite as necessary...
   LLCArgs.push_back (Bitcode.c_str());      // This is the input bitcode
   LLCArgs.push_back (0);
 
@@ -407,7 +408,7 @@ int LLC::ExecuteProgram(const std::string &Bitcode,
   GCCArgs.insert(GCCArgs.end(), gccArgs.begin(), gccArgs.end());
 
   // Assuming LLC worked, compile the result with GCC and run it.
-  return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile,
+  return gcc->ExecuteProgram(OutputAsmFile.str(), Args, GCC::AsmFile,
                              InputFile, OutputFile, GCCArgs,
                              Timeout, MemoryLimit);
 }
@@ -419,7 +420,7 @@ LLC *AbstractInterpreter::createLLC(const char *Argv0,
                                     const std::vector<std::string> *Args,
                                     const std::vector<std::string> *GCCArgs) {
   std::string LLCPath =
-    FindExecutable("llc", Argv0, (void *)(intptr_t)&createLLC).toString();
+    FindExecutable("llc", Argv0, (void *)(intptr_t)&createLLC).str();
   if (LLCPath.empty()) {
     Message = "Cannot find `llc' in executable directory or PATH!\n";
     return 0;
@@ -505,7 +506,7 @@ int JIT::ExecuteProgram(const std::string &Bitcode,
 AbstractInterpreter *AbstractInterpreter::createJIT(const char *Argv0,
                    std::string &Message, const std::vector<std::string> *Args) {
   std::string LLIPath =
-    FindExecutable("lli", Argv0, (void *)(intptr_t)&createJIT).toString();
+    FindExecutable("lli", Argv0, (void *)(intptr_t)&createJIT).str();
   if (!LLIPath.empty()) {
     Message = "Found lli: " + LLIPath + "\n";
     return new JIT(LLIPath, Args);
@@ -572,7 +573,7 @@ int CBE::ExecuteProgram(const std::string &Bitcode,
   std::vector<std::string> GCCArgs(ArgsForGCC);
   GCCArgs.insert(GCCArgs.end(), SharedLibs.begin(), SharedLibs.end());
 
-  return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
+  return gcc->ExecuteProgram(OutputCFile.str(), Args, GCC::CFile,
                              InputFile, OutputFile, GCCArgs,
                              Timeout, MemoryLimit);
 }
@@ -591,7 +592,7 @@ CBE *AbstractInterpreter::createCBE(const char *Argv0,
     return 0;
   }
 
-  Message = "Found llc: " + LLCPath.toString() + "\n";
+  Message = "Found llc: " + LLCPath.str() + "\n";
   GCC *gcc = GCC::create(Message, GCCArgs);
   if (!gcc) {
     errs() << Message << "\n";
@@ -609,9 +610,10 @@ IsARMArchitecture(std::vector<std::string> Args)
 {
   for (std::vector<std::string>::const_iterator
          I = Args.begin(), E = Args.end(); I != E; ++I) {
-    if (!StringsEqualNoCase(*I, "-arch")) {
+    StringRef S(*I);
+    if (!S.equals_lower("-arch")) {
       ++I;
-      if ((I != E) && !StringsEqualNoCase(I->c_str(), "arm", strlen("arm"))) {
+      if (I != E && !S.substr(0, strlen("arm")).equals_lower("arm")) {
         return true;
       }
     }
@@ -757,7 +759,7 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
     errs() << "Error making unique filename: " << ErrMsg << "\n";
     exit(1);
   }
-  OutputFile = uniqueFilename.toString();
+  OutputFile = uniqueFilename.str();
 
   std::vector<const char*> GCCArgs;
   
@@ -839,6 +841,6 @@ GCC *GCC::create(std::string &Message,
   if (!RemoteClient.empty())
     RemoteClientPath = sys::Program::FindProgramByName(RemoteClient);
 
-  Message = "Found gcc: " + GCCPath.toString() + "\n";
+  Message = "Found gcc: " + GCCPath.str() + "\n";
   return new GCC(GCCPath, RemoteClientPath, Args);
 }