Error.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //===- Error.cpp - system_error extensions for llvm-readobj -----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This defines a new error_category for the llvm-readobj tool.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "Error.h"
  14. #include "llvm/Support/ErrorHandling.h"
  15. using namespace llvm;
  16. namespace {
  17. class _readobj_error_category : public std::error_category {
  18. public:
  19. const char* name() const LLVM_NOEXCEPT override;
  20. std::string message(int ev) const override;
  21. };
  22. } // namespace
  23. const char *_readobj_error_category::name() const LLVM_NOEXCEPT {
  24. return "llvm.readobj";
  25. }
  26. std::string _readobj_error_category::message(int EV) const {
  27. switch (static_cast<readobj_error>(EV)) {
  28. case readobj_error::success: return "Success";
  29. case readobj_error::file_not_found:
  30. return "No such file.";
  31. case readobj_error::unsupported_file_format:
  32. return "The file was not recognized as a valid object file.";
  33. case readobj_error::unrecognized_file_format:
  34. return "Unrecognized file type.";
  35. case readobj_error::unsupported_obj_file_format:
  36. return "Unsupported object file format.";
  37. case readobj_error::unknown_symbol:
  38. return "Unknown symbol.";
  39. }
  40. llvm_unreachable("An enumerator of readobj_error does not have a message "
  41. "defined.");
  42. }
  43. namespace llvm {
  44. const std::error_category &readobj_category() {
  45. static _readobj_error_category o;
  46. return o;
  47. }
  48. } // namespace llvm