Fix layering StringRef copy using BumpPtrAllocator.
[oota-llvm.git] / include / llvm / Linker.h
index 8774012f152526d1b8e0e2b424fad22ae3642d4a..4f37459eb403f38a8f85a82b0844fbaa799f32e2 100644 (file)
@@ -1,37 +1,59 @@
-//===- llvm/Transforms/Linker.h - Module Linker Interface --------*- C++ -*--=//
+//===- llvm/Linker.h - Module Linker Interface ------------------*- C++ -*-===//
 //
-// This file defines the interface to the module linker.
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TRANSFORMATIONS_LINKER_H
-#define LLVM_TRANSFORMATIONS_LINKER_H
+#ifndef LLVM_LINKER_H
+#define LLVM_LINKER_H
 
+#include "llvm/ADT/SmallPtrSet.h"
 #include <string>
-class Module;
-class Type;
-class Value;
-
-
-// LinkModules - This function links two modules together, with the resulting
-// left module modified to be the composite of the two input modules.  If an
-// error occurs, true is returned and ErrorMsg (if not null) is set to indicate
-// the problem.
-//
-bool    LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0);
 
+namespace llvm {
 
-// MangleTypeName - Implement a consistent name-mangling scheme for
-//                  a given type.
-// 
-string MangleTypeName(const Type* type);
-
-
-// MangleName - implement a consistent name-mangling scheme for all
-// externally visible (i.e., global) objects.
-// privateName should be unique within the module.
-// 
-string  MangleName(const string& privateName, const Value* V);
-
+class Module;
+class StringRef;
+class StructType;
+
+/// This class provides the core functionality of linking in LLVM. It keeps a
+/// pointer to the merged module so far. It doesn't take ownership of the
+/// module since it is assumed that the user of this class will want to do
+/// something with it after the linking.
+class Linker {
+  public:
+    enum LinkerMode {
+      DestroySource = 0, // Allow source module to be destroyed.
+      PreserveSource = 1 // Preserve the source module.
+    };
+
+    Linker(Module *M);
+    ~Linker();
+
+    Module *getModule() const { return Composite; }
+    void deleteModule();
+
+    /// \brief Link \p Src into the composite. The source is destroyed if
+    /// \p Mode is DestroySource and preserved if it is PreserveSource.
+    /// 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);
+    }
+
+    static bool LinkModules(Module *Dest, Module *Src, unsigned Mode,
+                            std::string *ErrorMsg);
+
+  private:
+    Module *Composite;
+    SmallPtrSet<StructType*, 32> IdentifiedStructTypes;
+};
+
+} // End llvm namespace
 
 #endif