blob: ddb72544b770b63ea898c0eaf5c9f3d1c6a152e9 [file] [log] [blame]
Lang Hames635fd902018-01-22 03:00:31 +00001//===------- 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
12namespace llvm {
13namespace orc {
14
Lang Hamesfd0c1e712018-07-20 18:31:50 +000015void SymbolResolver::anchor() {}
16
Lang Hamesd261e122018-05-16 22:24:30 +000017JITSymbolResolverAdapter::JITSymbolResolverAdapter(
18 ExecutionSession &ES, SymbolResolver &R, MaterializationResponsibility *MR)
19 : ES(ES), R(R), MR(MR) {}
Lang Hames635fd902018-01-22 03:00:31 +000020
Lang Hamesadde5ba2018-09-25 19:48:46 +000021void JITSymbolResolverAdapter::lookup(const LookupSet &Symbols,
22 OnResolvedFunction OnResolved) {
Lang Hames635fd902018-01-22 03:00:31 +000023 SymbolNameSet InternedSymbols;
24 for (auto &S : Symbols)
Lang Hames71d781c2018-09-30 23:18:24 +000025 InternedSymbols.insert(ES.intern(S));
Lang Hames635fd902018-01-22 03:00:31 +000026
Lang Hamesadde5ba2018-09-25 19:48:46 +000027 auto OnResolvedWithUnwrap = [OnResolved](Expected<SymbolMap> InternedResult) {
28 if (!InternedResult) {
29 OnResolved(InternedResult.takeError());
30 return;
31 }
32
33 LookupResult Result;
34 for (auto &KV : *InternedResult)
35 Result[*KV.first] = std::move(KV.second);
36 OnResolved(Result);
Lang Hames253584f2018-06-12 20:43:17 +000037 };
Lang Hames635fd902018-01-22 03:00:31 +000038
Lang Hamesadde5ba2018-09-25 19:48:46 +000039 auto Q = std::make_shared<AsynchronousSymbolQuery>(
40 InternedSymbols, OnResolvedWithUnwrap,
41 [this](Error Err) { ES.reportError(std::move(Err)); });
42
43 auto Unresolved = R.lookup(Q, InternedSymbols);
44 if (Unresolved.empty()) {
Lang Hamesa48d1082018-07-20 22:22:19 +000045 if (MR)
Lang Hamesadde5ba2018-09-25 19:48:46 +000046 MR->addDependenciesForAll(Q->QueryRegistrations);
47 } else
48 ES.legacyFailQuery(*Q, make_error<SymbolsNotFound>(std::move(Unresolved)));
Lang Hames635fd902018-01-22 03:00:31 +000049}
50
Lang Hames6cadc7c2018-08-28 21:18:05 +000051Expected<JITSymbolResolverAdapter::LookupSet>
52JITSymbolResolverAdapter::getResponsibilitySet(const LookupSet &Symbols) {
Lang Hames635fd902018-01-22 03:00:31 +000053 SymbolNameSet InternedSymbols;
54 for (auto &S : Symbols)
Lang Hames71d781c2018-09-30 23:18:24 +000055 InternedSymbols.insert(ES.intern(S));
Lang Hames635fd902018-01-22 03:00:31 +000056
Lang Hames6cadc7c2018-08-28 21:18:05 +000057 auto InternedResult = R.getResponsibilitySet(InternedSymbols);
58 LookupSet Result;
59 for (auto &S : InternedResult) {
60 ResolvedStrings.insert(S);
61 Result.insert(*S);
Lang Hames635fd902018-01-22 03:00:31 +000062 }
63
64 return Result;
65}
66
67} // End namespace orc.
68} // End namespace llvm.