2009-06-02 17:52:33 +00:00
|
|
|
//===- llvm/Linker.h - Module Linker Interface ------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LINKER_H
|
|
|
|
#define LLVM_LINKER_H
|
|
|
|
|
2013-06-10 20:36:52 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2012-04-14 13:54:10 +00:00
|
|
|
#include <string>
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class Module;
|
2012-04-14 13:54:10 +00:00
|
|
|
class StringRef;
|
2013-06-10 20:36:52 +00:00
|
|
|
class StructType;
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2013-06-10 20:36:52 +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.
|
2009-06-02 17:52:33 +00:00
|
|
|
class Linker {
|
|
|
|
public:
|
2011-10-20 21:10:27 +00:00
|
|
|
enum LinkerMode {
|
|
|
|
DestroySource = 0, // Allow source module to be destroyed.
|
|
|
|
PreserveSource = 1 // Preserve the source module.
|
|
|
|
};
|
2013-04-08 18:41:23 +00:00
|
|
|
|
2013-06-10 20:36:52 +00:00
|
|
|
Linker(Module *M);
|
2009-06-02 17:52:33 +00:00
|
|
|
~Linker();
|
2013-06-10 20:36:52 +00:00
|
|
|
Module *getModule() const { return Composite; }
|
|
|
|
|
|
|
|
/// \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);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 20:36:52 +00:00
|
|
|
static bool LinkModules(Module *Dest, Module *Src, unsigned Mode,
|
|
|
|
std::string *ErrorMsg);
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
private:
|
2013-06-10 20:36:52 +00:00
|
|
|
Module *Composite;
|
|
|
|
SmallPtrSet<StructType*, 32> IdentifiedStructTypes;
|
2009-06-02 17:52:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|