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)) { |
| 32 | case OrcErrorCode::RemoteAllocatorDoesNotExist: |
| 33 | return "Remote allocator does not exist"; |
| 34 | case OrcErrorCode::RemoteAllocatorIdAlreadyInUse: |
| 35 | return "Remote allocator Id already in use"; |
| 36 | case OrcErrorCode::RemoteMProtectAddrUnrecognized: |
| 37 | return "Remote mprotect call references unallocated memory"; |
| 38 | case OrcErrorCode::RemoteIndirectStubsOwnerDoesNotExist: |
| 39 | return "Remote indirect stubs owner does not exist"; |
| 40 | case OrcErrorCode::RemoteIndirectStubsOwnerIdAlreadyInUse: |
| 41 | return "Remote indirect stubs owner Id already in use"; |
| 42 | case OrcErrorCode::UnexpectedRPCCall: |
| 43 | return "Unexpected RPC call"; |
Lang Hames | 3fde652 | 2016-04-18 19:55:43 +0000 | [diff] [blame] | 44 | case OrcErrorCode::UnexpectedRPCResponse: |
| 45 | return "Unexpected RPC response"; |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 46 | } |
| 47 | llvm_unreachable("Unhandled error code"); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | static ManagedStatic<OrcErrorCategory> OrcErrCat; |
| 52 | } |
| 53 | |
| 54 | namespace llvm { |
| 55 | namespace orc { |
| 56 | |
Lang Hames | ef5a0ee | 2016-04-25 19:56:45 +0000 | [diff] [blame] | 57 | Error orcError(OrcErrorCode ErrCode) { |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 58 | typedef std::underlying_type<OrcErrorCode>::type UT; |
Lang Hames | 1fa0e0e | 2016-04-25 21:21:20 +0000 | [diff] [blame] | 59 | return errorCodeToError( |
| 60 | std::error_code(static_cast<UT>(ErrCode), *OrcErrCat)); |
Lang Hames | 4026f90 | 2016-01-11 00:34:13 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |