xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcError.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
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/Compiler.h"
17 #include "llvm/Support/Error.h"
18 #include "llvm/Support/raw_ostream.h"
19 #include <string>
20 #include <system_error>
21 
22 namespace llvm {
23 namespace orc {
24 
25 enum class OrcErrorCode : int {
26   // RPC Errors
27   UnknownORCError = 1,
28   DuplicateDefinition,
29   JITSymbolNotFound,
30   RemoteAllocatorDoesNotExist,
31   RemoteAllocatorIdAlreadyInUse,
32   RemoteMProtectAddrUnrecognized,
33   RemoteIndirectStubsOwnerDoesNotExist,
34   RemoteIndirectStubsOwnerIdAlreadyInUse,
35   RPCConnectionClosed,
36   RPCCouldNotNegotiateFunction,
37   RPCResponseAbandoned,
38   UnexpectedRPCCall,
39   UnexpectedRPCResponse,
40   UnknownErrorCodeFromRemote,
41   UnknownResourceHandle,
42   MissingSymbolDefinitions,
43   UnexpectedSymbolDefinitions,
44 };
45 
46 LLVM_ABI std::error_code orcError(OrcErrorCode ErrCode);
47 
48 class LLVM_ABI DuplicateDefinition : public ErrorInfo<DuplicateDefinition> {
49 public:
50   static char ID;
51 
52   DuplicateDefinition(std::string SymbolName,
53                       std::optional<std::string> Context = {});
54   std::error_code convertToErrorCode() const override;
55   void log(raw_ostream &OS) const override;
56   const std::string &getSymbolName() const;
57   const std::optional<std::string> &getContext() const;
58 
59 private:
60   std::string SymbolName;
61   std::optional<std::string> Context;
62 };
63 
64 class LLVM_ABI JITSymbolNotFound : public ErrorInfo<JITSymbolNotFound> {
65 public:
66   static char ID;
67 
68   JITSymbolNotFound(std::string SymbolName);
69   std::error_code convertToErrorCode() const override;
70   void log(raw_ostream &OS) const override;
71   const std::string &getSymbolName() const;
72 private:
73   std::string SymbolName;
74 };
75 
76 } // End namespace orc.
77 } // End namespace llvm.
78 
79 #endif // LLVM_EXECUTIONENGINE_ORC_SHARED_ORCERROR_H
80