Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 1 | //===---------------- OrcError.cpp - Error codes for ORC ------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Error codes for ORC. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "llvm/ExecutionEngine/Orc/OrcError.h" |
| 14 | #include "llvm/Support/ErrorHandling.h" |
| 15 | #include "llvm/Support/ManagedStatic.h" |
| 16 | |
| 17 | using namespace llvm; |
| 18 | using namespace llvm::orc; |
| 19 | |
| 20 | namespace { |
| 21 | |
Peter Collingbourne | 4718f8b | 2016-05-24 20:13:46 +0000 | [diff] [blame] | 22 | // FIXME: This class is only here to support the transition to llvm::Error. It |
| 23 | // will be removed once this transition is complete. Clients should prefer to |
| 24 | // deal with the Error value directly, rather than converting to error_code. |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 25 | class OrcErrorCategory : public std::error_category { |
| 26 | public: |
Reid Kleckner | 990504e | 2016-10-19 23:52:38 +0000 | [diff] [blame] | 27 | const char *name() const noexcept override { return "orc"; } |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 28 | |
| 29 | std::string message(int condition) const override { |
| 30 | switch (static_cast<OrcErrorCode>(condition)) { |
Lang Hames | 9d8877b | 2018-04-12 18:35:08 +0000 | [diff] [blame] | 31 | case OrcErrorCode::UnknownORCError: |
| 32 | return "Unknown ORC error"; |
Lang Hames | 1097dc4 | 2018-01-05 22:50:43 +0000 | [diff] [blame] | 33 | case OrcErrorCode::DuplicateDefinition: |
| 34 | return "Duplicate symbol definition"; |
| 35 | case OrcErrorCode::JITSymbolNotFound: |
| 36 | return "JIT symbol not found"; |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 37 | case OrcErrorCode::RemoteAllocatorDoesNotExist: |
| 38 | return "Remote allocator does not exist"; |
| 39 | case OrcErrorCode::RemoteAllocatorIdAlreadyInUse: |
| 40 | return "Remote allocator Id already in use"; |
| 41 | case OrcErrorCode::RemoteMProtectAddrUnrecognized: |
| 42 | return "Remote mprotect call references unallocated memory"; |
| 43 | case OrcErrorCode::RemoteIndirectStubsOwnerDoesNotExist: |
| 44 | return "Remote indirect stubs owner does not exist"; |
| 45 | case OrcErrorCode::RemoteIndirectStubsOwnerIdAlreadyInUse: |
| 46 | return "Remote indirect stubs owner Id already in use"; |
Lang Hames | 22bc7b9 | 2017-04-13 01:03:06 +0000 | [diff] [blame] | 47 | case OrcErrorCode::RPCConnectionClosed: |
| 48 | return "RPC connection closed"; |
| 49 | case OrcErrorCode::RPCCouldNotNegotiateFunction: |
| 50 | return "Could not negotiate RPC function"; |
Lang Hames | c9d0ff1 | 2016-12-25 21:55:05 +0000 | [diff] [blame] | 51 | case OrcErrorCode::RPCResponseAbandoned: |
| 52 | return "RPC response abandoned"; |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 53 | case OrcErrorCode::UnexpectedRPCCall: |
| 54 | return "Unexpected RPC call"; |
Lang Hames | 3fde652 | 2016-04-18 19:55:43 +0000 | [diff] [blame] | 55 | case OrcErrorCode::UnexpectedRPCResponse: |
| 56 | return "Unexpected RPC response"; |
Lang Hames | ffad010 | 2017-04-13 03:51:35 +0000 | [diff] [blame] | 57 | case OrcErrorCode::UnknownErrorCodeFromRemote: |
| 58 | return "Unknown error returned from remote RPC function " |
| 59 | "(Use StringError to get error message)"; |
Lang Hames | 617fc35 | 2017-09-05 03:34:09 +0000 | [diff] [blame] | 60 | case OrcErrorCode::UnknownResourceHandle: |
| 61 | return "Unknown resource handle"; |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 62 | } |
| 63 | llvm_unreachable("Unhandled error code"); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | static ManagedStatic<OrcErrorCategory> OrcErrCat; |
| 68 | } |
| 69 | |
| 70 | namespace llvm { |
| 71 | namespace orc { |
| 72 | |
Lang Hames | 1097dc4 | 2018-01-05 22:50:43 +0000 | [diff] [blame] | 73 | char DuplicateDefinition::ID = 0; |
Lang Hames | 4ce9866 | 2017-07-07 02:59:13 +0000 | [diff] [blame] | 74 | char JITSymbolNotFound::ID = 0; |
| 75 | |
Lang Hames | a1d0f71 | 2017-04-06 01:35:13 +0000 | [diff] [blame] | 76 | std::error_code orcError(OrcErrorCode ErrCode) { |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 77 | typedef std::underlying_type<OrcErrorCode>::type UT; |
Lang Hames | a1d0f71 | 2017-04-06 01:35:13 +0000 | [diff] [blame] | 78 | return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat); |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 79 | } |
Lang Hames | 021cb2b | 2017-01-15 06:34:25 +0000 | [diff] [blame] | 80 | |
Lang Hames | 1097dc4 | 2018-01-05 22:50:43 +0000 | [diff] [blame] | 81 | |
| 82 | DuplicateDefinition::DuplicateDefinition(std::string SymbolName) |
| 83 | : SymbolName(std::move(SymbolName)) {} |
| 84 | |
| 85 | std::error_code DuplicateDefinition::convertToErrorCode() const { |
| 86 | return orcError(OrcErrorCode::DuplicateDefinition); |
| 87 | } |
| 88 | |
| 89 | void DuplicateDefinition::log(raw_ostream &OS) const { |
| 90 | OS << "Duplicate definition of symbol '" << SymbolName << "'"; |
| 91 | } |
| 92 | |
| 93 | const std::string &DuplicateDefinition::getSymbolName() const { |
| 94 | return SymbolName; |
| 95 | } |
| 96 | |
Lang Hames | 4ce9866 | 2017-07-07 02:59:13 +0000 | [diff] [blame] | 97 | JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName) |
| 98 | : SymbolName(std::move(SymbolName)) {} |
| 99 | |
| 100 | std::error_code JITSymbolNotFound::convertToErrorCode() const { |
| 101 | typedef std::underlying_type<OrcErrorCode>::type UT; |
| 102 | return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound), |
| 103 | *OrcErrCat); |
| 104 | } |
| 105 | |
| 106 | void JITSymbolNotFound::log(raw_ostream &OS) const { |
| 107 | OS << "Could not find symbol '" << SymbolName << "'"; |
| 108 | } |
| 109 | |
| 110 | const std::string &JITSymbolNotFound::getSymbolName() const { |
| 111 | return SymbolName; |
| 112 | } |
| 113 | |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 114 | } |
| 115 | } |