Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- LambdaResolverMM - Redirect symbol lookup via a functor --*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Defines a RuntimeDyld::SymbolResolver subclass that uses a user-supplied |
| 10 | // functor for symbol resolution. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_EXECUTIONENGINE_ORC_LAMBDARESOLVER_H |
| 15 | #define LLVM_EXECUTIONENGINE_ORC_LAMBDARESOLVER_H |
| 16 | |
| 17 | #include "llvm/ADT/STLExtras.h" |
| 18 | #include "llvm/ExecutionEngine/JITSymbol.h" |
| 19 | #include <memory> |
| 20 | |
| 21 | namespace llvm { |
| 22 | namespace orc { |
| 23 | |
| 24 | template <typename DylibLookupFtorT, typename ExternalLookupFtorT> |
| 25 | class LambdaResolver : public LegacyJITSymbolResolver { |
| 26 | public: |
| 27 | LambdaResolver(DylibLookupFtorT DylibLookupFtor, |
| 28 | ExternalLookupFtorT ExternalLookupFtor) |
| 29 | : DylibLookupFtor(DylibLookupFtor), |
| 30 | ExternalLookupFtor(ExternalLookupFtor) {} |
| 31 | |
| 32 | JITSymbol findSymbolInLogicalDylib(const std::string &Name) final { |
| 33 | return DylibLookupFtor(Name); |
| 34 | } |
| 35 | |
| 36 | JITSymbol findSymbol(const std::string &Name) final { |
| 37 | return ExternalLookupFtor(Name); |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | DylibLookupFtorT DylibLookupFtor; |
| 42 | ExternalLookupFtorT ExternalLookupFtor; |
| 43 | }; |
| 44 | |
| 45 | template <typename DylibLookupFtorT, |
| 46 | typename ExternalLookupFtorT> |
| 47 | std::shared_ptr<LambdaResolver<DylibLookupFtorT, ExternalLookupFtorT>> |
| 48 | createLambdaResolver(DylibLookupFtorT DylibLookupFtor, |
| 49 | ExternalLookupFtorT ExternalLookupFtor) { |
| 50 | using LR = LambdaResolver<DylibLookupFtorT, ExternalLookupFtorT>; |
| 51 | return make_unique<LR>(std::move(DylibLookupFtor), |
| 52 | std::move(ExternalLookupFtor)); |
| 53 | } |
| 54 | |
| 55 | } // end namespace orc |
| 56 | } // end namespace llvm |
| 57 | |
| 58 | #endif // LLVM_EXECUTIONENGINE_ORC_LAMBDARESOLVER_H |