//===- lib/Linker/LinkModules.cpp - Module Linker Implementation ----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the LLVM module linker.
//
// Specifically, this:
// * Merges global variables between the two modules
// * Uninit + Uninit = Init, Init + Uninit = Init, Init + Init = Error if !=
// * Merges functions between two modules
//
//===----------------------------------------------------------------------===//
#include "llvm/Linker.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/Instructions.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/ADT/DenseMap.h"
using namespace llvm;
// Error - Simple wrapper function to conditionally assign to E and return true.
// This just makes error return conditions a little bit simpler...
static inline bool Error(std::string *E, const Twine &Message) {
if (E) *E = Message.str();
return true;
}
// Function: ResolveTypes()
//
// Description:
// Attempt to link the two specified types together.
//
// Inputs:
// DestTy - The type to which we wish to resolve.
// SrcTy - The original type which we want to resolve.
//
// Outputs:
// DestST - The symbol table in which the new type should be placed.
//
// Return value:
// true - There is an error and the types cannot yet be linked.
// false - No errors.
//
static bool ResolveTypes(const Type *DestTy, const Type *SrcTy) {
if (DestTy == SrcTy) return false; // If already equal, noop
assert(DestTy && SrcTy && "Can't handle null types");
if (const OpaqueType *OT = dyn_cast<OpaqueType>(DestTy)) {
// Type _is_ in module, just opaque...
const_cast<OpaqueType*>(OT)->refineAbstractTypeTo(