EPCDynamicLibrarySearchGenerator.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===------------ EPCDynamicLibrarySearchGenerator.h ------------*- 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. //
  14. // Support loading and searching of dynamic libraries in an executor process
  15. // via the ExecutorProcessControl class.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_EXECUTIONENGINE_ORC_EPCDYNAMICLIBRARYSEARCHGENERATOR_H
  19. #define LLVM_EXECUTIONENGINE_ORC_EPCDYNAMICLIBRARYSEARCHGENERATOR_H
  20. #include "llvm/ADT/FunctionExtras.h"
  21. #include "llvm/ExecutionEngine/Orc/Core.h"
  22. namespace llvm {
  23. namespace orc {
  24. class ExecutorProcessControl;
  25. class EPCDynamicLibrarySearchGenerator : public DefinitionGenerator {
  26. public:
  27. using SymbolPredicate = unique_function<bool(const SymbolStringPtr &)>;
  28. /// Create a DynamicLibrarySearchGenerator that searches for symbols in the
  29. /// library with the given handle.
  30. ///
  31. /// If the Allow predicate is given then only symbols matching the predicate
  32. /// will be searched for. If the predicate is not given then all symbols will
  33. /// be searched for.
  34. EPCDynamicLibrarySearchGenerator(ExecutionSession &ES,
  35. tpctypes::DylibHandle H,
  36. SymbolPredicate Allow = SymbolPredicate())
  37. : EPC(ES.getExecutorProcessControl()), H(H), Allow(std::move(Allow)) {}
  38. /// Permanently loads the library at the given path and, on success, returns
  39. /// a DynamicLibrarySearchGenerator that will search it for symbol definitions
  40. /// in the library. On failure returns the reason the library failed to load.
  41. static Expected<std::unique_ptr<EPCDynamicLibrarySearchGenerator>>
  42. Load(ExecutionSession &ES, const char *LibraryPath,
  43. SymbolPredicate Allow = SymbolPredicate());
  44. /// Creates a EPCDynamicLibrarySearchGenerator that searches for symbols in
  45. /// the target process.
  46. static Expected<std::unique_ptr<EPCDynamicLibrarySearchGenerator>>
  47. GetForTargetProcess(ExecutionSession &ES,
  48. SymbolPredicate Allow = SymbolPredicate()) {
  49. return Load(ES, nullptr, std::move(Allow));
  50. }
  51. Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,
  52. JITDylibLookupFlags JDLookupFlags,
  53. const SymbolLookupSet &Symbols) override;
  54. private:
  55. ExecutorProcessControl &EPC;
  56. tpctypes::DylibHandle H;
  57. SymbolPredicate Allow;
  58. };
  59. } // end namespace orc
  60. } // end namespace llvm
  61. #endif // LLVM_EXECUTIONENGINE_ORC_EPCDYNAMICLIBRARYSEARCHGENERATOR_H
  62. #ifdef __GNUC__
  63. #pragma GCC diagnostic pop
  64. #endif