xref: /aosp_15_r20/external/llvm/tools/obj2yaml/Error.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- Error.h - 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 #ifndef LLVM_TOOLS_OBJ2YAML_ERROR_H
11*9880d681SAndroid Build Coastguard Worker #define LLVM_TOOLS_OBJ2YAML_ERROR_H
12*9880d681SAndroid Build Coastguard Worker 
13*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Error.h"
14*9880d681SAndroid Build Coastguard Worker 
15*9880d681SAndroid Build Coastguard Worker #include <system_error>
16*9880d681SAndroid Build Coastguard Worker 
17*9880d681SAndroid Build Coastguard Worker namespace llvm {
18*9880d681SAndroid Build Coastguard Worker const std::error_category &obj2yaml_category();
19*9880d681SAndroid Build Coastguard Worker 
20*9880d681SAndroid Build Coastguard Worker enum class obj2yaml_error {
21*9880d681SAndroid Build Coastguard Worker   success = 0,
22*9880d681SAndroid Build Coastguard Worker   file_not_found,
23*9880d681SAndroid Build Coastguard Worker   unrecognized_file_format,
24*9880d681SAndroid Build Coastguard Worker   unsupported_obj_file_format,
25*9880d681SAndroid Build Coastguard Worker   not_implemented
26*9880d681SAndroid Build Coastguard Worker };
27*9880d681SAndroid Build Coastguard Worker 
make_error_code(obj2yaml_error e)28*9880d681SAndroid Build Coastguard Worker inline std::error_code make_error_code(obj2yaml_error e) {
29*9880d681SAndroid Build Coastguard Worker   return std::error_code(static_cast<int>(e), obj2yaml_category());
30*9880d681SAndroid Build Coastguard Worker }
31*9880d681SAndroid Build Coastguard Worker 
32*9880d681SAndroid Build Coastguard Worker class Obj2YamlError : public ErrorInfo<Obj2YamlError> {
33*9880d681SAndroid Build Coastguard Worker public:
34*9880d681SAndroid Build Coastguard Worker   static char ID;
Obj2YamlError(obj2yaml_error C)35*9880d681SAndroid Build Coastguard Worker   Obj2YamlError(obj2yaml_error C) : Code(C) {}
Obj2YamlError(std::string ErrMsg)36*9880d681SAndroid Build Coastguard Worker   Obj2YamlError(std::string ErrMsg) : ErrMsg(std::move(ErrMsg)) {}
Obj2YamlError(obj2yaml_error C,std::string ErrMsg)37*9880d681SAndroid Build Coastguard Worker   Obj2YamlError(obj2yaml_error C, std::string ErrMsg)
38*9880d681SAndroid Build Coastguard Worker       : ErrMsg(std::move(ErrMsg)), Code(C) {}
39*9880d681SAndroid Build Coastguard Worker   void log(raw_ostream &OS) const override;
getErrorMessage()40*9880d681SAndroid Build Coastguard Worker   const std::string &getErrorMessage() const { return ErrMsg; }
41*9880d681SAndroid Build Coastguard Worker   std::error_code convertToErrorCode() const override;
42*9880d681SAndroid Build Coastguard Worker 
43*9880d681SAndroid Build Coastguard Worker private:
44*9880d681SAndroid Build Coastguard Worker   std::string ErrMsg;
45*9880d681SAndroid Build Coastguard Worker   obj2yaml_error Code;
46*9880d681SAndroid Build Coastguard Worker };
47*9880d681SAndroid Build Coastguard Worker 
48*9880d681SAndroid Build Coastguard Worker } // namespace llvm
49*9880d681SAndroid Build Coastguard Worker 
50*9880d681SAndroid Build Coastguard Worker namespace std {
51*9880d681SAndroid Build Coastguard Worker template <> struct is_error_code_enum<llvm::obj2yaml_error> : std::true_type {};
52*9880d681SAndroid Build Coastguard Worker }
53*9880d681SAndroid Build Coastguard Worker 
54*9880d681SAndroid Build Coastguard Worker #endif
55