Error.h revision 36b56886974eae4f9c5ebc96befd3e7bfe5de338
1//===- Error.h - system_error extensions for llvm-readobj -------*- 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// This declares a new error_category for the llvm-readobj tool.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_READOBJ_ERROR_H
15#define LLVM_READOBJ_ERROR_H
16
17#include "llvm/Support/system_error.h"
18
19namespace llvm {
20
21const error_category &readobj_category();
22
23struct readobj_error {
24  enum _ {
25    success = 0,
26    file_not_found,
27    unsupported_file_format,
28    unrecognized_file_format,
29    unsupported_obj_file_format,
30    unknown_symbol
31  };
32  _ v_;
33
34  readobj_error(_ v) : v_(v) {}
35  explicit readobj_error(int v) : v_(_(v)) {}
36  operator int() const {return v_;}
37};
38
39inline error_code make_error_code(readobj_error e) {
40  return error_code(static_cast<int>(e), readobj_category());
41}
42
43template <> struct is_error_code_enum<readobj_error> : std::true_type { };
44template <> struct is_error_code_enum<readobj_error::_> : std::true_type { };
45
46} // namespace llvm
47
48#endif
49