1e8d8bef9SDimitry Andric //===---------------- OrcError.cpp - Error codes for ORC ------------------===// 2e8d8bef9SDimitry Andric // 3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e8d8bef9SDimitry Andric // 7e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===// 8e8d8bef9SDimitry Andric // 9e8d8bef9SDimitry Andric // Error codes for ORC. 10e8d8bef9SDimitry Andric // 11e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===// 12e8d8bef9SDimitry Andric 13e8d8bef9SDimitry Andric #include "llvm/ExecutionEngine/Orc/Shared/OrcError.h" 14e8d8bef9SDimitry Andric #include "llvm/Support/ErrorHandling.h" 15e8d8bef9SDimitry Andric 16e8d8bef9SDimitry Andric #include <type_traits> 17e8d8bef9SDimitry Andric 18e8d8bef9SDimitry Andric using namespace llvm; 19e8d8bef9SDimitry Andric using namespace llvm::orc; 20e8d8bef9SDimitry Andric 21e8d8bef9SDimitry Andric namespace { 22e8d8bef9SDimitry Andric 23e8d8bef9SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It 24e8d8bef9SDimitry Andric // will be removed once this transition is complete. Clients should prefer to 25e8d8bef9SDimitry Andric // deal with the Error value directly, rather than converting to error_code. 26e8d8bef9SDimitry Andric class OrcErrorCategory : public std::error_category { 27e8d8bef9SDimitry Andric public: name() const28e8d8bef9SDimitry Andric const char *name() const noexcept override { return "orc"; } 29e8d8bef9SDimitry Andric message(int condition) const30e8d8bef9SDimitry Andric std::string message(int condition) const override { 31e8d8bef9SDimitry Andric switch (static_cast<OrcErrorCode>(condition)) { 32e8d8bef9SDimitry Andric case OrcErrorCode::UnknownORCError: 33e8d8bef9SDimitry Andric return "Unknown ORC error"; 34e8d8bef9SDimitry Andric case OrcErrorCode::DuplicateDefinition: 35e8d8bef9SDimitry Andric return "Duplicate symbol definition"; 36e8d8bef9SDimitry Andric case OrcErrorCode::JITSymbolNotFound: 37e8d8bef9SDimitry Andric return "JIT symbol not found"; 38e8d8bef9SDimitry Andric case OrcErrorCode::RemoteAllocatorDoesNotExist: 39e8d8bef9SDimitry Andric return "Remote allocator does not exist"; 40e8d8bef9SDimitry Andric case OrcErrorCode::RemoteAllocatorIdAlreadyInUse: 41e8d8bef9SDimitry Andric return "Remote allocator Id already in use"; 42e8d8bef9SDimitry Andric case OrcErrorCode::RemoteMProtectAddrUnrecognized: 43e8d8bef9SDimitry Andric return "Remote mprotect call references unallocated memory"; 44e8d8bef9SDimitry Andric case OrcErrorCode::RemoteIndirectStubsOwnerDoesNotExist: 45e8d8bef9SDimitry Andric return "Remote indirect stubs owner does not exist"; 46e8d8bef9SDimitry Andric case OrcErrorCode::RemoteIndirectStubsOwnerIdAlreadyInUse: 47e8d8bef9SDimitry Andric return "Remote indirect stubs owner Id already in use"; 48e8d8bef9SDimitry Andric case OrcErrorCode::RPCConnectionClosed: 49e8d8bef9SDimitry Andric return "RPC connection closed"; 50e8d8bef9SDimitry Andric case OrcErrorCode::RPCCouldNotNegotiateFunction: 51e8d8bef9SDimitry Andric return "Could not negotiate RPC function"; 52e8d8bef9SDimitry Andric case OrcErrorCode::RPCResponseAbandoned: 53e8d8bef9SDimitry Andric return "RPC response abandoned"; 54e8d8bef9SDimitry Andric case OrcErrorCode::UnexpectedRPCCall: 55e8d8bef9SDimitry Andric return "Unexpected RPC call"; 56e8d8bef9SDimitry Andric case OrcErrorCode::UnexpectedRPCResponse: 57e8d8bef9SDimitry Andric return "Unexpected RPC response"; 58e8d8bef9SDimitry Andric case OrcErrorCode::UnknownErrorCodeFromRemote: 59e8d8bef9SDimitry Andric return "Unknown error returned from remote RPC function " 60e8d8bef9SDimitry Andric "(Use StringError to get error message)"; 61e8d8bef9SDimitry Andric case OrcErrorCode::UnknownResourceHandle: 62e8d8bef9SDimitry Andric return "Unknown resource handle"; 63e8d8bef9SDimitry Andric case OrcErrorCode::MissingSymbolDefinitions: 64e8d8bef9SDimitry Andric return "MissingSymbolsDefinitions"; 65e8d8bef9SDimitry Andric case OrcErrorCode::UnexpectedSymbolDefinitions: 66e8d8bef9SDimitry Andric return "UnexpectedSymbolDefinitions"; 67e8d8bef9SDimitry Andric } 68e8d8bef9SDimitry Andric llvm_unreachable("Unhandled error code"); 69e8d8bef9SDimitry Andric } 70e8d8bef9SDimitry Andric }; 71e8d8bef9SDimitry Andric getOrcErrCat()72753f127fSDimitry AndricOrcErrorCategory &getOrcErrCat() { 73753f127fSDimitry Andric static OrcErrorCategory OrcErrCat; 74753f127fSDimitry Andric return OrcErrCat; 75753f127fSDimitry Andric } 76e8d8bef9SDimitry Andric } // namespace 77e8d8bef9SDimitry Andric 78e8d8bef9SDimitry Andric namespace llvm { 79e8d8bef9SDimitry Andric namespace orc { 80e8d8bef9SDimitry Andric 81e8d8bef9SDimitry Andric char DuplicateDefinition::ID = 0; 82e8d8bef9SDimitry Andric char JITSymbolNotFound::ID = 0; 83e8d8bef9SDimitry Andric orcError(OrcErrorCode ErrCode)84e8d8bef9SDimitry Andricstd::error_code orcError(OrcErrorCode ErrCode) { 85*bdd1243dSDimitry Andric typedef std::underlying_type_t<OrcErrorCode> UT; 86753f127fSDimitry Andric return std::error_code(static_cast<UT>(ErrCode), getOrcErrCat()); 87e8d8bef9SDimitry Andric } 88e8d8bef9SDimitry Andric DuplicateDefinition(std::string SymbolName)89e8d8bef9SDimitry AndricDuplicateDefinition::DuplicateDefinition(std::string SymbolName) 90e8d8bef9SDimitry Andric : SymbolName(std::move(SymbolName)) {} 91e8d8bef9SDimitry Andric convertToErrorCode() const92e8d8bef9SDimitry Andricstd::error_code DuplicateDefinition::convertToErrorCode() const { 93e8d8bef9SDimitry Andric return orcError(OrcErrorCode::DuplicateDefinition); 94e8d8bef9SDimitry Andric } 95e8d8bef9SDimitry Andric log(raw_ostream & OS) const96e8d8bef9SDimitry Andricvoid DuplicateDefinition::log(raw_ostream &OS) const { 97e8d8bef9SDimitry Andric OS << "Duplicate definition of symbol '" << SymbolName << "'"; 98e8d8bef9SDimitry Andric } 99e8d8bef9SDimitry Andric getSymbolName() const100e8d8bef9SDimitry Andricconst std::string &DuplicateDefinition::getSymbolName() const { 101e8d8bef9SDimitry Andric return SymbolName; 102e8d8bef9SDimitry Andric } 103e8d8bef9SDimitry Andric JITSymbolNotFound(std::string SymbolName)104e8d8bef9SDimitry AndricJITSymbolNotFound::JITSymbolNotFound(std::string SymbolName) 105e8d8bef9SDimitry Andric : SymbolName(std::move(SymbolName)) {} 106e8d8bef9SDimitry Andric convertToErrorCode() const107e8d8bef9SDimitry Andricstd::error_code JITSymbolNotFound::convertToErrorCode() const { 108*bdd1243dSDimitry Andric typedef std::underlying_type_t<OrcErrorCode> UT; 109e8d8bef9SDimitry Andric return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound), 110753f127fSDimitry Andric getOrcErrCat()); 111e8d8bef9SDimitry Andric } 112e8d8bef9SDimitry Andric log(raw_ostream & OS) const113e8d8bef9SDimitry Andricvoid JITSymbolNotFound::log(raw_ostream &OS) const { 114e8d8bef9SDimitry Andric OS << "Could not find symbol '" << SymbolName << "'"; 115e8d8bef9SDimitry Andric } 116e8d8bef9SDimitry Andric getSymbolName() const117e8d8bef9SDimitry Andricconst std::string &JITSymbolNotFound::getSymbolName() const { 118e8d8bef9SDimitry Andric return SymbolName; 119e8d8bef9SDimitry Andric } 120e8d8bef9SDimitry Andric 121e8d8bef9SDimitry Andric } // namespace orc 122e8d8bef9SDimitry Andric } // namespace llvm 123