blob: f0bfed8ddb8a4757f6e480670ff29546f64ec2cc [file] [log] [blame]
Lang Hames4026f902016-01-11 00:34:13 +00001//===---------------- 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
18using namespace llvm;
19using namespace llvm::orc;
20
21namespace {
22
Peter Collingbourne4718f8b2016-05-24 20:13:46 +000023// 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 Hames4026f902016-01-11 00:34:13 +000026class OrcErrorCategory : public std::error_category {
27public:
Reid Kleckner990504e2016-10-19 23:52:38 +000028 const char *name() const noexcept override { return "orc"; }
Lang Hames4026f902016-01-11 00:34:13 +000029
30 std::string message(int condition) const override {
31 switch (static_cast<OrcErrorCode>(condition)) {
Lang Hames1097dc42018-01-05 22:50:43 +000032 case OrcErrorCode::DuplicateDefinition:
33 return "Duplicate symbol definition";
34 case OrcErrorCode::JITSymbolNotFound:
35 return "JIT symbol not found";
Lang Hames4026f902016-01-11 00:34:13 +000036 case OrcErrorCode::RemoteAllocatorDoesNotExist:
37 return "Remote allocator does not exist";
38 case OrcErrorCode::RemoteAllocatorIdAlreadyInUse:
39 return "Remote allocator Id already in use";
40 case OrcErrorCode::RemoteMProtectAddrUnrecognized:
41 return "Remote mprotect call references unallocated memory";
42 case OrcErrorCode::RemoteIndirectStubsOwnerDoesNotExist:
43 return "Remote indirect stubs owner does not exist";
44 case OrcErrorCode::RemoteIndirectStubsOwnerIdAlreadyInUse:
45 return "Remote indirect stubs owner Id already in use";
Lang Hames22bc7b92017-04-13 01:03:06 +000046 case OrcErrorCode::RPCConnectionClosed:
47 return "RPC connection closed";
48 case OrcErrorCode::RPCCouldNotNegotiateFunction:
49 return "Could not negotiate RPC function";
Lang Hamesc9d0ff12016-12-25 21:55:05 +000050 case OrcErrorCode::RPCResponseAbandoned:
51 return "RPC response abandoned";
Lang Hames4026f902016-01-11 00:34:13 +000052 case OrcErrorCode::UnexpectedRPCCall:
53 return "Unexpected RPC call";
Lang Hames3fde6522016-04-18 19:55:43 +000054 case OrcErrorCode::UnexpectedRPCResponse:
55 return "Unexpected RPC response";
Lang Hamesffad0102017-04-13 03:51:35 +000056 case OrcErrorCode::UnknownErrorCodeFromRemote:
57 return "Unknown error returned from remote RPC function "
58 "(Use StringError to get error message)";
Lang Hames617fc352017-09-05 03:34:09 +000059 case OrcErrorCode::UnknownResourceHandle:
60 return "Unknown resource handle";
Lang Hames4026f902016-01-11 00:34:13 +000061 }
62 llvm_unreachable("Unhandled error code");
63 }
64};
65
66static ManagedStatic<OrcErrorCategory> OrcErrCat;
67}
68
69namespace llvm {
70namespace orc {
71
Lang Hames1097dc42018-01-05 22:50:43 +000072char DuplicateDefinition::ID = 0;
Lang Hames4ce98662017-07-07 02:59:13 +000073char JITSymbolNotFound::ID = 0;
74
Lang Hamesa1d0f712017-04-06 01:35:13 +000075std::error_code orcError(OrcErrorCode ErrCode) {
Lang Hames4026f902016-01-11 00:34:13 +000076 typedef std::underlying_type<OrcErrorCode>::type UT;
Lang Hamesa1d0f712017-04-06 01:35:13 +000077 return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat);
Lang Hames4026f902016-01-11 00:34:13 +000078}
Lang Hames021cb2b2017-01-15 06:34:25 +000079
Lang Hames1097dc42018-01-05 22:50:43 +000080
81DuplicateDefinition::DuplicateDefinition(std::string SymbolName)
82 : SymbolName(std::move(SymbolName)) {}
83
84std::error_code DuplicateDefinition::convertToErrorCode() const {
85 return orcError(OrcErrorCode::DuplicateDefinition);
86}
87
88void DuplicateDefinition::log(raw_ostream &OS) const {
89 OS << "Duplicate definition of symbol '" << SymbolName << "'";
90}
91
92const std::string &DuplicateDefinition::getSymbolName() const {
93 return SymbolName;
94}
95
Lang Hames4ce98662017-07-07 02:59:13 +000096JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)
97 : SymbolName(std::move(SymbolName)) {}
98
99std::error_code JITSymbolNotFound::convertToErrorCode() const {
100 typedef std::underlying_type<OrcErrorCode>::type UT;
101 return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound),
102 *OrcErrCat);
103}
104
105void JITSymbolNotFound::log(raw_ostream &OS) const {
106 OS << "Could not find symbol '" << SymbolName << "'";
107}
108
109const std::string &JITSymbolNotFound::getSymbolName() const {
110 return SymbolName;
111}
112
Lang Hames4026f902016-01-11 00:34:13 +0000113}
114}