Lang Hames | 635fd90 | 2018-01-22 03:00:31 +0000 | [diff] [blame] | 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 | |
| 15 | JITSymbolResolverAdapter::JITSymbolResolverAdapter(ExecutionSession &ES, |
| 16 | SymbolResolver &R) |
| 17 | : ES(ES), R(R) {} |
| 18 | |
| 19 | Expected<JITSymbolResolverAdapter::LookupResult> |
| 20 | JITSymbolResolverAdapter::lookup(const LookupSet &Symbols) { |
| 21 | Error Err = Error::success(); |
| 22 | JITSymbolResolver::LookupResult Result; |
| 23 | |
| 24 | SymbolNameSet InternedSymbols; |
| 25 | for (auto &S : Symbols) |
| 26 | InternedSymbols.insert(ES.getSymbolStringPool().intern(S)); |
| 27 | |
| 28 | auto OnResolve = [&](Expected<SymbolMap> R) { |
| 29 | if (R) { |
| 30 | for (auto &KV : *R) { |
| 31 | ResolvedStrings.insert(KV.first); |
| 32 | Result[*KV.first] = KV.second; |
| 33 | } |
| 34 | } else |
| 35 | Err = joinErrors(std::move(Err), R.takeError()); |
| 36 | }; |
| 37 | |
| 38 | auto OnReady = [](Error Err) { |
| 39 | // FIXME: Report error to ExecutionSession. |
| 40 | logAllUnhandledErrors(std::move(Err), errs(), |
| 41 | "legacy resolver received on-ready error:\n"); |
| 42 | }; |
| 43 | |
| 44 | AsynchronousSymbolQuery Query(InternedSymbols, OnResolve, OnReady); |
| 45 | |
| 46 | auto UnresolvedSymbols = R.lookup(Query, InternedSymbols); |
| 47 | |
Lang Hames | 4b546c9 | 2018-02-06 21:25:11 +0000 | [diff] [blame^] | 48 | if (!UnresolvedSymbols.empty()) { |
| 49 | std::string ErrorMsg = "Unresolved symbols: "; |
| 50 | |
| 51 | ErrorMsg += **UnresolvedSymbols.begin(); |
| 52 | for (auto I = std::next(UnresolvedSymbols.begin()), |
| 53 | E = UnresolvedSymbols.end(); |
| 54 | I != E; ++I) { |
| 55 | ErrorMsg += ", "; |
| 56 | ErrorMsg += **I; |
| 57 | } |
| 58 | |
| 59 | Err = |
| 60 | joinErrors(std::move(Err), |
| 61 | make_error<StringError>(ErrorMsg, inconvertibleErrorCode())); |
| 62 | } |
Lang Hames | 635fd90 | 2018-01-22 03:00:31 +0000 | [diff] [blame] | 63 | |
| 64 | if (Err) |
| 65 | return std::move(Err); |
| 66 | |
| 67 | return Result; |
| 68 | } |
| 69 | |
| 70 | Expected<JITSymbolResolverAdapter::LookupFlagsResult> |
| 71 | JITSymbolResolverAdapter::lookupFlags(const LookupSet &Symbols) { |
| 72 | SymbolNameSet InternedSymbols; |
| 73 | for (auto &S : Symbols) |
| 74 | InternedSymbols.insert(ES.getSymbolStringPool().intern(S)); |
| 75 | |
Lang Hames | c8a74a0 | 2018-01-25 01:43:00 +0000 | [diff] [blame] | 76 | SymbolFlagsMap SymbolFlags; |
| 77 | R.lookupFlags(SymbolFlags, InternedSymbols); |
Lang Hames | 635fd90 | 2018-01-22 03:00:31 +0000 | [diff] [blame] | 78 | LookupFlagsResult Result; |
Lang Hames | c8a74a0 | 2018-01-25 01:43:00 +0000 | [diff] [blame] | 79 | for (auto &KV : SymbolFlags) { |
Lang Hames | 635fd90 | 2018-01-22 03:00:31 +0000 | [diff] [blame] | 80 | ResolvedStrings.insert(KV.first); |
| 81 | Result[*KV.first] = KV.second; |
| 82 | } |
| 83 | |
| 84 | return Result; |
| 85 | } |
| 86 | |
| 87 | } // End namespace orc. |
| 88 | } // End namespace llvm. |