mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-18 04:06:08 +00:00

first argument. This makes lookupFlags more consistent with lookup (which takes the query as the first argument) and composes better in practice, since lookups are usually linearly chained: Each lookupFlags can populate the result map based on the symbols not found in the previous lookup. (If the maps were returned rather than passed by reference there would have to be a merge step at the end). llvm-svn: 323398
78 lines
2.2 KiB
C++
78 lines
2.2 KiB
C++
//===------- Legacy.cpp - Adapters for ExecutionEngine API interop --------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ExecutionEngine/Orc/Legacy.h"
|
|
|
|
namespace llvm {
|
|
namespace orc {
|
|
|
|
JITSymbolResolverAdapter::JITSymbolResolverAdapter(ExecutionSession &ES,
|
|
SymbolResolver &R)
|
|
: ES(ES), R(R) {}
|
|
|
|
Expected<JITSymbolResolverAdapter::LookupResult>
|
|
JITSymbolResolverAdapter::lookup(const LookupSet &Symbols) {
|
|
Error Err = Error::success();
|
|
JITSymbolResolver::LookupResult Result;
|
|
|
|
SymbolNameSet InternedSymbols;
|
|
for (auto &S : Symbols)
|
|
InternedSymbols.insert(ES.getSymbolStringPool().intern(S));
|
|
|
|
auto OnResolve = [&](Expected<SymbolMap> R) {
|
|
if (R) {
|
|
for (auto &KV : *R) {
|
|
ResolvedStrings.insert(KV.first);
|
|
Result[*KV.first] = KV.second;
|
|
}
|
|
} else
|
|
Err = joinErrors(std::move(Err), R.takeError());
|
|
};
|
|
|
|
auto OnReady = [](Error Err) {
|
|
// FIXME: Report error to ExecutionSession.
|
|
logAllUnhandledErrors(std::move(Err), errs(),
|
|
"legacy resolver received on-ready error:\n");
|
|
};
|
|
|
|
AsynchronousSymbolQuery Query(InternedSymbols, OnResolve, OnReady);
|
|
|
|
auto UnresolvedSymbols = R.lookup(Query, InternedSymbols);
|
|
|
|
if (!UnresolvedSymbols.empty())
|
|
Err = joinErrors(std::move(Err),
|
|
make_error<StringError>("Unresolved symbols",
|
|
inconvertibleErrorCode()));
|
|
|
|
if (Err)
|
|
return std::move(Err);
|
|
|
|
return Result;
|
|
}
|
|
|
|
Expected<JITSymbolResolverAdapter::LookupFlagsResult>
|
|
JITSymbolResolverAdapter::lookupFlags(const LookupSet &Symbols) {
|
|
SymbolNameSet InternedSymbols;
|
|
for (auto &S : Symbols)
|
|
InternedSymbols.insert(ES.getSymbolStringPool().intern(S));
|
|
|
|
SymbolFlagsMap SymbolFlags;
|
|
R.lookupFlags(SymbolFlags, InternedSymbols);
|
|
LookupFlagsResult Result;
|
|
for (auto &KV : SymbolFlags) {
|
|
ResolvedStrings.insert(KV.first);
|
|
Result[*KV.first] = KV.second;
|
|
}
|
|
|
|
return Result;
|
|
}
|
|
|
|
} // End namespace orc.
|
|
} // End namespace llvm.
|