2014-03-06 03:42:23 +00:00
|
|
|
//===- Linker.h - Module Linker Interface -----------------------*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-10-13 16:57:49 +00:00
|
|
|
|
2014-03-06 03:42:23 +00:00
|
|
|
#ifndef LLVM_LINKER_LINKER_H
|
|
|
|
#define LLVM_LINKER_LINKER_H
|
2001-10-13 16:57:49 +00:00
|
|
|
|
2014-12-03 22:36:37 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2015-01-10 00:07:30 +00:00
|
|
|
#include "llvm/IR/DiagnosticInfo.h"
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2014-10-27 23:02:10 +00:00
|
|
|
namespace llvm {
|
2001-10-13 16:57:49 +00:00
|
|
|
class Module;
|
2013-05-04 05:05:18 +00:00
|
|
|
class StructType;
|
2014-12-03 22:36:37 +00:00
|
|
|
class Type;
|
2001-10-28 21:23:44 +00:00
|
|
|
|
2013-05-04 03:06:50 +00:00
|
|
|
/// 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.
|
2004-12-13 02:58:05 +00:00
|
|
|
class Linker {
|
2014-11-21 18:05:55 +00:00
|
|
|
public:
|
2014-12-03 22:36:37 +00:00
|
|
|
struct StructTypeKeyInfo {
|
|
|
|
struct KeyTy {
|
|
|
|
ArrayRef<Type *> ETypes;
|
|
|
|
bool IsPacked;
|
|
|
|
KeyTy(ArrayRef<Type *> E, bool P);
|
|
|
|
KeyTy(const StructType *ST);
|
|
|
|
bool operator==(const KeyTy &that) const;
|
|
|
|
bool operator!=(const KeyTy &that) const;
|
|
|
|
};
|
|
|
|
static StructType *getEmptyKey();
|
|
|
|
static StructType *getTombstoneKey();
|
|
|
|
static unsigned getHashValue(const KeyTy &Key);
|
|
|
|
static unsigned getHashValue(const StructType *ST);
|
|
|
|
static bool isEqual(const KeyTy &LHS, const StructType *RHS);
|
|
|
|
static bool isEqual(const StructType *LHS, const StructType *RHS);
|
|
|
|
};
|
|
|
|
|
2014-12-06 19:22:54 +00:00
|
|
|
typedef DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypeSet;
|
2014-12-03 22:36:37 +00:00
|
|
|
typedef DenseSet<StructType *> OpaqueStructTypeSet;
|
|
|
|
|
|
|
|
struct IdentifiedStructTypeSet {
|
|
|
|
// The set of opaque types is the composite module.
|
|
|
|
OpaqueStructTypeSet OpaqueStructTypes;
|
|
|
|
|
|
|
|
// The set of identified but non opaque structures in the composite module.
|
|
|
|
NonOpaqueStructTypeSet NonOpaqueStructTypes;
|
|
|
|
|
|
|
|
void addNonOpaque(StructType *Ty);
|
|
|
|
void addOpaque(StructType *Ty);
|
|
|
|
StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
|
|
|
|
bool hasType(StructType *Ty);
|
|
|
|
};
|
|
|
|
|
2014-11-21 18:05:55 +00:00
|
|
|
Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
|
|
|
|
Linker(Module *M);
|
|
|
|
~Linker();
|
2013-10-16 08:59:57 +00:00
|
|
|
|
2014-11-21 18:05:55 +00:00
|
|
|
Module *getModule() const { return Composite; }
|
|
|
|
void deleteModule();
|
2013-05-04 03:06:50 +00:00
|
|
|
|
2014-11-21 18:05:55 +00:00
|
|
|
/// \brief Link \p Src into the composite. The source is destroyed.
|
|
|
|
/// Returns true on error.
|
|
|
|
bool linkInModule(Module *Src);
|
2014-10-27 23:02:10 +00:00
|
|
|
|
2014-11-21 18:05:55 +00:00
|
|
|
static bool LinkModules(Module *Dest, Module *Src,
|
|
|
|
DiagnosticHandlerFunction DiagnosticHandler);
|
2014-10-27 23:02:10 +00:00
|
|
|
|
2014-11-21 18:05:55 +00:00
|
|
|
static bool LinkModules(Module *Dest, Module *Src);
|
2004-12-13 02:58:05 +00:00
|
|
|
|
2014-11-21 18:05:55 +00:00
|
|
|
private:
|
|
|
|
void init(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
|
|
|
|
Module *Composite;
|
2014-12-03 22:36:37 +00:00
|
|
|
|
|
|
|
IdentifiedStructTypeSet IdentifiedStructTypes;
|
|
|
|
|
2014-11-21 18:05:55 +00:00
|
|
|
DiagnosticHandlerFunction DiagnosticHandler;
|
2004-12-13 02:58:05 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-10-13 16:57:49 +00:00
|
|
|
#endif
|