Home | History | Annotate | Download | only in Linker
      1 //===- Linker.h - Module Linker Interface -----------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef LLVM_LINKER_LINKER_H
     11 #define LLVM_LINKER_LINKER_H
     12 
     13 #include "llvm/ADT/SmallPtrSet.h"
     14 #include <string>
     15 
     16 namespace llvm {
     17 
     18 class Comdat;
     19 class GlobalValue;
     20 class Module;
     21 class StringRef;
     22 class StructType;
     23 
     24 /// This class provides the core functionality of linking in LLVM. It keeps a
     25 /// pointer to the merged module so far. It doesn't take ownership of the
     26 /// module since it is assumed that the user of this class will want to do
     27 /// something with it after the linking.
     28 class Linker {
     29   public:
     30     enum LinkerMode {
     31       DestroySource = 0, // Allow source module to be destroyed.
     32       PreserveSource = 1 // Preserve the source module.
     33     };
     34 
     35     Linker(Module *M, bool SuppressWarnings=false);
     36     ~Linker();
     37 
     38     Module *getModule() const { return Composite; }
     39     void deleteModule();
     40 
     41     /// \brief Link \p Src into the composite. The source is destroyed if
     42     /// \p Mode is DestroySource and preserved if it is PreserveSource.
     43     /// If \p ErrorMsg is not null, information about any error is written
     44     /// to it.
     45     /// Returns true on error.
     46     bool linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg);
     47     bool linkInModule(Module *Src, std::string *ErrorMsg) {
     48       return linkInModule(Src, Linker::DestroySource, ErrorMsg);
     49     }
     50 
     51     static bool LinkModules(Module *Dest, Module *Src, unsigned Mode,
     52                             std::string *ErrorMsg);
     53 
     54   private:
     55     Module *Composite;
     56     SmallPtrSet<StructType*, 32> IdentifiedStructTypes;
     57 
     58     bool SuppressWarnings;
     59 };
     60 
     61 } // End llvm namespace
     62 
     63 #endif
     64