Update the error handling of lib/Linker.
[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 namespace llvm {
16
17 class Module;
18 class StructType;
19
20 /// This class provides the core functionality of linking in LLVM. It keeps a
21 /// pointer to the merged module so far. It doesn't take ownership of the
22 /// module since it is assumed that the user of this class will want to do
23 /// something with it after the linking.
24 class Linker {
25   public:
26     enum LinkerMode {
27       DestroySource = 0, // Allow source module to be destroyed.
28       PreserveSource = 1 // Preserve the source module.
29     };
30
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 if
38     /// \p Mode is DestroySource and preserved if it is PreserveSource.
39     /// If \p ErrorMsg is not null, information about any error is written
40     /// to it.
41     /// Returns true on error.
42     bool linkInModule(Module *Src, unsigned Mode);
43     bool linkInModule(Module *Src) {
44       return linkInModule(Src, Linker::DestroySource);
45     }
46
47     static bool LinkModules(Module *Dest, Module *Src, unsigned Mode);
48
49   private:
50     Module *Composite;
51     SmallPtrSet<StructType*, 32> IdentifiedStructTypes;
52 };
53
54 } // End llvm namespace
55
56 #endif