Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 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 _do_message { |
| 21 | public: |
| 22 | virtual const char* name() const; |
| 23 | virtual std::string message(int ev) const; |
| 24 | virtual error_condition default_error_condition(int ev) const; |
| 25 | }; |
| 26 | } // namespace |
| 27 | |
| 28 | const char *_readobj_error_category::name() const { |
| 29 | return "llvm.readobj"; |
| 30 | } |
| 31 | |
| 32 | std::string _readobj_error_category::message(int ev) const { |
| 33 | switch (ev) { |
| 34 | case readobj_error::success: return "Success"; |
| 35 | case readobj_error::file_not_found: |
| 36 | return "No such file."; |
| 37 | case readobj_error::unsupported_file_format: |
| 38 | return "The file was not recognized as a valid object file."; |
| 39 | case readobj_error::unrecognized_file_format: |
| 40 | return "Unrecognized file type."; |
| 41 | case readobj_error::unsupported_obj_file_format: |
| 42 | return "Unsupported object file format."; |
| 43 | case readobj_error::unknown_symbol: |
| 44 | return "Unknown symbol."; |
| 45 | default: |
| 46 | llvm_unreachable("An enumerator of readobj_error does not have a message " |
| 47 | "defined."); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | error_condition _readobj_error_category::default_error_condition(int ev) const { |
| 52 | if (ev == readobj_error::success) |
| 53 | return errc::success; |
| 54 | return errc::invalid_argument; |
| 55 | } |
| 56 | |
| 57 | namespace llvm { |
| 58 | const error_category &readobj_category() { |
| 59 | static _readobj_error_category o; |
| 60 | return o; |
| 61 | } |
| 62 | } // namespace llvm |