X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FLinker.h;h=3667b8521d90c5c8e482e9f3f4f84e4f9e4e764a;hb=2f02ded68a114410f11bc2f4e901d0d8e5850de1;hp=523906ce6a31b7067b0c5c7e9f05ced06f865b38;hpb=7d0a022489b56220c365d00aed23bf8ad9983108;p=oota-llvm.git diff --git a/include/llvm/Linker.h b/include/llvm/Linker.h index 523906ce6a3..3667b8521d9 100644 --- a/include/llvm/Linker.h +++ b/include/llvm/Linker.h @@ -1,33 +1,57 @@ //===- llvm/Linker.h - Module Linker Interface ------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure // -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// +// The LLVM Compiler Infrastructure // -// This file defines the interface to the module linker. +// 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 +#include "llvm/ADT/SmallPtrSet.h" #include namespace llvm { class Module; - -// LinkModules - This function links two modules together, with the resulting -// left module modified to be the composite of the two input modules. If an -// error occurs, true is returned and ErrorMsg (if not null) is set to indicate -// the problem. -// -bool LinkModules(Module *Dest, const Module *Src, std::string *ErrorMsg = 0); +class StringRef; +class StructType; + +/// 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. +class Linker { + public: + enum LinkerMode { + DestroySource = 0, // Allow source module to be destroyed. + PreserveSource = 1 // Preserve the source module. + }; + + Linker(Module *M); + ~Linker(); + 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); + } + + static bool LinkModules(Module *Dest, Module *Src, unsigned Mode, + std::string *ErrorMsg); + + private: + Module *Composite; + SmallPtrSet IdentifiedStructTypes; +}; } // End llvm namespace #endif -