LLVM 22.0.0git
OrcError.cpp
Go to the documentation of this file.
1//===---------------- OrcError.cpp - Error codes for ORC ------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// Error codes for ORC.
10//
11//===----------------------------------------------------------------------===//
12
15
16#include <type_traits>
17
18using namespace llvm;
19using namespace llvm::orc;
20
21namespace {
22
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.
26class OrcErrorCategory : public std::error_category {
27public:
28 const char *name() const noexcept override { return "orc"; }
29
30 std::string message(int condition) const override {
31 switch (static_cast<OrcErrorCode>(condition)) {
32 case OrcErrorCode::UnknownORCError:
33 return "Unknown ORC error";
34 case OrcErrorCode::DuplicateDefinition:
35 return "Duplicate symbol definition";
36 case OrcErrorCode::JITSymbolNotFound:
37 return "JIT symbol not found";
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";
48 case OrcErrorCode::RPCConnectionClosed:
49 return "RPC connection closed";
50 case OrcErrorCode::RPCCouldNotNegotiateFunction:
51 return "Could not negotiate RPC function";
52 case OrcErrorCode::RPCResponseAbandoned:
53 return "RPC response abandoned";
54 case OrcErrorCode::UnexpectedRPCCall:
55 return "Unexpected RPC call";
56 case OrcErrorCode::UnexpectedRPCResponse:
57 return "Unexpected RPC response";
58 case OrcErrorCode::UnknownErrorCodeFromRemote:
59 return "Unknown error returned from remote RPC function "
60 "(Use StringError to get error message)";
61 case OrcErrorCode::UnknownResourceHandle:
62 return "Unknown resource handle";
63 case OrcErrorCode::MissingSymbolDefinitions:
64 return "MissingSymbolsDefinitions";
65 case OrcErrorCode::UnexpectedSymbolDefinitions:
66 return "UnexpectedSymbolDefinitions";
67 }
68 llvm_unreachable("Unhandled error code");
69 }
70};
71
72OrcErrorCategory &getOrcErrCat() {
73 static OrcErrorCategory OrcErrCat;
74 return OrcErrCat;
75}
76} // namespace
77
78namespace llvm {
79namespace orc {
80
83
84std::error_code orcError(OrcErrorCode ErrCode) {
85 typedef std::underlying_type_t<OrcErrorCode> UT;
86 return std::error_code(static_cast<UT>(ErrCode), getOrcErrCat());
87}
88
90 std::optional<std::string> Context)
91 : SymbolName(std::move(SymbolName)), Context(std::move(Context)) {}
92
95}
96
98 if (Context)
99 OS << "In " << *Context << ", ";
100 OS << "duplicate definition of symbol '" << SymbolName << "'";
101}
102
103const std::string &DuplicateDefinition::getSymbolName() const {
104 return SymbolName;
105}
106
107const std::optional<std::string> &DuplicateDefinition::getContext() const {
108 return Context;
109}
110
112 : SymbolName(std::move(SymbolName)) {}
113
115 typedef std::underlying_type_t<OrcErrorCode> UT;
116 return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound),
117 getOrcErrCat());
118}
119
121 OS << "Could not find symbol '" << SymbolName << "'";
122}
123
124const std::string &JITSymbolNotFound::getSymbolName() const {
125 return SymbolName;
126}
127
128} // namespace orc
129} // namespace llvm
aarch64 promote const
static const char * name
Definition: SMEABIPass.cpp:52
raw_pwrite_stream & OS
const std::string & getSymbolName() const
Definition: OrcError.cpp:103
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: OrcError.cpp:97
DuplicateDefinition(std::string SymbolName, std::optional< std::string > Context={})
Definition: OrcError.cpp:89
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: OrcError.cpp:93
const std::optional< std::string > & getContext() const
Definition: OrcError.cpp:107
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: OrcError.cpp:120
JITSymbolNotFound(std::string SymbolName)
Definition: OrcError.cpp:111
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: OrcError.cpp:114
const std::string & getSymbolName() const
Definition: OrcError.cpp:124
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
OrcErrorCode
Definition: OrcError.h:25
LLVM_ABI std::error_code orcError(OrcErrorCode ErrCode)
Definition: OrcError.cpp:84
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856