39d765f884e27f9628c7b8ca970fbd165b98a54a
[oota-llvm.git] / lib / Object / Error.cpp
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
14 #include "llvm/Object/Error.h"
15 #include "llvm/Support/ErrorHandling.h"
16
17 using namespace llvm;
18 using namespace object;
19
20 namespace {
21 class _object_error_category : public error_category {
22 public:
23   const char* name() const LLVM_NOEXCEPT override;
24   std::string message(int ev) const override;
25   std::error_condition
26   default_error_condition(int ev) const LLVM_NOEXCEPT override;
27 };
28 }
29
30 const char *_object_error_category::name() const {
31   return "llvm.object";
32 }
33
34 std::string _object_error_category::message(int EV) const {
35   object_error E = static_cast<object_error>(EV);
36   switch (E) {
37   case object_error::success: return "Success";
38   case object_error::arch_not_found:
39     return "No object file for requested architecture";
40   case object_error::invalid_file_type:
41     return "The file was not recognized as a valid object file";
42   case object_error::parse_failed:
43     return "Invalid data was encountered while parsing the file";
44   case object_error::unexpected_eof:
45     return "The end of the file was unexpectedly encountered";
46   }
47   llvm_unreachable("An enumerator of object_error does not have a message "
48                    "defined.");
49 }
50
51 std::error_condition
52 _object_error_category::default_error_condition(int EV) const {
53   if (static_cast<object_error>(EV) == object_error::success)
54     return std::error_condition();
55   return std::errc::invalid_argument;
56 }
57
58 const error_category &object::object_category() {
59   static _object_error_category o;
60   return o;
61 }