Make it easier to pass a custom diagnostic handler to the IR linker.
[oota-llvm.git] / include / llvm / Linker / Linker.h
index 42b2cb37b30959eb62cf580276a400e2b7e78195..50922e3ebe225131900182083eba224e92ac4afc 100644 (file)
 #define LLVM_LINKER_LINKER_H
 
 #include "llvm/ADT/SmallPtrSet.h"
-#include <string>
 
-namespace llvm {
+#include <functional>
 
+namespace llvm {
+class DiagnosticInfo;
 class Module;
-class StringRef;
 class StructType;
 
 /// This class provides the core functionality of linking in LLVM. It keeps a
@@ -30,7 +30,11 @@ class Linker {
       PreserveSource = 1 // Preserve the source module.
     };
 
-    Linker(Module *M, bool SuppressWarnings=false);
+    typedef std::function<void(const DiagnosticInfo &)>
+        DiagnosticHandlerFunction;
+
+    Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
+    Linker(Module *M);
     ~Linker();
 
     Module *getModule() const { return Composite; }
@@ -41,19 +45,23 @@ class Linker {
     /// If \p ErrorMsg is not null, information about any error is written
     /// to it.
     /// Returns true on error.
-    bool linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg);
-    bool linkInModule(Module *Src, std::string *ErrorMsg) {
-      return linkInModule(Src, Linker::DestroySource, ErrorMsg);
+    bool linkInModule(Module *Src, unsigned Mode);
+    bool linkInModule(Module *Src) {
+      return linkInModule(Src, Linker::DestroySource);
     }
 
-    static bool LinkModules(Module *Dest, Module *Src, unsigned Mode,
-                            std::string *ErrorMsg);
+    static bool
+    LinkModules(Module *Dest, Module *Src, unsigned Mode,
+                DiagnosticHandlerFunction DiagnosticHandler);
+
+    static bool
+    LinkModules(Module *Dest, Module *Src, unsigned Mode);
+
 
   private:
     Module *Composite;
     SmallPtrSet<StructType*, 32> IdentifiedStructTypes;
-
-    bool SuppressWarnings;
+    DiagnosticHandlerFunction DiagnosticHandler;
 };
 
 } // End llvm namespace