Linker.h 1.8 KB

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