Fix formatting. NFC.
[oota-llvm.git] / include / llvm / Linker / Linker.h
1 //===- Linker.h - Module Linker Interface -----------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_LINKER_LINKER_H
11 #define LLVM_LINKER_LINKER_H
12
13 #include "llvm/ADT/SmallPtrSet.h"
14
15 #include <functional>
16
17 namespace llvm {
18 class DiagnosticInfo;
19 class Module;
20 class StructType;
21
22 /// This class provides the core functionality of linking in LLVM. It keeps a
23 /// pointer to the merged module so far. It doesn't take ownership of the
24 /// module since it is assumed that the user of this class will want to do
25 /// something with it after the linking.
26 class Linker {
27 public:
28   typedef std::function<void(const DiagnosticInfo &)> DiagnosticHandlerFunction;
29
30   Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
31   Linker(Module *M);
32   ~Linker();
33
34   Module *getModule() const { return Composite; }
35   void deleteModule();
36
37   /// \brief Link \p Src into the composite. The source is destroyed.
38   /// Returns true on error.
39   bool linkInModule(Module *Src);
40
41   static bool LinkModules(Module *Dest, Module *Src,
42                           DiagnosticHandlerFunction DiagnosticHandler);
43
44   static bool LinkModules(Module *Dest, Module *Src);
45
46 private:
47   void init(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
48   Module *Composite;
49   SmallPtrSet<StructType *, 32> IdentifiedStructTypes;
50   DiagnosticHandlerFunction DiagnosticHandler;
51 };
52
53 } // End llvm namespace
54
55 #endif