bugpoint: Return Errors instead of passing around strings
This replaces the threading of `std::string &Error` through all of
these APIs with checked Error returns instead. There are very few
places here that actually emit any errors right now, but threading the
APIs through will allow us to replace a bunch of exit(1)'s that are
scattered through this code with proper error handling.
This is more or less NFC, but does move around where a couple of error
messages are printed out.
llvm-svn: 280720
diff --git a/llvm/tools/bugpoint/ToolRunner.h b/llvm/tools/bugpoint/ToolRunner.h
index 3e5d83d..f218ad5 100644
--- a/llvm/tools/bugpoint/ToolRunner.h
+++ b/llvm/tools/bugpoint/ToolRunner.h
@@ -19,7 +19,7 @@
 
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/CommandLine.h"
-#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SystemUtils.h"
 #include <exception>
@@ -59,20 +59,19 @@
   /// option specifies optional native shared objects that can be loaded into
   /// the program for execution.
   ///
-  int ExecuteProgram(
+  Expected<int> ExecuteProgram(
       const std::string &ProgramFile, const std::vector<std::string> &Args,
       FileType fileType, const std::string &InputFile,
-      const std::string &OutputFile, std::string *Error = nullptr,
+      const std::string &OutputFile,
       const std::vector<std::string> &CCArgs = std::vector<std::string>(),
       unsigned Timeout = 0, unsigned MemoryLimit = 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,
-                       const std::vector<std::string> &ArgsForCC,
-                       std::string &Error);
+  Error MakeSharedObject(const std::string &InputFile, FileType fileType,
+                         std::string &OutputFile,
+                         const std::vector<std::string> &ArgsForCC);
 };
 
 //===---------------------------------------------------------------------===//
@@ -111,30 +110,31 @@
   /// compileProgram - Compile the specified program from bitcode to executable
   /// code.  This does not produce any output, it is only used when debugging
   /// the code generator.  It returns false if the code generator fails.
-  virtual void compileProgram(const std::string &Bitcode, std::string *Error,
-                              unsigned Timeout = 0, unsigned MemoryLimit = 0) {}
+  virtual Error compileProgram(const std::string &Bitcode, unsigned Timeout = 0,
+                               unsigned MemoryLimit = 0) {
+    return Error::success();
+  }
 
-  /// OutputCode - Compile the specified program from bitcode to code
-  /// understood by the CC driver (either C or asm).  If the code generator
-  /// fails, it sets Error, otherwise, this function returns the type of code
-  /// emitted.
-  virtual CC::FileType OutputCode(const std::string &Bitcode,
-                                  std::string &OutFile, std::string &Error,
-                                  unsigned Timeout = 0,
-                                  unsigned MemoryLimit = 0) {
-    Error = "OutputCode not supported by this AbstractInterpreter!";
-    return CC::AsmFile;
+  /// Compile the specified program from bitcode to code understood by the CC
+  /// driver (either C or asm).  Returns an error if the code generator fails,,
+  /// otherwise, the type of code emitted.
+  virtual Expected<CC::FileType> OutputCode(const std::string &Bitcode,
+                                            std::string &OutFile,
+                                            unsigned Timeout = 0,
+                                            unsigned MemoryLimit = 0) {
+    return make_error<StringError>(
+        "OutputCode not supported by this AbstractInterpreter!",
+        inconvertibleErrorCode());
   }
 
   /// ExecuteProgram - Run the specified bitcode file, emitting output to the
   /// specified filename.  This sets RetVal to the exit code of the program or
-  /// returns false if a problem was encountered that prevented execution of
+  /// returns an Error if a problem was encountered that prevented execution of
   /// the program.
   ///
-  virtual int ExecuteProgram(
+  virtual Expected<int> ExecuteProgram(
       const std::string &Bitcode, const std::vector<std::string> &Args,
       const std::string &InputFile, const std::string &OutputFile,
-      std::string *Error,
       const std::vector<std::string> &CCArgs = std::vector<std::string>(),
       const std::vector<std::string> &SharedLibs = std::vector<std::string>(),
       unsigned Timeout = 0, unsigned MemoryLimit = 0) = 0;
@@ -163,24 +163,19 @@
   /// compileProgram - Compile the specified program from bitcode to executable
   /// code.  This does not produce any output, it is only used when debugging
   /// the code generator.  Returns false if the code generator fails.
-  void compileProgram(const std::string &Bitcode, std::string *Error,
-                      unsigned Timeout = 0, unsigned MemoryLimit = 0) override;
+  Error compileProgram(const std::string &Bitcode, unsigned Timeout = 0,
+                       unsigned MemoryLimit = 0) override;
 
-  int ExecuteProgram(
+  Expected<int> ExecuteProgram(
       const std::string &Bitcode, const std::vector<std::string> &Args,
       const std::string &InputFile, const std::string &OutputFile,
-      std::string *Error,
       const std::vector<std::string> &CCArgs = std::vector<std::string>(),
       const std::vector<std::string> &SharedLibs = std::vector<std::string>(),
       unsigned Timeout = 0, unsigned MemoryLimit = 0) override;
 
-  /// OutputCode - Compile the specified program from bitcode to code
-  /// understood by the CC driver (either C or asm).  If the code generator
-  /// fails, it sets Error, otherwise, this function returns the type of code
-  /// emitted.
-  CC::FileType OutputCode(const std::string &Bitcode, std::string &OutFile,
-                          std::string &Error, unsigned Timeout = 0,
-                          unsigned MemoryLimit = 0) override;
+  Expected<CC::FileType> OutputCode(const std::string &Bitcode,
+                                    std::string &OutFile, unsigned Timeout = 0,
+                                    unsigned MemoryLimit = 0) override;
 };
 
 } // End llvm namespace