1193323Sed//===- llvm/Linker.h - Module Linker Interface ------------------*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed 10193323Sed#ifndef LLVM_LINKER_H 11193323Sed#define LLVM_LINKER_H 12193323Sed 13252723Sdim#include "llvm/ADT/SmallPtrSet.h" 14235633Sdim#include <string> 15193323Sed 16193323Sednamespace llvm { 17193323Sed 18193323Sedclass Module; 19235633Sdimclass StringRef; 20252723Sdimclass StructType; 21193323Sed 22252723Sdim/// This class provides the core functionality of linking in LLVM. It keeps a 23252723Sdim/// pointer to the merged module so far. It doesn't take ownership of the 24252723Sdim/// module since it is assumed that the user of this class will want to do 25252723Sdim/// something with it after the linking. 26193323Sedclass Linker { 27193323Sed public: 28226890Sdim enum LinkerMode { 29226890Sdim DestroySource = 0, // Allow source module to be destroyed. 30226890Sdim PreserveSource = 1 // Preserve the source module. 31226890Sdim }; 32193323Sed 33252723Sdim Linker(Module *M); 34193323Sed ~Linker(); 35263509Sdim 36252723Sdim Module *getModule() const { return Composite; } 37263509Sdim void deleteModule(); 38193323Sed 39252723Sdim /// \brief Link \p Src into the composite. The source is destroyed if 40252723Sdim /// \p Mode is DestroySource and preserved if it is PreserveSource. 41252723Sdim /// If \p ErrorMsg is not null, information about any error is written 42252723Sdim /// to it. 43252723Sdim /// Returns true on error. 44252723Sdim bool linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg); 45252723Sdim bool linkInModule(Module *Src, std::string *ErrorMsg) { 46252723Sdim return linkInModule(Src, Linker::DestroySource, ErrorMsg); 47193323Sed } 48193323Sed 49252723Sdim static bool LinkModules(Module *Dest, Module *Src, unsigned Mode, 50252723Sdim std::string *ErrorMsg); 51193323Sed 52193323Sed private: 53252723Sdim Module *Composite; 54252723Sdim SmallPtrSet<StructType*, 32> IdentifiedStructTypes; 55193323Sed}; 56193323Sed 57193323Sed} // End llvm namespace 58193323Sed 59193323Sed#endif 60