| 1 | //===------- LookupAndRecordAddrs.h - Symbol lookup support utility -------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/ExecutionEngine/Orc/LookupAndRecordAddrs.h" |
| 10 | |
| 11 | #include <future> |
| 12 | |
| 13 | namespace llvm { |
| 14 | namespace orc { |
| 15 | |
| 16 | void lookupAndRecordAddrs( |
| 17 | unique_function<void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K, |
| 18 | const JITDylibSearchOrder &SearchOrder, |
| 19 | std::vector<std::pair<SymbolStringPtr, ExecutorAddr *>> Pairs, |
| 20 | SymbolLookupFlags LookupFlags) { |
| 21 | |
| 22 | SymbolLookupSet Symbols; |
| 23 | for (auto &KV : Pairs) |
| 24 | Symbols.add(Name: KV.first, Flags: LookupFlags); |
| 25 | |
| 26 | ES.lookup( |
| 27 | K, SearchOrder, Symbols: std::move(Symbols), RequiredState: SymbolState::Ready, |
| 28 | NotifyComplete: [Pairs = std::move(Pairs), |
| 29 | OnRec = std::move(OnRecorded)](Expected<SymbolMap> Result) mutable { |
| 30 | if (!Result) |
| 31 | return OnRec(Result.takeError()); |
| 32 | for (auto &KV : Pairs) { |
| 33 | auto I = Result->find(Val: KV.first); |
| 34 | *KV.second = |
| 35 | I != Result->end() ? I->second.getAddress() : orc::ExecutorAddr(); |
| 36 | } |
| 37 | OnRec(Error::success()); |
| 38 | }, |
| 39 | RegisterDependencies: NoDependenciesToRegister); |
| 40 | } |
| 41 | |
| 42 | Error lookupAndRecordAddrs( |
| 43 | ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder, |
| 44 | std::vector<std::pair<SymbolStringPtr, ExecutorAddr *>> Pairs, |
| 45 | SymbolLookupFlags LookupFlags) { |
| 46 | |
| 47 | std::promise<MSVCPError> ResultP; |
| 48 | auto ResultF = ResultP.get_future(); |
| 49 | lookupAndRecordAddrs(OnRecorded: [&](Error Err) { ResultP.set_value(std::move(Err)); }, |
| 50 | ES, K, SearchOrder, Pairs: std::move(Pairs), LookupFlags); |
| 51 | return ResultF.get(); |
| 52 | } |
| 53 | |
| 54 | } // End namespace orc. |
| 55 | } // End namespace llvm. |
| 56 | |