35e0a48fda08beff3dd845228b6d4a466285c0b6
[oota-llvm.git] / tools / llvm-readobj / Error.cpp
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
14 #include "Error.h"
15 #include "llvm/Support/ErrorHandling.h"
16
17 using namespace llvm;
18
19 namespace {
20 class _readobj_error_category : public error_category {
21 public:
22   const char* name() const LLVM_NOEXCEPT override;
23   std::string message(int ev) const override;
24   std::error_condition
25   default_error_condition(int ev) const LLVM_NOEXCEPT override;
26 };
27 } // namespace
28
29 const char *_readobj_error_category::name() const {
30   return "llvm.readobj";
31 }
32
33 std::string _readobj_error_category::message(int EV) const {
34   switch (static_cast<readobj_error>(EV)) {
35   case readobj_error::success: return "Success";
36   case readobj_error::file_not_found:
37     return "No such file.";
38   case readobj_error::unsupported_file_format:
39     return "The file was not recognized as a valid object file.";
40   case readobj_error::unrecognized_file_format:
41     return "Unrecognized file type.";
42   case readobj_error::unsupported_obj_file_format:
43     return "Unsupported object file format.";
44   case readobj_error::unknown_symbol:
45     return "Unknown symbol.";
46   }
47   llvm_unreachable("An enumerator of readobj_error does not have a message "
48                    "defined.");
49 }
50
51 std::error_condition
52 _readobj_error_category::default_error_condition(int EV) const {
53   if (static_cast<readobj_error>(EV) == readobj_error::success)
54     return std::error_condition();
55   return std::errc::invalid_argument;
56 }
57
58 namespace llvm {
59 const error_category &readobj_category() {
60   static _readobj_error_category o;
61   return o;
62 }
63 } // namespace llvm