1*0b57cec5SDimitry Andric //===- Linker.h - Module Linker Interface -----------------------*- C++ -*-===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #ifndef LLVM_LINKER_LINKER_H 10*0b57cec5SDimitry Andric #define LLVM_LINKER_LINKER_H 11*0b57cec5SDimitry Andric 12*0b57cec5SDimitry Andric #include "llvm/ADT/StringSet.h" 13*0b57cec5SDimitry Andric #include "llvm/Linker/IRMover.h" 14*0b57cec5SDimitry Andric 15*0b57cec5SDimitry Andric namespace llvm { 16*0b57cec5SDimitry Andric class Module; 17*0b57cec5SDimitry Andric 18*0b57cec5SDimitry Andric /// This class provides the core functionality of linking in LLVM. It keeps a 19*0b57cec5SDimitry Andric /// pointer to the merged module so far. It doesn't take ownership of the 20*0b57cec5SDimitry Andric /// module since it is assumed that the user of this class will want to do 21*0b57cec5SDimitry Andric /// something with it after the linking. 22*0b57cec5SDimitry Andric class Linker { 23*0b57cec5SDimitry Andric IRMover Mover; 24*0b57cec5SDimitry Andric 25*0b57cec5SDimitry Andric public: 26*0b57cec5SDimitry Andric enum Flags { 27*0b57cec5SDimitry Andric None = 0, 28*0b57cec5SDimitry Andric OverrideFromSrc = (1 << 0), 29*0b57cec5SDimitry Andric LinkOnlyNeeded = (1 << 1), 30*0b57cec5SDimitry Andric }; 31*0b57cec5SDimitry Andric 32*0b57cec5SDimitry Andric Linker(Module &M); 33*0b57cec5SDimitry Andric 34*0b57cec5SDimitry Andric /// Link \p Src into the composite. 35*0b57cec5SDimitry Andric /// 36*0b57cec5SDimitry Andric /// Passing OverrideSymbols as true will have symbols from Src 37*0b57cec5SDimitry Andric /// shadow those in the Dest. 38*0b57cec5SDimitry Andric /// 39*0b57cec5SDimitry Andric /// Passing InternalizeCallback will have the linker call the function with 40*0b57cec5SDimitry Andric /// the new module and a list of global value names to be internalized by the 41*0b57cec5SDimitry Andric /// callback. 42*0b57cec5SDimitry Andric /// 43*0b57cec5SDimitry Andric /// Returns true on error. 44*0b57cec5SDimitry Andric bool linkInModule(std::unique_ptr<Module> Src, unsigned Flags = Flags::None, 45*0b57cec5SDimitry Andric std::function<void(Module &, const StringSet<> &)> 46*0b57cec5SDimitry Andric InternalizeCallback = {}); 47*0b57cec5SDimitry Andric 48*0b57cec5SDimitry Andric static bool linkModules(Module &Dest, std::unique_ptr<Module> Src, 49*0b57cec5SDimitry Andric unsigned Flags = Flags::None, 50*0b57cec5SDimitry Andric std::function<void(Module &, const StringSet<> &)> 51*0b57cec5SDimitry Andric InternalizeCallback = {}); 52*0b57cec5SDimitry Andric }; 53*0b57cec5SDimitry Andric 54*0b57cec5SDimitry Andric } // End llvm namespace 55*0b57cec5SDimitry Andric 56*0b57cec5SDimitry Andric #endif 57