]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcError.cpp
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / ExecutionEngine / Orc / OrcError.cpp
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
13 #include "llvm/ExecutionEngine/Orc/OrcError.h"
14 #include "llvm/Support/ErrorHandling.h"
15 #include "llvm/Support/ManagedStatic.h"
16
17 using namespace llvm;
18 using namespace llvm::orc;
19
20 namespace {
21
22 // FIXME: This class is only here to support the transition to llvm::Error. It
23 // will be removed once this transition is complete. Clients should prefer to
24 // deal with the Error value directly, rather than converting to error_code.
25 class OrcErrorCategory : public std::error_category {
26 public:
27   const char *name() const noexcept override { return "orc"; }
28
29   std::string message(int condition) const override {
30     switch (static_cast<OrcErrorCode>(condition)) {
31     case OrcErrorCode::UnknownORCError:
32       return "Unknown ORC error";
33     case OrcErrorCode::DuplicateDefinition:
34       return "Duplicate symbol definition";
35     case OrcErrorCode::JITSymbolNotFound:
36       return "JIT symbol not found";
37     case OrcErrorCode::RemoteAllocatorDoesNotExist:
38       return "Remote allocator does not exist";
39     case OrcErrorCode::RemoteAllocatorIdAlreadyInUse:
40       return "Remote allocator Id already in use";
41     case OrcErrorCode::RemoteMProtectAddrUnrecognized:
42       return "Remote mprotect call references unallocated memory";
43     case OrcErrorCode::RemoteIndirectStubsOwnerDoesNotExist:
44       return "Remote indirect stubs owner does not exist";
45     case OrcErrorCode::RemoteIndirectStubsOwnerIdAlreadyInUse:
46       return "Remote indirect stubs owner Id already in use";
47     case OrcErrorCode::RPCConnectionClosed:
48       return "RPC connection closed";
49     case OrcErrorCode::RPCCouldNotNegotiateFunction:
50       return "Could not negotiate RPC function";
51     case OrcErrorCode::RPCResponseAbandoned:
52       return "RPC response abandoned";
53     case OrcErrorCode::UnexpectedRPCCall:
54       return "Unexpected RPC call";
55     case OrcErrorCode::UnexpectedRPCResponse:
56       return "Unexpected RPC response";
57     case OrcErrorCode::UnknownErrorCodeFromRemote:
58       return "Unknown error returned from remote RPC function "
59              "(Use StringError to get error message)";
60     case OrcErrorCode::UnknownResourceHandle:
61       return "Unknown resource handle";
62     }
63     llvm_unreachable("Unhandled error code");
64   }
65 };
66
67 static ManagedStatic<OrcErrorCategory> OrcErrCat;
68 }
69
70 namespace llvm {
71 namespace orc {
72
73 char DuplicateDefinition::ID = 0;
74 char JITSymbolNotFound::ID = 0;
75
76 std::error_code orcError(OrcErrorCode ErrCode) {
77   typedef std::underlying_type<OrcErrorCode>::type UT;
78   return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat);
79 }
80
81
82 DuplicateDefinition::DuplicateDefinition(std::string SymbolName)
83   : SymbolName(std::move(SymbolName)) {}
84
85 std::error_code DuplicateDefinition::convertToErrorCode() const {
86   return orcError(OrcErrorCode::DuplicateDefinition);
87 }
88
89 void DuplicateDefinition::log(raw_ostream &OS) const {
90   OS << "Duplicate definition of symbol '" << SymbolName << "'";
91 }
92
93 const std::string &DuplicateDefinition::getSymbolName() const {
94   return SymbolName;
95 }
96
97 JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)
98   : SymbolName(std::move(SymbolName)) {}
99
100 std::error_code JITSymbolNotFound::convertToErrorCode() const {
101   typedef std::underlying_type<OrcErrorCode>::type UT;
102   return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound),
103                          *OrcErrCat);
104 }
105
106 void JITSymbolNotFound::log(raw_ostream &OS) const {
107   OS << "Could not find symbol '" << SymbolName << "'";
108 }
109
110 const std::string &JITSymbolNotFound::getSymbolName() const {
111   return SymbolName;
112 }
113
114 }
115 }