Path: blob/main/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Shared/OrcError.cpp
39606 views
//===---------------- OrcError.cpp - Error codes for ORC ------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Error codes for ORC.9//10//===----------------------------------------------------------------------===//1112#include "llvm/ExecutionEngine/Orc/Shared/OrcError.h"13#include "llvm/Support/ErrorHandling.h"1415#include <type_traits>1617using namespace llvm;18using namespace llvm::orc;1920namespace {2122// FIXME: This class is only here to support the transition to llvm::Error. It23// will be removed once this transition is complete. Clients should prefer to24// deal with the Error value directly, rather than converting to error_code.25class OrcErrorCategory : public std::error_category {26public:27const char *name() const noexcept override { return "orc"; }2829std::string message(int condition) const override {30switch (static_cast<OrcErrorCode>(condition)) {31case OrcErrorCode::UnknownORCError:32return "Unknown ORC error";33case OrcErrorCode::DuplicateDefinition:34return "Duplicate symbol definition";35case OrcErrorCode::JITSymbolNotFound:36return "JIT symbol not found";37case OrcErrorCode::RemoteAllocatorDoesNotExist:38return "Remote allocator does not exist";39case OrcErrorCode::RemoteAllocatorIdAlreadyInUse:40return "Remote allocator Id already in use";41case OrcErrorCode::RemoteMProtectAddrUnrecognized:42return "Remote mprotect call references unallocated memory";43case OrcErrorCode::RemoteIndirectStubsOwnerDoesNotExist:44return "Remote indirect stubs owner does not exist";45case OrcErrorCode::RemoteIndirectStubsOwnerIdAlreadyInUse:46return "Remote indirect stubs owner Id already in use";47case OrcErrorCode::RPCConnectionClosed:48return "RPC connection closed";49case OrcErrorCode::RPCCouldNotNegotiateFunction:50return "Could not negotiate RPC function";51case OrcErrorCode::RPCResponseAbandoned:52return "RPC response abandoned";53case OrcErrorCode::UnexpectedRPCCall:54return "Unexpected RPC call";55case OrcErrorCode::UnexpectedRPCResponse:56return "Unexpected RPC response";57case OrcErrorCode::UnknownErrorCodeFromRemote:58return "Unknown error returned from remote RPC function "59"(Use StringError to get error message)";60case OrcErrorCode::UnknownResourceHandle:61return "Unknown resource handle";62case OrcErrorCode::MissingSymbolDefinitions:63return "MissingSymbolsDefinitions";64case OrcErrorCode::UnexpectedSymbolDefinitions:65return "UnexpectedSymbolDefinitions";66}67llvm_unreachable("Unhandled error code");68}69};7071OrcErrorCategory &getOrcErrCat() {72static OrcErrorCategory OrcErrCat;73return OrcErrCat;74}75} // namespace7677namespace llvm {78namespace orc {7980char DuplicateDefinition::ID = 0;81char JITSymbolNotFound::ID = 0;8283std::error_code orcError(OrcErrorCode ErrCode) {84typedef std::underlying_type_t<OrcErrorCode> UT;85return std::error_code(static_cast<UT>(ErrCode), getOrcErrCat());86}8788DuplicateDefinition::DuplicateDefinition(std::string SymbolName)89: SymbolName(std::move(SymbolName)) {}9091std::error_code DuplicateDefinition::convertToErrorCode() const {92return orcError(OrcErrorCode::DuplicateDefinition);93}9495void DuplicateDefinition::log(raw_ostream &OS) const {96OS << "Duplicate definition of symbol '" << SymbolName << "'";97}9899const std::string &DuplicateDefinition::getSymbolName() const {100return SymbolName;101}102103JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)104: SymbolName(std::move(SymbolName)) {}105106std::error_code JITSymbolNotFound::convertToErrorCode() const {107typedef std::underlying_type_t<OrcErrorCode> UT;108return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound),109getOrcErrCat());110}111112void JITSymbolNotFound::log(raw_ostream &OS) const {113OS << "Could not find symbol '" << SymbolName << "'";114}115116const std::string &JITSymbolNotFound::getSymbolName() const {117return SymbolName;118}119120} // namespace orc121} // namespace llvm122123124