LLVM API Documentation

Linker/Linker.h
Go to the documentation of this file.
00001 //===- Linker.h - Module Linker Interface -----------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_LINKER_LINKER_H
00011 #define LLVM_LINKER_LINKER_H
00012 
00013 #include "llvm/ADT/SmallPtrSet.h"
00014 #include <string>
00015 
00016 namespace llvm {
00017 
00018 class Comdat;
00019 class GlobalValue;
00020 class Module;
00021 class StringRef;
00022 class StructType;
00023 
00024 /// This class provides the core functionality of linking in LLVM. It keeps a
00025 /// pointer to the merged module so far. It doesn't take ownership of the
00026 /// module since it is assumed that the user of this class will want to do
00027 /// something with it after the linking.
00028 class Linker {
00029   public:
00030     enum LinkerMode {
00031       DestroySource = 0, // Allow source module to be destroyed.
00032       PreserveSource = 1 // Preserve the source module.
00033     };
00034 
00035     Linker(Module *M, bool SuppressWarnings=false);
00036     ~Linker();
00037 
00038     Module *getModule() const { return Composite; }
00039     void deleteModule();
00040 
00041     /// \brief Link \p Src into the composite. The source is destroyed if
00042     /// \p Mode is DestroySource and preserved if it is PreserveSource.
00043     /// If \p ErrorMsg is not null, information about any error is written
00044     /// to it.
00045     /// Returns true on error.
00046     bool linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg);
00047     bool linkInModule(Module *Src, std::string *ErrorMsg) {
00048       return linkInModule(Src, Linker::DestroySource, ErrorMsg);
00049     }
00050 
00051     static bool LinkModules(Module *Dest, Module *Src, unsigned Mode,
00052                             std::string *ErrorMsg);
00053 
00054   private:
00055     Module *Composite;
00056     SmallPtrSet<StructType*, 32> IdentifiedStructTypes;
00057 
00058     bool SuppressWarnings;
00059 };
00060 
00061 } // End llvm namespace
00062 
00063 #endif