MSFError.cpp 2.2 KB

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