1 //===--------------- OrcError.h - Orc Error Types ---------------*- C++ -*-===//
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 // Define an error category, error codes, and helper utilities for Orc.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_ORCERROR_H
14 #define LLVM_EXECUTIONENGINE_ORC_SHARED_ORCERROR_H
15 
16 #include "llvm/Support/Error.h"
17 #include "llvm/Support/raw_ostream.h"
18 #include <string>
19 #include <system_error>
20 
21 namespace llvm {
22 namespace orc {
23 
24 enum class OrcErrorCode : int {
25   // RPC Errors
26   UnknownORCError = 1,
27   DuplicateDefinition,
28   JITSymbolNotFound,
29   RemoteAllocatorDoesNotExist,
30   RemoteAllocatorIdAlreadyInUse,
31   RemoteMProtectAddrUnrecognized,
32   RemoteIndirectStubsOwnerDoesNotExist,
33   RemoteIndirectStubsOwnerIdAlreadyInUse,
34   RPCConnectionClosed,
35   RPCCouldNotNegotiateFunction,
36   RPCResponseAbandoned,
37   UnexpectedRPCCall,
38   UnexpectedRPCResponse,
39   UnknownErrorCodeFromRemote,
40   UnknownResourceHandle,
41   MissingSymbolDefinitions,
42   UnexpectedSymbolDefinitions,
43 };
44 
45 std::error_code orcError(OrcErrorCode ErrCode);
46 
47 class DuplicateDefinition : public ErrorInfo<DuplicateDefinition> {
48 public:
49   static char ID;
50 
51   DuplicateDefinition(std::string SymbolName);
52   std::error_code convertToErrorCode() const override;
53   void log(raw_ostream &OS) const override;
54   const std::string &getSymbolName() const;
55 private:
56   std::string SymbolName;
57 };
58 
59 class JITSymbolNotFound : public ErrorInfo<JITSymbolNotFound> {
60 public:
61   static char ID;
62 
63   JITSymbolNotFound(std::string SymbolName);
64   std::error_code convertToErrorCode() const override;
65   void log(raw_ostream &OS) const override;
66   const std::string &getSymbolName() const;
67 private:
68   std::string SymbolName;
69 };
70 
71 } // End namespace orc.
72 } // End namespace llvm.
73 
74 #endif // LLVM_EXECUTIONENGINE_ORC_SHARED_ORCERROR_H
75