Linker.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. class StructType;
  20. class Type;
  21. /// This class provides the core functionality of linking in LLVM. It keeps a
  22. /// pointer to the merged module so far. It doesn't take ownership of the
  23. /// module since it is assumed that the user of this class will want to do
  24. /// something with it after the linking.
  25. class Linker {
  26. IRMover Mover;
  27. public:
  28. enum Flags {
  29. None = 0,
  30. OverrideFromSrc = (1 << 0),
  31. LinkOnlyNeeded = (1 << 1),
  32. };
  33. Linker(Module &M);
  34. /// Link \p Src into the composite.
  35. ///
  36. /// Passing OverrideSymbols as true will have symbols from Src
  37. /// shadow those in the Dest.
  38. ///
  39. /// Passing InternalizeCallback will have the linker call the function with
  40. /// the new module and a list of global value names to be internalized by the
  41. /// callback.
  42. ///
  43. /// Returns true on error.
  44. bool linkInModule(std::unique_ptr<Module> Src, unsigned Flags = Flags::None,
  45. std::function<void(Module &, const StringSet<> &)>
  46. InternalizeCallback = {});
  47. static bool linkModules(Module &Dest, std::unique_ptr<Module> Src,
  48. unsigned Flags = Flags::None,
  49. std::function<void(Module &, const StringSet<> &)>
  50. InternalizeCallback = {});
  51. };
  52. } // End llvm namespace
  53. #endif
  54. #ifdef __GNUC__
  55. #pragma GCC diagnostic pop
  56. #endif