[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / ExecutionEngine / Orc / Shared / OrcError.cpp
blobfdad90cbcfb747f1744bade0db0e2ff7020678c8
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.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ExecutionEngine/Orc/Shared/OrcError.h"
14 #include "llvm/Support/ErrorHandling.h"
15 #include "llvm/Support/ManagedStatic.h"
17 #include <type_traits>
19 using namespace llvm;
20 using namespace llvm::orc;
22 namespace {
24 // 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.
27 class OrcErrorCategory : public std::error_category {
28 public:
29 const char *name() const noexcept override { return "orc"; }
31 std::string message(int condition) const override {
32 switch (static_cast<OrcErrorCode>(condition)) {
33 case OrcErrorCode::UnknownORCError:
34 return "Unknown ORC error";
35 case OrcErrorCode::DuplicateDefinition:
36 return "Duplicate symbol definition";
37 case OrcErrorCode::JITSymbolNotFound:
38 return "JIT symbol not found";
39 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";
49 case OrcErrorCode::RPCConnectionClosed:
50 return "RPC connection closed";
51 case OrcErrorCode::RPCCouldNotNegotiateFunction:
52 return "Could not negotiate RPC function";
53 case OrcErrorCode::RPCResponseAbandoned:
54 return "RPC response abandoned";
55 case OrcErrorCode::UnexpectedRPCCall:
56 return "Unexpected RPC call";
57 case OrcErrorCode::UnexpectedRPCResponse:
58 return "Unexpected RPC response";
59 case OrcErrorCode::UnknownErrorCodeFromRemote:
60 return "Unknown error returned from remote RPC function "
61 "(Use StringError to get error message)";
62 case OrcErrorCode::UnknownResourceHandle:
63 return "Unknown resource handle";
64 case OrcErrorCode::MissingSymbolDefinitions:
65 return "MissingSymbolsDefinitions";
66 case OrcErrorCode::UnexpectedSymbolDefinitions:
67 return "UnexpectedSymbolDefinitions";
69 llvm_unreachable("Unhandled error code");
73 static ManagedStatic<OrcErrorCategory> OrcErrCat;
74 } // namespace
76 namespace llvm {
77 namespace orc {
79 char DuplicateDefinition::ID = 0;
80 char JITSymbolNotFound::ID = 0;
82 std::error_code orcError(OrcErrorCode ErrCode) {
83 typedef std::underlying_type<OrcErrorCode>::type UT;
84 return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat);
87 DuplicateDefinition::DuplicateDefinition(std::string SymbolName)
88 : SymbolName(std::move(SymbolName)) {}
90 std::error_code DuplicateDefinition::convertToErrorCode() const {
91 return orcError(OrcErrorCode::DuplicateDefinition);
94 void DuplicateDefinition::log(raw_ostream &OS) const {
95 OS << "Duplicate definition of symbol '" << SymbolName << "'";
98 const std::string &DuplicateDefinition::getSymbolName() const {
99 return SymbolName;
102 JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)
103 : SymbolName(std::move(SymbolName)) {}
105 std::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);
111 void JITSymbolNotFound::log(raw_ostream &OS) const {
112 OS << "Could not find symbol '" << SymbolName << "'";
115 const std::string &JITSymbolNotFound::getSymbolName() const {
116 return SymbolName;
119 } // namespace orc
120 } // namespace llvm