2018-01-22 11:00:31 +08:00
|
|
|
//===------- Legacy.cpp - Adapters for ExecutionEngine API interop --------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-01-22 11:00:31 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/ExecutionEngine/Orc/Legacy.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace orc {
|
|
|
|
|
2018-07-21 02:31:50 +08:00
|
|
|
void SymbolResolver::anchor() {}
|
|
|
|
|
2018-05-17 06:24:30 +08:00
|
|
|
JITSymbolResolverAdapter::JITSymbolResolverAdapter(
|
|
|
|
ExecutionSession &ES, SymbolResolver &R, MaterializationResponsibility *MR)
|
|
|
|
: ES(ES), R(R), MR(MR) {}
|
2018-01-22 11:00:31 +08:00
|
|
|
|
2018-09-26 03:48:46 +08:00
|
|
|
void JITSymbolResolverAdapter::lookup(const LookupSet &Symbols,
|
|
|
|
OnResolvedFunction OnResolved) {
|
2018-01-22 11:00:31 +08:00
|
|
|
SymbolNameSet InternedSymbols;
|
|
|
|
for (auto &S : Symbols)
|
2018-10-01 07:18:24 +08:00
|
|
|
InternedSymbols.insert(ES.intern(S));
|
2018-01-22 11:00:31 +08:00
|
|
|
|
2019-09-13 19:35:33 +08:00
|
|
|
auto OnResolvedWithUnwrap = [OnResolved = std::move(OnResolved)](
|
|
|
|
Expected<SymbolMap> InternedResult) mutable {
|
2018-09-26 03:48:46 +08:00
|
|
|
if (!InternedResult) {
|
|
|
|
OnResolved(InternedResult.takeError());
|
|
|
|
return;
|
|
|
|
}
|
2018-01-22 11:00:31 +08:00
|
|
|
|
2018-09-26 03:48:46 +08:00
|
|
|
LookupResult Result;
|
|
|
|
for (auto &KV : *InternedResult)
|
|
|
|
Result[*KV.first] = std::move(KV.second);
|
|
|
|
OnResolved(Result);
|
2018-07-21 06:22:19 +08:00
|
|
|
};
|
|
|
|
|
2018-09-26 03:48:46 +08:00
|
|
|
auto Q = std::make_shared<AsynchronousSymbolQuery>(
|
2019-11-26 13:57:27 +08:00
|
|
|
SymbolLookupSet(InternedSymbols), SymbolState::Resolved,
|
|
|
|
std::move(OnResolvedWithUnwrap));
|
2018-09-25 12:54:03 +08:00
|
|
|
|
2018-09-26 03:48:46 +08:00
|
|
|
auto Unresolved = R.lookup(Q, InternedSymbols);
|
|
|
|
if (Unresolved.empty()) {
|
|
|
|
if (MR)
|
|
|
|
MR->addDependenciesForAll(Q->QueryRegistrations);
|
|
|
|
} else
|
|
|
|
ES.legacyFailQuery(*Q, make_error<SymbolsNotFound>(std::move(Unresolved)));
|
2018-01-22 11:00:31 +08:00
|
|
|
}
|
|
|
|
|
2018-08-29 05:18:05 +08:00
|
|
|
Expected<JITSymbolResolverAdapter::LookupSet>
|
|
|
|
JITSymbolResolverAdapter::getResponsibilitySet(const LookupSet &Symbols) {
|
2018-01-22 11:00:31 +08:00
|
|
|
SymbolNameSet InternedSymbols;
|
|
|
|
for (auto &S : Symbols)
|
2018-10-01 07:18:24 +08:00
|
|
|
InternedSymbols.insert(ES.intern(S));
|
2018-01-22 11:00:31 +08:00
|
|
|
|
2018-08-29 05:18:05 +08:00
|
|
|
auto InternedResult = R.getResponsibilitySet(InternedSymbols);
|
|
|
|
LookupSet Result;
|
|
|
|
for (auto &S : InternedResult) {
|
|
|
|
ResolvedStrings.insert(S);
|
|
|
|
Result.insert(*S);
|
2018-01-22 11:00:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End namespace orc.
|
|
|
|
} // End namespace llvm.
|