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