Finegrainify namespacification
[oota-llvm.git] / tools / bugpoint / ToolRunner.cpp
index 654ce95bafa4a90d98de72f848a7ddbea6c7c905..b1fb64b9908e94fae359936e55dc9652f635bbb2 100644 (file)
@@ -1,31 +1,43 @@
 //===-- ToolRunner.cpp ----------------------------------------------------===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This file implements the interfaces described in the ToolRunner.h file.
 //
 //===----------------------------------------------------------------------===//
 
+#define DEBUG_TYPE "toolrunner"
 #include "llvm/Support/ToolRunner.h"
+#include "Config/config.h"   // for HAVE_LINK_R
 #include "Support/Debug.h"
 #include "Support/FileUtilities.h"
 #include <iostream>
 #include <fstream>
+using namespace llvm;
 
 //===---------------------------------------------------------------------===//
 // LLI Implementation of AbstractIntepreter interface
 //
-class LLI : public AbstractInterpreter {
-  std::string LLIPath;          // The path to the LLI executable
-public:
-  LLI(const std::string &Path) : LLIPath(Path) { }
-
-
-  virtual int ExecuteProgram(const std::string &Bytecode,
-                             const std::vector<std::string> &Args,
-                             const std::string &InputFile,
-                             const std::string &OutputFile,
-                             const std::vector<std::string> &SharedLibs = 
+namespace {
+  class LLI : public AbstractInterpreter {
+    std::string LLIPath;          // The path to the LLI executable
+  public:
+    LLI(const std::string &Path) : LLIPath(Path) { }
+    
+    
+    virtual int ExecuteProgram(const std::string &Bytecode,
+                               const std::vector<std::string> &Args,
+                               const std::string &InputFile,
+                               const std::string &OutputFile,
+                               const std::vector<std::string> &SharedLibs = 
                                std::vector<std::string>());
-};
+  };
+}
 
 int LLI::ExecuteProgram(const std::string &Bytecode,
                         const std::vector<std::string> &Args,
@@ -49,8 +61,8 @@ int LLI::ExecuteProgram(const std::string &Bytecode,
   LLIArgs.push_back(0);
 
   std::cout << "<lli>" << std::flush;
-  DEBUG(std::cerr << "\nAbout to run:\n\t";
-        for (unsigned i=0, e = LLIArgs.size(); i != e; ++i)
+  DEBUG(std::cerr << "\nAbout to run:\t";
+        for (unsigned i=0, e = LLIArgs.size()-1; i != e; ++i)
           std::cerr << " " << LLIArgs[i];
         std::cerr << "\n";
         );
@@ -137,19 +149,21 @@ LLC *AbstractInterpreter::createLLC(const std::string &ProgramPath,
 //===---------------------------------------------------------------------===//
 // JIT Implementation of AbstractIntepreter interface
 //
-class JIT : public AbstractInterpreter {
-  std::string LLIPath;          // The path to the LLI executable
-public:
-  JIT(const std::string &Path) : LLIPath(Path) { }
-
-
-  virtual int ExecuteProgram(const std::string &Bytecode,
-                             const std::vector<std::string> &Args,
-                             const std::string &InputFile,
-                             const std::string &OutputFile,
-                             const std::vector<std::string> &SharedLibs = 
+namespace {
+  class JIT : public AbstractInterpreter {
+    std::string LLIPath;          // The path to the LLI executable
+  public:
+    JIT(const std::string &Path) : LLIPath(Path) { }
+    
+    
+    virtual int ExecuteProgram(const std::string &Bytecode,
+                               const std::vector<std::string> &Args,
+                               const std::string &InputFile,
+                               const std::string &OutputFile,
+                               const std::vector<std::string> &SharedLibs = 
                                std::vector<std::string>());
-};
+  };
+}
 
 int JIT::ExecuteProgram(const std::string &Bytecode,
                         const std::vector<std::string> &Args,
@@ -173,8 +187,8 @@ int JIT::ExecuteProgram(const std::string &Bytecode,
   JITArgs.push_back(0);
 
   std::cout << "<jit>" << std::flush;
-  DEBUG(std::cerr << "\nAbout to run:\n\t";
-        for (unsigned i=0, e = JITArgs.size(); i != e; ++i)
+  DEBUG(std::cerr << "\nAbout to run:\t";
+        for (unsigned i=0, e = JITArgs.size()-1; i != e; ++i)
           std::cerr << " " << JITArgs[i];
         std::cerr << "\n";
         );
@@ -289,6 +303,9 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
   GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file...
   GCCArgs.push_back("-lm");                // Hard-code the math library...
   GCCArgs.push_back("-O2");                // Optimize the program a bit...
+#if defined (HAVE_LINK_R)
+  GCCArgs.push_back("-Wl,-R.");            // Search this dir for .so files
+#endif
   GCCArgs.push_back(0);                    // NULL terminator
 
   std::cout << "<gcc>" << std::flush;
@@ -307,8 +324,8 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
 
   // Now that we have a binary, run it!
   std::cout << "<program>" << std::flush;
-  DEBUG(std::cerr << "\nAbout to run:\n\t";
-        for (unsigned i=0, e = ProgramArgs.size(); i != e; ++i)
+  DEBUG(std::cerr << "\nAbout to run:\t";
+        for (unsigned i=0, e = ProgramArgs.size()-1; i != e; ++i)
           std::cerr << " " << ProgramArgs[i];
         std::cerr << "\n";
         );