blob: dcbbf5f2ae7000f64bc2a39c0cb865036ae654d6 [file] [log] [blame]
Lang Hames4026f902016-01-11 00:34:13 +00001//===---------------- OrcError.cpp - Error codes for ORC ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Error codes for ORC.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/ExecutionEngine/Orc/OrcError.h"
15#include "llvm/Support/ErrorHandling.h"
16#include "llvm/Support/ManagedStatic.h"
17
18using namespace llvm;
19using namespace llvm::orc;
20
21namespace {
22
Peter Collingbourne4718f8b2016-05-24 20:13:46 +000023// FIXME: This class is only here to support the transition to llvm::Error. It
24// will be removed once this transition is complete. Clients should prefer to
25// deal with the Error value directly, rather than converting to error_code.
Lang Hames4026f902016-01-11 00:34:13 +000026class OrcErrorCategory : public std::error_category {
27public:
Reid Kleckner990504e2016-10-19 23:52:38 +000028 const char *name() const noexcept override { return "orc"; }
Lang Hames4026f902016-01-11 00:34:13 +000029
30 std::string message(int condition) const override {
31 switch (static_cast<OrcErrorCode>(condition)) {
32 case OrcErrorCode::RemoteAllocatorDoesNotExist:
33 return "Remote allocator does not exist";
34 case OrcErrorCode::RemoteAllocatorIdAlreadyInUse:
35 return "Remote allocator Id already in use";
36 case OrcErrorCode::RemoteMProtectAddrUnrecognized:
37 return "Remote mprotect call references unallocated memory";
38 case OrcErrorCode::RemoteIndirectStubsOwnerDoesNotExist:
39 return "Remote indirect stubs owner does not exist";
40 case OrcErrorCode::RemoteIndirectStubsOwnerIdAlreadyInUse:
41 return "Remote indirect stubs owner Id already in use";
Lang Hamesc9d0ff12016-12-25 21:55:05 +000042 case OrcErrorCode::RPCResponseAbandoned:
43 return "RPC response abandoned";
Lang Hames4026f902016-01-11 00:34:13 +000044 case OrcErrorCode::UnexpectedRPCCall:
45 return "Unexpected RPC call";
Lang Hames3fde6522016-04-18 19:55:43 +000046 case OrcErrorCode::UnexpectedRPCResponse:
47 return "Unexpected RPC response";
Lang Hames1f2bf2d2016-11-11 21:42:09 +000048 case OrcErrorCode::UnknownRPCFunction:
49 return "Unknown RPC function";
Lang Hames4026f902016-01-11 00:34:13 +000050 }
51 llvm_unreachable("Unhandled error code");
52 }
53};
54
55static ManagedStatic<OrcErrorCategory> OrcErrCat;
56}
57
58namespace llvm {
59namespace orc {
60
Lang Hames021cb2b2017-01-15 06:34:25 +000061char RPCFunctionNotSupported::ID = 0;
62
Lang Hamesa1d0f712017-04-06 01:35:13 +000063std::error_code orcError(OrcErrorCode ErrCode) {
Lang Hames4026f902016-01-11 00:34:13 +000064 typedef std::underlying_type<OrcErrorCode>::type UT;
Lang Hamesa1d0f712017-04-06 01:35:13 +000065 return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat);
Lang Hames4026f902016-01-11 00:34:13 +000066}
Lang Hames021cb2b2017-01-15 06:34:25 +000067
68RPCFunctionNotSupported::RPCFunctionNotSupported(std::string RPCFunctionSignature)
69 : RPCFunctionSignature(std::move(RPCFunctionSignature)) {}
70
71std::error_code RPCFunctionNotSupported::convertToErrorCode() const {
Lang Hamesa1d0f712017-04-06 01:35:13 +000072 return orcError(OrcErrorCode::UnknownRPCFunction);
Lang Hames021cb2b2017-01-15 06:34:25 +000073}
74
75void RPCFunctionNotSupported::log(raw_ostream &OS) const {
76 OS << "Could not negotiate RPC function '" << RPCFunctionSignature << "'";
77}
78
79const std::string &RPCFunctionNotSupported::getFunctionSignature() const {
80 return RPCFunctionSignature;
81}
82
Lang Hames4026f902016-01-11 00:34:13 +000083}
84}