MSFError.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //===- MSFError.cpp - Error extensions for MSF files ------------*- 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. #include "llvm/DebugInfo/MSF/MSFError.h"
  9. #include "llvm/Support/ErrorHandling.h"
  10. #include <string>
  11. using namespace llvm;
  12. using namespace llvm::msf;
  13. namespace {
  14. // FIXME: This class is only here to support the transition to llvm::Error. It
  15. // will be removed once this transition is complete. Clients should prefer to
  16. // deal with the Error value directly, rather than converting to error_code.
  17. class MSFErrorCategory : public std::error_category {
  18. public:
  19. const char *name() const noexcept override { return "llvm.msf"; }
  20. std::string message(int Condition) const override {
  21. switch (static_cast<msf_error_code>(Condition)) {
  22. case msf_error_code::unspecified:
  23. return "An unknown error has occurred.";
  24. case msf_error_code::insufficient_buffer:
  25. return "The buffer is not large enough to read the requested number of "
  26. "bytes.";
  27. case msf_error_code::size_overflow_4096:
  28. return "Output data is larger than 4 GiB.";
  29. case msf_error_code::size_overflow_8192:
  30. return "Output data is larger than 8 GiB.";
  31. case msf_error_code::size_overflow_16384:
  32. return "Output data is larger than 16 GiB.";
  33. case msf_error_code::size_overflow_32768:
  34. return "Output data is larger than 32 GiB.";
  35. case msf_error_code::not_writable:
  36. return "The specified stream is not writable.";
  37. case msf_error_code::no_stream:
  38. return "The specified stream does not exist.";
  39. case msf_error_code::invalid_format:
  40. return "The data is in an unexpected format.";
  41. case msf_error_code::block_in_use:
  42. return "The block is already in use.";
  43. }
  44. llvm_unreachable("Unrecognized msf_error_code");
  45. }
  46. };
  47. } // namespace
  48. const std::error_category &llvm::msf::MSFErrCategory() {
  49. static MSFErrorCategory MSFCategory;
  50. return MSFCategory;
  51. }
  52. char MSFError::ID;