Fix #includes of i*.h => Instructions.h as per PR403.
[oota-llvm.git] / tools / bugpoint / ToolRunner.h
index 097fc6aed036fe5b48c044f87d435c54139d60d0..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,16 +64,13 @@ 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.
   ///
   int MakeSharedObject(const std::string &InputFile, FileType fileType,
                        std::string &OutputFile);
-  
-private:
-  void ProcessFailure(const char **Args);
 };
 
 
@@ -81,18 +80,28 @@ private:
 /// 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() {}
 
+  /// 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
+  /// thrown, otherwise, this function will just return.
+  virtual void compileProgram(const std::string &Bytecode) {}
+
   /// ExecuteProgram - Run the specified bytecode file, emitting output to the
   /// specified filename.  This returns the exit code of the program.
   ///
@@ -101,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;
 };
 
 //===---------------------------------------------------------------------===//
@@ -109,17 +119,29 @@ 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
+  /// 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
+  /// thrown, otherwise, this function will just return.
+  virtual void compileProgram(const std::string &Bytecode);
+
   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>());
+                               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
@@ -134,18 +156,29 @@ 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
+  /// thrown, otherwise, this function will just return.
+  virtual void compileProgram(const std::string &Bytecode);
+
   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>());
+                                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