blob: 9b1c028d7047d7f9bc0fcff1e73f7210fad4e8c4 [file] [log] [blame]
Lang Hames4026f902016-01-11 00:34:13 +00001//===---------------- OrcError.cpp - Error codes for ORC ------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Hames4026f902016-01-11 00:34:13 +00006//
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
Lang Hames76bcbaa2019-11-20 17:27:44 -080017#include <type_traits>
18
Lang Hames4026f902016-01-11 00:34:13 +000019using namespace llvm;
20using namespace llvm::orc;
21
22namespace {
23
Peter Collingbourne4718f8b2016-05-24 20:13:46 +000024// FIXME: This class is only here to support the transition to llvm::Error. It
25// will be removed once this transition is complete. Clients should prefer to
26// deal with the Error value directly, rather than converting to error_code.
Lang Hames4026f902016-01-11 00:34:13 +000027class OrcErrorCategory : public std::error_category {
28public:
Reid Kleckner990504e2016-10-19 23:52:38 +000029 const char *name() const noexcept override { return "orc"; }
Lang Hames4026f902016-01-11 00:34:13 +000030
31 std::string message(int condition) const override {
32 switch (static_cast<OrcErrorCode>(condition)) {
Lang Hames9d8877b2018-04-12 18:35:08 +000033 case OrcErrorCode::UnknownORCError:
34 return "Unknown ORC error";
Lang Hames1097dc42018-01-05 22:50:43 +000035 case OrcErrorCode::DuplicateDefinition:
36 return "Duplicate symbol definition";
37 case OrcErrorCode::JITSymbolNotFound:
38 return "JIT symbol not found";
Lang Hames4026f902016-01-11 00:34:13 +000039 case OrcErrorCode::RemoteAllocatorDoesNotExist:
40 return "Remote allocator does not exist";
41 case OrcErrorCode::RemoteAllocatorIdAlreadyInUse:
42 return "Remote allocator Id already in use";
43 case OrcErrorCode::RemoteMProtectAddrUnrecognized:
44 return "Remote mprotect call references unallocated memory";
45 case OrcErrorCode::RemoteIndirectStubsOwnerDoesNotExist:
46 return "Remote indirect stubs owner does not exist";
47 case OrcErrorCode::RemoteIndirectStubsOwnerIdAlreadyInUse:
48 return "Remote indirect stubs owner Id already in use";
Lang Hames22bc7b92017-04-13 01:03:06 +000049 case OrcErrorCode::RPCConnectionClosed:
50 return "RPC connection closed";
51 case OrcErrorCode::RPCCouldNotNegotiateFunction:
52 return "Could not negotiate RPC function";
Lang Hamesc9d0ff12016-12-25 21:55:05 +000053 case OrcErrorCode::RPCResponseAbandoned:
54 return "RPC response abandoned";
Lang Hames4026f902016-01-11 00:34:13 +000055 case OrcErrorCode::UnexpectedRPCCall:
56 return "Unexpected RPC call";
Lang Hames3fde6522016-04-18 19:55:43 +000057 case OrcErrorCode::UnexpectedRPCResponse:
58 return "Unexpected RPC response";
Lang Hamesffad0102017-04-13 03:51:35 +000059 case OrcErrorCode::UnknownErrorCodeFromRemote:
60 return "Unknown error returned from remote RPC function "
61 "(Use StringError to get error message)";
Lang Hames617fc352017-09-05 03:34:09 +000062 case OrcErrorCode::UnknownResourceHandle:
63 return "Unknown resource handle";
Lang Hames81726892020-02-21 17:38:42 -080064 case OrcErrorCode::MissingSymbolDefinitions:
65 return "MissingSymbolsDefinitions";
66 case OrcErrorCode::UnexpectedSymbolDefinitions:
67 return "UnexpectedSymbolDefinitions";
Lang Hames4026f902016-01-11 00:34:13 +000068 }
69 llvm_unreachable("Unhandled error code");
70 }
71};
72
73static ManagedStatic<OrcErrorCategory> OrcErrCat;
Lang Hames1d0676b2020-11-11 11:55:24 +110074} // namespace
Lang Hames4026f902016-01-11 00:34:13 +000075
76namespace llvm {
77namespace orc {
78
Lang Hames1097dc42018-01-05 22:50:43 +000079char DuplicateDefinition::ID = 0;
Lang Hames4ce98662017-07-07 02:59:13 +000080char JITSymbolNotFound::ID = 0;
81
Lang Hamesa1d0f712017-04-06 01:35:13 +000082std::error_code orcError(OrcErrorCode ErrCode) {
Lang Hames4026f902016-01-11 00:34:13 +000083 typedef std::underlying_type<OrcErrorCode>::type UT;
Lang Hamesa1d0f712017-04-06 01:35:13 +000084 return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat);
Lang Hames4026f902016-01-11 00:34:13 +000085}
Lang Hames021cb2b2017-01-15 06:34:25 +000086
Lang Hames1097dc42018-01-05 22:50:43 +000087DuplicateDefinition::DuplicateDefinition(std::string SymbolName)
Lang Hames1d0676b2020-11-11 11:55:24 +110088 : SymbolName(std::move(SymbolName)) {}
Lang Hames1097dc42018-01-05 22:50:43 +000089
90std::error_code DuplicateDefinition::convertToErrorCode() const {
91 return orcError(OrcErrorCode::DuplicateDefinition);
92}
93
94void DuplicateDefinition::log(raw_ostream &OS) const {
95 OS << "Duplicate definition of symbol '" << SymbolName << "'";
96}
97
98const std::string &DuplicateDefinition::getSymbolName() const {
99 return SymbolName;
100}
101
Lang Hames4ce98662017-07-07 02:59:13 +0000102JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)
Lang Hames1d0676b2020-11-11 11:55:24 +1100103 : SymbolName(std::move(SymbolName)) {}
Lang Hames4ce98662017-07-07 02:59:13 +0000104
105std::error_code JITSymbolNotFound::convertToErrorCode() const {
106 typedef std::underlying_type<OrcErrorCode>::type UT;
107 return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound),
108 *OrcErrCat);
109}
110
111void JITSymbolNotFound::log(raw_ostream &OS) const {
112 OS << "Could not find symbol '" << SymbolName << "'";
113}
114
115const std::string &JITSymbolNotFound::getSymbolName() const {
116 return SymbolName;
117}
118
Lang Hames1d0676b2020-11-11 11:55:24 +1100119} // namespace orc
120} // namespace llvm