1 //===------- Legacy.cpp - Adapters for ExecutionEngine API interop --------===//
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 #include "llvm/ExecutionEngine/Orc/Legacy.h"
11
12 namespace llvm {
13 namespace orc {
14
anchor()15 void SymbolResolver::anchor() {}
16
JITSymbolResolverAdapter(ExecutionSession & ES,SymbolResolver & R,MaterializationResponsibility * MR)17 JITSymbolResolverAdapter::JITSymbolResolverAdapter(
18 ExecutionSession &ES, SymbolResolver &R, MaterializationResponsibility *MR)
19 : ES(ES), R(R), MR(MR) {}
20
21 Expected<JITSymbolResolverAdapter::LookupResult>
lookup(const LookupSet & Symbols)22 JITSymbolResolverAdapter::lookup(const LookupSet &Symbols) {
23 SymbolNameSet InternedSymbols;
24 for (auto &S : Symbols)
25 InternedSymbols.insert(ES.getSymbolStringPool().intern(S));
26
27 auto LookupFn = [&, this](std::shared_ptr<AsynchronousSymbolQuery> Q,
28 SymbolNameSet Unresolved) {
29 return R.lookup(std::move(Q), std::move(Unresolved));
30 };
31
32 auto RegisterDependencies = [&](const SymbolDependenceMap &Deps) {
33 if (MR)
34 MR->addDependenciesForAll(Deps);
35 };
36
37 auto InternedResult =
38 ES.legacyLookup(ES, std::move(LookupFn), std::move(InternedSymbols),
39 false, RegisterDependencies);
40
41 if (!InternedResult)
42 return InternedResult.takeError();
43
44 JITSymbolResolver::LookupResult Result;
45 for (auto &KV : *InternedResult)
46 Result[*KV.first] = KV.second;
47
48 return Result;
49 }
50
51 Expected<JITSymbolResolverAdapter::LookupFlagsResult>
lookupFlags(const LookupSet & Symbols)52 JITSymbolResolverAdapter::lookupFlags(const LookupSet &Symbols) {
53 SymbolNameSet InternedSymbols;
54 for (auto &S : Symbols)
55 InternedSymbols.insert(ES.getSymbolStringPool().intern(S));
56
57 SymbolFlagsMap SymbolFlags = R.lookupFlags(InternedSymbols);
58 LookupFlagsResult Result;
59 for (auto &KV : SymbolFlags) {
60 ResolvedStrings.insert(KV.first);
61 Result[*KV.first] = KV.second;
62 }
63
64 return Result;
65 }
66
67 } // End namespace orc.
68 } // End namespace llvm.
69