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