Linker.h revision 256281
1178784Skmacy//===- llvm/Linker.h - Module Linker Interface ------------------*- C++ -*-===// 2178784Skmacy// 3178784Skmacy// The LLVM Compiler Infrastructure 4178784Skmacy// 5178784Skmacy// This file is distributed under the University of Illinois Open Source 6178784Skmacy// License. See LICENSE.TXT for details. 7178784Skmacy// 8178784Skmacy//===----------------------------------------------------------------------===// 9178784Skmacy 10178784Skmacy#ifndef LLVM_LINKER_H 11178784Skmacy#define LLVM_LINKER_H 12178784Skmacy 13178784Skmacy#include "llvm/ADT/SmallPtrSet.h" 14178784Skmacy#include <string> 15178784Skmacy 16178784Skmacynamespace llvm { 17178784Skmacy 18178784Skmacyclass Module; 19178784Skmacyclass StringRef; 20178784Skmacyclass StructType; 21178784Skmacy 22178784Skmacy/// This class provides the core functionality of linking in LLVM. It keeps a 23178784Skmacy/// pointer to the merged module so far. It doesn't take ownership of the 24178784Skmacy/// module since it is assumed that the user of this class will want to do 25178784Skmacy/// something with it after the linking. 26178784Skmacyclass Linker { 27178784Skmacy public: 28178784Skmacy enum LinkerMode { 29178784Skmacy DestroySource = 0, // Allow source module to be destroyed. 30178784Skmacy PreserveSource = 1 // Preserve the source module. 31178784Skmacy }; 32178784Skmacy 33178784Skmacy Linker(Module *M); 34178784Skmacy ~Linker(); 35178784Skmacy Module *getModule() const { return Composite; } 36178784Skmacy 37178784Skmacy /// \brief Link \p Src into the composite. The source is destroyed if 38178784Skmacy /// \p Mode is DestroySource and preserved if it is PreserveSource. 39178784Skmacy /// If \p ErrorMsg is not null, information about any error is written 40178784Skmacy /// to it. 41178784Skmacy /// Returns true on error. 42178784Skmacy bool linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg); 43178784Skmacy bool linkInModule(Module *Src, std::string *ErrorMsg) { 44178784Skmacy return linkInModule(Src, Linker::DestroySource, ErrorMsg); 45178784Skmacy } 46178784Skmacy 47178784Skmacy static bool LinkModules(Module *Dest, Module *Src, unsigned Mode, 48178784Skmacy std::string *ErrorMsg); 49178784Skmacy 50178784Skmacy private: 51178784Skmacy Module *Composite; 52178784Skmacy SmallPtrSet<StructType*, 32> IdentifiedStructTypes; 53178784Skmacy}; 54178784Skmacy 55178784Skmacy} // End llvm namespace 56178784Skmacy 57178784Skmacy#endif 58178784Skmacy