1 //===- Error.h - system_error extensions for obj2yaml -----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TOOLS_OBJ2YAML_ERROR_H
10 #define LLVM_TOOLS_OBJ2YAML_ERROR_H
12 #include "llvm/Support/Error.h"
14 #include <system_error>
17 const std::error_category
&obj2yaml_category();
19 enum class obj2yaml_error
{
22 unrecognized_file_format
,
23 unsupported_obj_file_format
,
27 inline std::error_code
make_error_code(obj2yaml_error e
) {
28 return std::error_code(static_cast<int>(e
), obj2yaml_category());
31 class Obj2YamlError
: public ErrorInfo
<Obj2YamlError
> {
34 Obj2YamlError(obj2yaml_error C
) : Code(C
) {}
35 Obj2YamlError(std::string ErrMsg
) : ErrMsg(std::move(ErrMsg
)) {}
36 Obj2YamlError(obj2yaml_error C
, std::string ErrMsg
)
37 : ErrMsg(std::move(ErrMsg
)), Code(C
) {}
38 void log(raw_ostream
&OS
) const override
;
39 const std::string
&getErrorMessage() const { return ErrMsg
; }
40 std::error_code
convertToErrorCode() const override
;
50 template <> struct is_error_code_enum
<llvm::obj2yaml_error
> : std::true_type
{};