blob: 92efdeded36254c4b91855fab2957a6b6f9dab23 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- LambdaResolverMM - Redirect symbol lookup via a functor --*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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 Scull5e1ddfa2018-08-14 10:06:54 +01006//
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
21namespace llvm {
22namespace orc {
23
24template <typename DylibLookupFtorT, typename ExternalLookupFtorT>
25class LambdaResolver : public LegacyJITSymbolResolver {
26public:
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
40private:
41 DylibLookupFtorT DylibLookupFtor;
42 ExternalLookupFtorT ExternalLookupFtor;
43};
44
45template <typename DylibLookupFtorT,
46 typename ExternalLookupFtorT>
47std::shared_ptr<LambdaResolver<DylibLookupFtorT, ExternalLookupFtorT>>
48createLambdaResolver(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