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