1224133Sdim//===- Error.cpp - system_error extensions for Object -----------*- C++ -*-===//
2224133Sdim//
3224133Sdim//                     The LLVM Compiler Infrastructure
4224133Sdim//
5224133Sdim// This file is distributed under the University of Illinois Open Source
6224133Sdim// License. See LICENSE.TXT for details.
7224133Sdim//
8224133Sdim//===----------------------------------------------------------------------===//
9224133Sdim//
10224133Sdim// This defines a new error_category for the Object library.
11224133Sdim//
12224133Sdim//===----------------------------------------------------------------------===//
13224133Sdim
14224133Sdim#include "llvm/Object/Error.h"
15224133Sdim#include "llvm/Support/ErrorHandling.h"
16280031Sdim#include "llvm/Support/ManagedStatic.h"
17224133Sdim
18224133Sdimusing namespace llvm;
19224133Sdimusing namespace object;
20224133Sdim
21224133Sdimnamespace {
22276479Sdimclass _object_error_category : public std::error_category {
23224133Sdimpublic:
24276479Sdim  const char* name() const LLVM_NOEXCEPT override;
25276479Sdim  std::string message(int ev) const override;
26224133Sdim};
27224133Sdim}
28224133Sdim
29280031Sdimconst char *_object_error_category::name() const LLVM_NOEXCEPT {
30224133Sdim  return "llvm.object";
31224133Sdim}
32224133Sdim
33276479Sdimstd::string _object_error_category::message(int EV) const {
34276479Sdim  object_error E = static_cast<object_error>(EV);
35261991Sdim  switch (E) {
36261991Sdim  case object_error::arch_not_found:
37261991Sdim    return "No object file for requested architecture";
38224133Sdim  case object_error::invalid_file_type:
39224133Sdim    return "The file was not recognized as a valid object file";
40224133Sdim  case object_error::parse_failed:
41224133Sdim    return "Invalid data was encountered while parsing the file";
42224133Sdim  case object_error::unexpected_eof:
43224133Sdim    return "The end of the file was unexpectedly encountered";
44288943Sdim  case object_error::string_table_non_null_end:
45288943Sdim    return "String table must end with a null terminator";
46288943Sdim  case object_error::invalid_section_index:
47288943Sdim    return "Invalid section index";
48280031Sdim  case object_error::bitcode_section_not_found:
49280031Sdim    return "Bitcode section not found in object file";
50296417Sdim  case object_error::elf_invalid_dynamic_table_size:
51296417Sdim    return "Invalid dynamic table size";
52288943Sdim  case object_error::macho_small_load_command:
53288943Sdim    return "Mach-O load command with size < 8 bytes";
54288943Sdim  case object_error::macho_load_segment_too_many_sections:
55288943Sdim    return "Mach-O segment load command contains too many sections";
56288943Sdim  case object_error::macho_load_segment_too_small:
57288943Sdim    return "Mach-O segment load command size is too small";
58224133Sdim  }
59261991Sdim  llvm_unreachable("An enumerator of object_error does not have a message "
60261991Sdim                   "defined.");
61224133Sdim}
62224133Sdim
63280031Sdimstatic ManagedStatic<_object_error_category> error_category;
64280031Sdim
65276479Sdimconst std::error_category &object::object_category() {
66280031Sdim  return *error_category;
67224133Sdim}
68