xref: /aosp_15_r20/external/llvm/tools/obj2yaml/Error.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- Error.cpp - system_error extensions for obj2yaml ---------*- 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 #include "Error.h"
11*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/ErrorHandling.h"
12*9880d681SAndroid Build Coastguard Worker 
13*9880d681SAndroid Build Coastguard Worker using namespace llvm;
14*9880d681SAndroid Build Coastguard Worker 
15*9880d681SAndroid Build Coastguard Worker namespace {
16*9880d681SAndroid Build Coastguard Worker // FIXME: This class is only here to support the transition to llvm::Error. It
17*9880d681SAndroid Build Coastguard Worker // will be removed once this transition is complete. Clients should prefer to
18*9880d681SAndroid Build Coastguard Worker // deal with the Error value directly, rather than converting to error_code.
19*9880d681SAndroid Build Coastguard Worker class _obj2yaml_error_category : public std::error_category {
20*9880d681SAndroid Build Coastguard Worker public:
21*9880d681SAndroid Build Coastguard Worker   const char *name() const LLVM_NOEXCEPT override;
22*9880d681SAndroid Build Coastguard Worker   std::string message(int ev) const override;
23*9880d681SAndroid Build Coastguard Worker };
24*9880d681SAndroid Build Coastguard Worker } // namespace
25*9880d681SAndroid Build Coastguard Worker 
name() const26*9880d681SAndroid Build Coastguard Worker const char *_obj2yaml_error_category::name() const LLVM_NOEXCEPT {
27*9880d681SAndroid Build Coastguard Worker   return "obj2yaml";
28*9880d681SAndroid Build Coastguard Worker }
29*9880d681SAndroid Build Coastguard Worker 
message(int ev) const30*9880d681SAndroid Build Coastguard Worker std::string _obj2yaml_error_category::message(int ev) const {
31*9880d681SAndroid Build Coastguard Worker   switch (static_cast<obj2yaml_error>(ev)) {
32*9880d681SAndroid Build Coastguard Worker   case obj2yaml_error::success:
33*9880d681SAndroid Build Coastguard Worker     return "Success";
34*9880d681SAndroid Build Coastguard Worker   case obj2yaml_error::file_not_found:
35*9880d681SAndroid Build Coastguard Worker     return "No such file.";
36*9880d681SAndroid Build Coastguard Worker   case obj2yaml_error::unrecognized_file_format:
37*9880d681SAndroid Build Coastguard Worker     return "Unrecognized file type.";
38*9880d681SAndroid Build Coastguard Worker   case obj2yaml_error::unsupported_obj_file_format:
39*9880d681SAndroid Build Coastguard Worker     return "Unsupported object file format.";
40*9880d681SAndroid Build Coastguard Worker   case obj2yaml_error::not_implemented:
41*9880d681SAndroid Build Coastguard Worker     return "Feature not yet implemented.";
42*9880d681SAndroid Build Coastguard Worker   }
43*9880d681SAndroid Build Coastguard Worker   llvm_unreachable("An enumerator of obj2yaml_error does not have a message "
44*9880d681SAndroid Build Coastguard Worker                    "defined.");
45*9880d681SAndroid Build Coastguard Worker }
46*9880d681SAndroid Build Coastguard Worker 
47*9880d681SAndroid Build Coastguard Worker namespace llvm {
48*9880d681SAndroid Build Coastguard Worker 
obj2yaml_category()49*9880d681SAndroid Build Coastguard Worker const std::error_category &obj2yaml_category() {
50*9880d681SAndroid Build Coastguard Worker   static _obj2yaml_error_category o;
51*9880d681SAndroid Build Coastguard Worker   return o;
52*9880d681SAndroid Build Coastguard Worker }
53*9880d681SAndroid Build Coastguard Worker 
54*9880d681SAndroid Build Coastguard Worker char Obj2YamlError::ID = 0;
55*9880d681SAndroid Build Coastguard Worker 
log(raw_ostream & OS) const56*9880d681SAndroid Build Coastguard Worker void Obj2YamlError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
57*9880d681SAndroid Build Coastguard Worker 
convertToErrorCode() const58*9880d681SAndroid Build Coastguard Worker std::error_code Obj2YamlError::convertToErrorCode() const {
59*9880d681SAndroid Build Coastguard Worker   return std::error_code(static_cast<int>(Code), obj2yaml_category());
60*9880d681SAndroid Build Coastguard Worker }
61*9880d681SAndroid Build Coastguard Worker 
62*9880d681SAndroid Build Coastguard Worker } // namespace llvm
63