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 13251662Sdim#include "llvm/ADT/SmallPtrSet.h" 14234353Sdim#include <string> 15193323Sed 16193323Sednamespace llvm { 17193323Sed 18193323Sedclass Module; 19234353Sdimclass StringRef; 20251662Sdimclass StructType; 21193323Sed 22251662Sdim/// This class provides the core functionality of linking in LLVM. It keeps a 23251662Sdim/// pointer to the merged module so far. It doesn't take ownership of the 24251662Sdim/// module since it is assumed that the user of this class will want to do 25251662Sdim/// something with it after the linking. 26193323Sedclass Linker { 27193323Sed public: 28226633Sdim enum LinkerMode { 29226633Sdim DestroySource = 0, // Allow source module to be destroyed. 30226633Sdim PreserveSource = 1 // Preserve the source module. 31226633Sdim }; 32249423Sdim 33251662Sdim Linker(Module *M); 34193323Sed ~Linker(); 35263508Sdim 36251662Sdim Module *getModule() const { return Composite; } 37263508Sdim void deleteModule(); 38193323Sed 39251662Sdim /// \brief Link \p Src into the composite. The source is destroyed if 40251662Sdim /// \p Mode is DestroySource and preserved if it is PreserveSource. 41251662Sdim /// If \p ErrorMsg is not null, information about any error is written 42251662Sdim /// to it. 43251662Sdim /// Returns true on error. 44251662Sdim bool linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg); 45251662Sdim bool linkInModule(Module *Src, std::string *ErrorMsg) { 46251662Sdim return linkInModule(Src, Linker::DestroySource, ErrorMsg); 47193323Sed } 48193323Sed 49251662Sdim static bool LinkModules(Module *Dest, Module *Src, unsigned Mode, 50251662Sdim std::string *ErrorMsg); 51193323Sed 52193323Sed private: 53251662Sdim Module *Composite; 54251662Sdim SmallPtrSet<StructType*, 32> IdentifiedStructTypes; 55193323Sed}; 56193323Sed 57193323Sed} // End llvm namespace 58193323Sed 59193323Sed#endif 60