Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 1 | //===- Error.cpp - system_error extensions for llvm-readobj -----*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This defines a new error_category for the llvm-readobj tool. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "Error.h" |
| 14 | #include "llvm/Support/ErrorHandling.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | namespace { |
Peter Collingbourne | 4718f8b | 2016-05-24 20:13:46 +0000 | [diff] [blame] | 19 | // FIXME: This class is only here to support the transition to llvm::Error. It |
| 20 | // will be removed once this transition is complete. Clients should prefer to |
| 21 | // deal with the Error value directly, rather than converting to error_code. |
Rafael Espindola | 25188c9 | 2014-06-12 01:45:43 +0000 | [diff] [blame] | 22 | class _readobj_error_category : public std::error_category { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 23 | public: |
Reid Kleckner | 990504e | 2016-10-19 23:52:38 +0000 | [diff] [blame] | 24 | const char* name() const noexcept override; |
Craig Topper | e56917c | 2014-03-08 08:27:28 +0000 | [diff] [blame] | 25 | std::string message(int ev) const override; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 26 | }; |
| 27 | } // namespace |
| 28 | |
Reid Kleckner | 990504e | 2016-10-19 23:52:38 +0000 | [diff] [blame] | 29 | const char *_readobj_error_category::name() const noexcept { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 30 | return "llvm.readobj"; |
| 31 | } |
| 32 | |
Rafael Espindola | 933c950 | 2014-06-11 01:22:20 +0000 | [diff] [blame] | 33 | std::string _readobj_error_category::message(int EV) const { |
| 34 | switch (static_cast<readobj_error>(EV)) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 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."; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 46 | } |
Rafael Espindola | 933c950 | 2014-06-11 01:22:20 +0000 | [diff] [blame] | 47 | llvm_unreachable("An enumerator of readobj_error does not have a message " |
| 48 | "defined."); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 51 | namespace llvm { |
Rafael Espindola | 25188c9 | 2014-06-12 01:45:43 +0000 | [diff] [blame] | 52 | const std::error_category &readobj_category() { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 53 | static _readobj_error_category o; |
| 54 | return o; |
| 55 | } |
| 56 | } // namespace llvm |