• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- LambdaResolverMM - Redirect symbol lookup via a functor -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //   Defines a RuntimeDyld::SymbolResolver subclass that uses a user-supplied
11 // functor for symbol resolution.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_EXECUTIONENGINE_ORC_LAMBDARESOLVER_H
16 #define LLVM_EXECUTIONENGINE_ORC_LAMBDARESOLVER_H
17 
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ExecutionEngine/RuntimeDyld.h"
20 #include <memory>
21 
22 namespace llvm {
23 namespace orc {
24 
25 template <typename DylibLookupFtorT, typename ExternalLookupFtorT>
26 class LambdaResolver : public RuntimeDyld::SymbolResolver {
27 public:
28 
LambdaResolver(DylibLookupFtorT DylibLookupFtor,ExternalLookupFtorT ExternalLookupFtor)29   LambdaResolver(DylibLookupFtorT DylibLookupFtor,
30                  ExternalLookupFtorT ExternalLookupFtor)
31       : DylibLookupFtor(DylibLookupFtor),
32         ExternalLookupFtor(ExternalLookupFtor) {}
33 
34   RuntimeDyld::SymbolInfo
findSymbolInLogicalDylib(const std::string & Name)35   findSymbolInLogicalDylib(const std::string &Name) final {
36     return DylibLookupFtor(Name);
37   }
38 
findSymbol(const std::string & Name)39   RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) final {
40     return ExternalLookupFtor(Name);
41   }
42 
43 private:
44   DylibLookupFtorT DylibLookupFtor;
45   ExternalLookupFtorT ExternalLookupFtor;
46 };
47 
48 template <typename DylibLookupFtorT,
49           typename ExternalLookupFtorT>
50 std::unique_ptr<LambdaResolver<DylibLookupFtorT, ExternalLookupFtorT>>
createLambdaResolver(DylibLookupFtorT DylibLookupFtor,ExternalLookupFtorT ExternalLookupFtor)51 createLambdaResolver(DylibLookupFtorT DylibLookupFtor,
52                      ExternalLookupFtorT ExternalLookupFtor) {
53   typedef LambdaResolver<DylibLookupFtorT, ExternalLookupFtorT> LR;
54   return make_unique<LR>(std::move(DylibLookupFtor),
55                          std::move(ExternalLookupFtor));
56 }
57 
58 } // End namespace orc.
59 } // End namespace llvm.
60 
61 #endif // LLVM_EXECUTIONENGINE_ORC_LAMBDARESOLVER_H
62