OrcError.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <type_traits>
  15. using namespace llvm;
  16. using namespace llvm::orc;
  17. namespace {
  18. // FIXME: This class is only here to support the transition to llvm::Error. It
  19. // will be removed once this transition is complete. Clients should prefer to
  20. // deal with the Error value directly, rather than converting to error_code.
  21. class OrcErrorCategory : public std::error_category {
  22. public:
  23. const char *name() const noexcept override { return "orc"; }
  24. std::string message(int condition) const override {
  25. switch (static_cast<OrcErrorCode>(condition)) {
  26. case OrcErrorCode::UnknownORCError:
  27. return "Unknown ORC error";
  28. case OrcErrorCode::DuplicateDefinition:
  29. return "Duplicate symbol definition";
  30. case OrcErrorCode::JITSymbolNotFound:
  31. return "JIT symbol not found";
  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";
  42. case OrcErrorCode::RPCConnectionClosed:
  43. return "RPC connection closed";
  44. case OrcErrorCode::RPCCouldNotNegotiateFunction:
  45. return "Could not negotiate RPC function";
  46. case OrcErrorCode::RPCResponseAbandoned:
  47. return "RPC response abandoned";
  48. case OrcErrorCode::UnexpectedRPCCall:
  49. return "Unexpected RPC call";
  50. case OrcErrorCode::UnexpectedRPCResponse:
  51. return "Unexpected RPC response";
  52. case OrcErrorCode::UnknownErrorCodeFromRemote:
  53. return "Unknown error returned from remote RPC function "
  54. "(Use StringError to get error message)";
  55. case OrcErrorCode::UnknownResourceHandle:
  56. return "Unknown resource handle";
  57. case OrcErrorCode::MissingSymbolDefinitions:
  58. return "MissingSymbolsDefinitions";
  59. case OrcErrorCode::UnexpectedSymbolDefinitions:
  60. return "UnexpectedSymbolDefinitions";
  61. }
  62. llvm_unreachable("Unhandled error code");
  63. }
  64. };
  65. OrcErrorCategory &getOrcErrCat() {
  66. static OrcErrorCategory OrcErrCat;
  67. return OrcErrCat;
  68. }
  69. } // namespace
  70. namespace llvm {
  71. namespace orc {
  72. char DuplicateDefinition::ID = 0;
  73. char JITSymbolNotFound::ID = 0;
  74. std::error_code orcError(OrcErrorCode ErrCode) {
  75. typedef std::underlying_type_t<OrcErrorCode> UT;
  76. return std::error_code(static_cast<UT>(ErrCode), getOrcErrCat());
  77. }
  78. DuplicateDefinition::DuplicateDefinition(std::string SymbolName)
  79. : SymbolName(std::move(SymbolName)) {}
  80. std::error_code DuplicateDefinition::convertToErrorCode() const {
  81. return orcError(OrcErrorCode::DuplicateDefinition);
  82. }
  83. void DuplicateDefinition::log(raw_ostream &OS) const {
  84. OS << "Duplicate definition of symbol '" << SymbolName << "'";
  85. }
  86. const std::string &DuplicateDefinition::getSymbolName() const {
  87. return SymbolName;
  88. }
  89. JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)
  90. : SymbolName(std::move(SymbolName)) {}
  91. std::error_code JITSymbolNotFound::convertToErrorCode() const {
  92. typedef std::underlying_type_t<OrcErrorCode> UT;
  93. return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound),
  94. getOrcErrCat());
  95. }
  96. void JITSymbolNotFound::log(raw_ostream &OS) const {
  97. OS << "Could not find symbol '" << SymbolName << "'";
  98. }
  99. const std::string &JITSymbolNotFound::getSymbolName() const {
  100. return SymbolName;
  101. }
  102. } // namespace orc
  103. } // namespace llvm