• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <type_traits>
18 
19 using namespace llvm;
20 using namespace llvm::orc;
21 
22 namespace {
23 
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:
name() const29   const char *name() const noexcept override { return "orc"; }
30 
message(int condition) const31   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     }
65     llvm_unreachable("Unhandled error code");
66   }
67 };
68 
69 static ManagedStatic<OrcErrorCategory> OrcErrCat;
70 }
71 
72 namespace llvm {
73 namespace orc {
74 
75 char DuplicateDefinition::ID = 0;
76 char JITSymbolNotFound::ID = 0;
77 
orcError(OrcErrorCode ErrCode)78 std::error_code orcError(OrcErrorCode ErrCode) {
79   typedef std::underlying_type<OrcErrorCode>::type UT;
80   return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat);
81 }
82 
83 
DuplicateDefinition(std::string SymbolName)84 DuplicateDefinition::DuplicateDefinition(std::string SymbolName)
85   : SymbolName(std::move(SymbolName)) {}
86 
convertToErrorCode() const87 std::error_code DuplicateDefinition::convertToErrorCode() const {
88   return orcError(OrcErrorCode::DuplicateDefinition);
89 }
90 
log(raw_ostream & OS) const91 void DuplicateDefinition::log(raw_ostream &OS) const {
92   OS << "Duplicate definition of symbol '" << SymbolName << "'";
93 }
94 
getSymbolName() const95 const std::string &DuplicateDefinition::getSymbolName() const {
96   return SymbolName;
97 }
98 
JITSymbolNotFound(std::string SymbolName)99 JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)
100   : SymbolName(std::move(SymbolName)) {}
101 
convertToErrorCode() const102 std::error_code JITSymbolNotFound::convertToErrorCode() const {
103   typedef std::underlying_type<OrcErrorCode>::type UT;
104   return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound),
105                          *OrcErrCat);
106 }
107 
log(raw_ostream & OS) const108 void JITSymbolNotFound::log(raw_ostream &OS) const {
109   OS << "Could not find symbol '" << SymbolName << "'";
110 }
111 
getSymbolName() const112 const std::string &JITSymbolNotFound::getSymbolName() const {
113   return SymbolName;
114 }
115 
116 }
117 }
118