Linker.h 1.9 KB

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