]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | ||
85aaf69f SL |
13 | #include "llvm/ADT/ArrayRef.h" |
14 | #include "llvm/ADT/DenseMap.h" | |
15 | #include "llvm/ADT/DenseSet.h" | |
16 | #include "llvm/IR/DiagnosticInfo.h" | |
1a4d82fc JJ |
17 | |
18 | namespace llvm { | |
1a4d82fc | 19 | class Module; |
1a4d82fc | 20 | class StructType; |
85aaf69f | 21 | class Type; |
1a4d82fc JJ |
22 | |
23 | /// This class provides the core functionality of linking in LLVM. It keeps a | |
24 | /// pointer to the merged module so far. It doesn't take ownership of the | |
25 | /// module since it is assumed that the user of this class will want to do | |
26 | /// something with it after the linking. | |
27 | class Linker { | |
85aaf69f SL |
28 | public: |
29 | struct StructTypeKeyInfo { | |
30 | struct KeyTy { | |
31 | ArrayRef<Type *> ETypes; | |
32 | bool IsPacked; | |
33 | KeyTy(ArrayRef<Type *> E, bool P); | |
34 | KeyTy(const StructType *ST); | |
35 | bool operator==(const KeyTy &that) const; | |
36 | bool operator!=(const KeyTy &that) const; | |
1a4d82fc | 37 | }; |
85aaf69f SL |
38 | static StructType *getEmptyKey(); |
39 | static StructType *getTombstoneKey(); | |
40 | static unsigned getHashValue(const KeyTy &Key); | |
41 | static unsigned getHashValue(const StructType *ST); | |
42 | static bool isEqual(const KeyTy &LHS, const StructType *RHS); | |
43 | static bool isEqual(const StructType *LHS, const StructType *RHS); | |
44 | }; | |
45 | ||
46 | typedef DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypeSet; | |
47 | typedef DenseSet<StructType *> OpaqueStructTypeSet; | |
48 | ||
49 | struct IdentifiedStructTypeSet { | |
50 | // The set of opaque types is the composite module. | |
51 | OpaqueStructTypeSet OpaqueStructTypes; | |
52 | ||
53 | // The set of identified but non opaque structures in the composite module. | |
54 | NonOpaqueStructTypeSet NonOpaqueStructTypes; | |
55 | ||
56 | void addNonOpaque(StructType *Ty); | |
57 | void addOpaque(StructType *Ty); | |
58 | StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked); | |
59 | bool hasType(StructType *Ty); | |
60 | }; | |
61 | ||
62 | Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler); | |
63 | Linker(Module *M); | |
64 | ~Linker(); | |
65 | ||
66 | Module *getModule() const { return Composite; } | |
67 | void deleteModule(); | |
1a4d82fc | 68 | |
85aaf69f SL |
69 | /// \brief Link \p Src into the composite. The source is destroyed. |
70 | /// Returns true on error. | |
71 | bool linkInModule(Module *Src); | |
1a4d82fc | 72 | |
85aaf69f SL |
73 | static bool LinkModules(Module *Dest, Module *Src, |
74 | DiagnosticHandlerFunction DiagnosticHandler); | |
1a4d82fc | 75 | |
85aaf69f | 76 | static bool LinkModules(Module *Dest, Module *Src); |
1a4d82fc | 77 | |
85aaf69f SL |
78 | private: |
79 | void init(Module *M, DiagnosticHandlerFunction DiagnosticHandler); | |
80 | Module *Composite; | |
1a4d82fc | 81 | |
85aaf69f | 82 | IdentifiedStructTypeSet IdentifiedStructTypes; |
1a4d82fc | 83 | |
85aaf69f | 84 | DiagnosticHandlerFunction DiagnosticHandler; |
1a4d82fc JJ |
85 | }; |
86 | ||
87 | } // End llvm namespace | |
88 | ||
89 | #endif |