1*9880d681SAndroid Build Coastguard Worker //===- Error.cpp - system_error extensions for llvm-readobj -----*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This defines a new error_category for the llvm-readobj tool. 11*9880d681SAndroid Build Coastguard Worker // 12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker #include "Error.h" 15*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/ErrorHandling.h" 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker using namespace llvm; 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Worker namespace { 20*9880d681SAndroid Build Coastguard Worker // FIXME: This class is only here to support the transition to llvm::Error. It 21*9880d681SAndroid Build Coastguard Worker // will be removed once this transition is complete. Clients should prefer to 22*9880d681SAndroid Build Coastguard Worker // deal with the Error value directly, rather than converting to error_code. 23*9880d681SAndroid Build Coastguard Worker class _readobj_error_category : public std::error_category { 24*9880d681SAndroid Build Coastguard Worker public: 25*9880d681SAndroid Build Coastguard Worker const char* name() const LLVM_NOEXCEPT override; 26*9880d681SAndroid Build Coastguard Worker std::string message(int ev) const override; 27*9880d681SAndroid Build Coastguard Worker }; 28*9880d681SAndroid Build Coastguard Worker } // namespace 29*9880d681SAndroid Build Coastguard Worker name() const30*9880d681SAndroid Build Coastguard Workerconst char *_readobj_error_category::name() const LLVM_NOEXCEPT { 31*9880d681SAndroid Build Coastguard Worker return "llvm.readobj"; 32*9880d681SAndroid Build Coastguard Worker } 33*9880d681SAndroid Build Coastguard Worker message(int EV) const34*9880d681SAndroid Build Coastguard Workerstd::string _readobj_error_category::message(int EV) const { 35*9880d681SAndroid Build Coastguard Worker switch (static_cast<readobj_error>(EV)) { 36*9880d681SAndroid Build Coastguard Worker case readobj_error::success: return "Success"; 37*9880d681SAndroid Build Coastguard Worker case readobj_error::file_not_found: 38*9880d681SAndroid Build Coastguard Worker return "No such file."; 39*9880d681SAndroid Build Coastguard Worker case readobj_error::unsupported_file_format: 40*9880d681SAndroid Build Coastguard Worker return "The file was not recognized as a valid object file."; 41*9880d681SAndroid Build Coastguard Worker case readobj_error::unrecognized_file_format: 42*9880d681SAndroid Build Coastguard Worker return "Unrecognized file type."; 43*9880d681SAndroid Build Coastguard Worker case readobj_error::unsupported_obj_file_format: 44*9880d681SAndroid Build Coastguard Worker return "Unsupported object file format."; 45*9880d681SAndroid Build Coastguard Worker case readobj_error::unknown_symbol: 46*9880d681SAndroid Build Coastguard Worker return "Unknown symbol."; 47*9880d681SAndroid Build Coastguard Worker } 48*9880d681SAndroid Build Coastguard Worker llvm_unreachable("An enumerator of readobj_error does not have a message " 49*9880d681SAndroid Build Coastguard Worker "defined."); 50*9880d681SAndroid Build Coastguard Worker } 51*9880d681SAndroid Build Coastguard Worker 52*9880d681SAndroid Build Coastguard Worker namespace llvm { readobj_category()53*9880d681SAndroid Build Coastguard Workerconst std::error_category &readobj_category() { 54*9880d681SAndroid Build Coastguard Worker static _readobj_error_category o; 55*9880d681SAndroid Build Coastguard Worker return o; 56*9880d681SAndroid Build Coastguard Worker } 57*9880d681SAndroid Build Coastguard Worker } // namespace llvm 58