Fix #includes of i*.h => Instructions.h as per PR403.
[oota-llvm.git] / tools / bugpoint / ToolRunner.h
index d8e7503253fbb0c6a289e26bc04123c4211f54b7..bd085eab6d09d291667483811293745c53c84eb0 100644 (file)
@@ -18,6 +18,7 @@
 #define TOOLRUNNER_H
 
 #include "Support/SystemUtils.h"
+#include <exception>
 #include <vector>
 
 namespace llvm {
@@ -30,11 +31,12 @@ class LLC;
 /// AbstractInterpreter instances if there is an error running a tool (e.g., LLC
 /// crashes) which prevents execution of the program.
 ///
-class ToolExecutionError {
+class ToolExecutionError : std::exception {
   std::string Message;
 public:
-  ToolExecutionError(const std::string &M) : Message(M) {}
-  const std::string getMessage() const { return Message; }
+  explicit ToolExecutionError(const std::string &M) : Message(M) {}
+  virtual ~ToolExecutionError() throw();
+  virtual const char* what() const throw() { return Message.c_str(); }
 };
 
 
@@ -62,7 +64,7 @@ public:
                      const std::string &InputFile,
                      const std::string &OutputFile,
                      const std::vector<std::string> &SharedLibs = 
-                         std::vector<std::string>());
+                         std::vector<std::string>(), unsigned Timeout = 0);
 
   /// MakeSharedObject - This compiles the specified file (which is either a .c
   /// file or a .s file) into a shared object.
@@ -78,14 +80,18 @@ public:
 /// complexity behind a simple interface.
 ///
 struct AbstractInterpreter {
-  static CBE* createCBE(const std::string &ProgramPath, std::string &Message);
-  static LLC *createLLC(const std::string &ProgramPath, std::string &Message);
+  static CBE *createCBE(const std::string &ProgramPath, std::string &Message,
+                        const std::vector<std::string> *Args = 0);
+  static LLC *createLLC(const std::string &ProgramPath, std::string &Message,
+                        const std::vector<std::string> *Args = 0);
 
   static AbstractInterpreter* createLLI(const std::string &ProgramPath,
-                                        std::string &Message);
+                                        std::string &Message,
+                                        const std::vector<std::string> *Args=0);
 
   static AbstractInterpreter* createJIT(const std::string &ProgramPath,
-                                        std::string &Message);
+                                        std::string &Message,
+                                        const std::vector<std::string> *Args=0);
 
 
   virtual ~AbstractInterpreter() {}
@@ -104,7 +110,8 @@ struct AbstractInterpreter {
                              const std::string &InputFile,
                              const std::string &OutputFile,
                              const std::vector<std::string> &SharedLibs = 
-                               std::vector<std::string>()) = 0;
+                               std::vector<std::string>(),
+                             unsigned Timeout = 0) = 0;
 };
 
 //===---------------------------------------------------------------------===//
@@ -112,9 +119,14 @@ struct AbstractInterpreter {
 //
 class CBE : public AbstractInterpreter {
   std::string LLCPath;          // The path to the `llc' executable
+  std::vector<std::string> ToolArgs; // Extra args to pass to LLC
   GCC *gcc;
 public:
-  CBE(const std::string &llcPath, GCC *Gcc) : LLCPath(llcPath), gcc(Gcc) { }
+  CBE(const std::string &llcPath, GCC *Gcc,
+      const std::vector<std::string> *Args) : LLCPath(llcPath), gcc(Gcc) {
+    ToolArgs.clear ();
+    if (Args) { ToolArgs = *Args; }
+  }
   ~CBE() { delete gcc; }
 
   /// compileProgram - Compile the specified program from bytecode to executable
@@ -128,7 +140,8 @@ public:
                              const std::string &InputFile,
                              const std::string &OutputFile,
                              const std::vector<std::string> &SharedLibs = 
-                               std::vector<std::string>());
+                               std::vector<std::string>(),
+                             unsigned Timeout = 0);
 
   // Sometimes we just want to go half-way and only generate the .c file, not
   // necessarily compile it with GCC and run the program.  This throws an
@@ -143,13 +156,16 @@ public:
 //
 class LLC : public AbstractInterpreter {
   std::string LLCPath;          // The path to the LLC executable
+  std::vector<std::string> ToolArgs; // Extra args to pass to LLC
   GCC *gcc;
 public:
-  LLC(const std::string &llcPath, GCC *Gcc)
-    : LLCPath(llcPath), gcc(Gcc) { }
+  LLC(const std::string &llcPath, GCC *Gcc,
+    const std::vector<std::string> *Args) : LLCPath(llcPath), gcc(Gcc) {
+    ToolArgs.clear ();
+    if (Args) { ToolArgs = *Args; }
+  }
   ~LLC() { delete gcc; }
 
-
   /// compileProgram - Compile the specified program from bytecode to executable
   /// code.  This does not produce any output, it is only used when debugging
   /// the code generator.  If the code generator fails, an exception should be
@@ -161,7 +177,8 @@ public:
                              const std::string &InputFile,
                              const std::string &OutputFile,
                              const std::vector<std::string> &SharedLibs = 
-                                std::vector<std::string>());
+                                std::vector<std::string>(),
+                             unsigned Timeout = 0);
 
   // Sometimes we just want to go half-way and only generate the .s file,
   // not necessarily compile it all the way and run the program.  This throws