OrcError.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //===---------------- OrcError.cpp - Error codes for ORC ------------------===//
  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. // Error codes for ORC.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/ExecutionEngine/Orc/Shared/OrcError.h"
  13. #include "llvm/Support/ErrorHandling.h"
  14. #include "llvm/Support/ManagedStatic.h"
  15. #include <type_traits>
  16. using namespace llvm;
  17. using namespace llvm::orc;
  18. namespace {
  19. // FIXME: This class is only here to support the transition to llvm::Error. It
  20. // will be removed once this transition is complete. Clients should prefer to
  21. // deal with the Error value directly, rather than converting to error_code.
  22. class OrcErrorCategory : public std::error_category {
  23. public:
  24. const char *name() const noexcept override { return "orc"; }
  25. std::string message(int condition) const override {
  26. switch (static_cast<OrcErrorCode>(condition)) {
  27. case OrcErrorCode::UnknownORCError:
  28. return "Unknown ORC error";
  29. case OrcErrorCode::DuplicateDefinition:
  30. return "Duplicate symbol definition";
  31. case OrcErrorCode::JITSymbolNotFound:
  32. return "JIT symbol not found";
  33. case OrcErrorCode::RemoteAllocatorDoesNotExist:
  34. return "Remote allocator does not exist";
  35. case OrcErrorCode::RemoteAllocatorIdAlreadyInUse:
  36. return "Remote allocator Id already in use";
  37. case OrcErrorCode::RemoteMProtectAddrUnrecognized:
  38. return "Remote mprotect call references unallocated memory";
  39. case OrcErrorCode::RemoteIndirectStubsOwnerDoesNotExist:
  40. return "Remote indirect stubs owner does not exist";
  41. case OrcErrorCode::RemoteIndirectStubsOwnerIdAlreadyInUse:
  42. return "Remote indirect stubs owner Id already in use";
  43. case OrcErrorCode::RPCConnectionClosed:
  44. return "RPC connection closed";
  45. case OrcErrorCode::RPCCouldNotNegotiateFunction:
  46. return "Could not negotiate RPC function";
  47. case OrcErrorCode::RPCResponseAbandoned:
  48. return "RPC response abandoned";
  49. case OrcErrorCode::UnexpectedRPCCall:
  50. return "Unexpected RPC call";
  51. case OrcErrorCode::UnexpectedRPCResponse:
  52. return "Unexpected RPC response";
  53. case OrcErrorCode::UnknownErrorCodeFromRemote:
  54. return "Unknown error returned from remote RPC function "
  55. "(Use StringError to get error message)";
  56. case OrcErrorCode::UnknownResourceHandle:
  57. return "Unknown resource handle";
  58. case OrcErrorCode::MissingSymbolDefinitions:
  59. return "MissingSymbolsDefinitions";
  60. case OrcErrorCode::UnexpectedSymbolDefinitions:
  61. return "UnexpectedSymbolDefinitions";
  62. }
  63. llvm_unreachable("Unhandled error code");
  64. }
  65. };
  66. static ManagedStatic<OrcErrorCategory> OrcErrCat;
  67. } // namespace
  68. namespace llvm {
  69. namespace orc {
  70. char DuplicateDefinition::ID = 0;
  71. char JITSymbolNotFound::ID = 0;
  72. std::error_code orcError(OrcErrorCode ErrCode) {
  73. typedef std::underlying_type<OrcErrorCode>::type UT;
  74. return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat);
  75. }
  76. DuplicateDefinition::DuplicateDefinition(std::string SymbolName)
  77. : SymbolName(std::move(SymbolName)) {}
  78. std::error_code DuplicateDefinition::convertToErrorCode() const {
  79. return orcError(OrcErrorCode::DuplicateDefinition);
  80. }
  81. void DuplicateDefinition::log(raw_ostream &OS) const {
  82. OS << "Duplicate definition of symbol '" << SymbolName << "'";
  83. }
  84. const std::string &DuplicateDefinition::getSymbolName() const {
  85. return SymbolName;
  86. }
  87. JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)
  88. : SymbolName(std::move(SymbolName)) {}
  89. std::error_code JITSymbolNotFound::convertToErrorCode() const {
  90. typedef std::underlying_type<OrcErrorCode>::type UT;
  91. return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound),
  92. *OrcErrCat);
  93. }
  94. void JITSymbolNotFound::log(raw_ostream &OS) const {
  95. OS << "Could not find symbol '" << SymbolName << "'";
  96. }
  97. const std::string &JITSymbolNotFound::getSymbolName() const {
  98. return SymbolName;
  99. }
  100. } // namespace orc
  101. } // namespace llvm