Error.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===- Error.cpp - system_error extensions for Object -----------*- 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 Object library.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/Object/Error.h"
  14. #include "llvm/Support/ErrorHandling.h"
  15. #include "llvm/Support/ManagedStatic.h"
  16. using namespace llvm;
  17. using namespace object;
  18. namespace {
  19. class _object_error_category : public std::error_category {
  20. public:
  21. const char* name() const LLVM_NOEXCEPT override;
  22. std::string message(int ev) const override;
  23. };
  24. }
  25. const char *_object_error_category::name() const LLVM_NOEXCEPT {
  26. return "llvm.object";
  27. }
  28. std::string _object_error_category::message(int EV) const {
  29. object_error E = static_cast<object_error>(EV);
  30. switch (E) {
  31. case object_error::arch_not_found:
  32. return "No object file for requested architecture";
  33. case object_error::invalid_file_type:
  34. return "The file was not recognized as a valid object file";
  35. case object_error::parse_failed:
  36. return "Invalid data was encountered while parsing the file";
  37. case object_error::unexpected_eof:
  38. return "The end of the file was unexpectedly encountered";
  39. case object_error::string_table_non_null_end:
  40. return "String table must end with a null terminator";
  41. case object_error::invalid_section_index:
  42. return "Invalid section index";
  43. case object_error::bitcode_section_not_found:
  44. return "Bitcode section not found in object file";
  45. case object_error::macho_small_load_command:
  46. return "Mach-O load command with size < 8 bytes";
  47. case object_error::macho_load_segment_too_many_sections:
  48. return "Mach-O segment load command contains too many sections";
  49. case object_error::macho_load_segment_too_small:
  50. return "Mach-O segment load command size is too small";
  51. }
  52. llvm_unreachable("An enumerator of object_error does not have a message "
  53. "defined.");
  54. }
  55. static ManagedStatic<_object_error_category> error_category;
  56. const std::error_category &object::object_category() {
  57. return *error_category;
  58. }