1224133Sdim//===- Error.cpp - system_error extensions for Object -----------*- C++ -*-===//
2224133Sdim//
3224133Sdim//                     The LLVM Compiler Infrastructure
4224133Sdim//
5224133Sdim// This file is distributed under the University of Illinois Open Source
6224133Sdim// License. See LICENSE.TXT for details.
7224133Sdim//
8224133Sdim//===----------------------------------------------------------------------===//
9224133Sdim//
10224133Sdim// This defines a new error_category for the Object library.
11224133Sdim//
12224133Sdim//===----------------------------------------------------------------------===//
13224133Sdim
14224133Sdim#include "llvm/Object/Error.h"
15224133Sdim#include "llvm/Support/ErrorHandling.h"
16224133Sdim
17224133Sdimusing namespace llvm;
18224133Sdimusing namespace object;
19224133Sdim
20224133Sdimnamespace {
21224133Sdimclass _object_error_category : public _do_message {
22224133Sdimpublic:
23224133Sdim  virtual const char* name() const;
24224133Sdim  virtual std::string message(int ev) const;
25224133Sdim  virtual error_condition default_error_condition(int ev) const;
26224133Sdim};
27224133Sdim}
28224133Sdim
29224133Sdimconst char *_object_error_category::name() const {
30224133Sdim  return "llvm.object";
31224133Sdim}
32224133Sdim
33224133Sdimstd::string _object_error_category::message(int ev) const {
34263508Sdim  object_error::Impl E = static_cast<object_error::Impl>(ev);
35263508Sdim  switch (E) {
36224133Sdim  case object_error::success: return "Success";
37263508Sdim  case object_error::arch_not_found:
38263508Sdim    return "No object file for requested architecture";
39224133Sdim  case object_error::invalid_file_type:
40224133Sdim    return "The file was not recognized as a valid object file";
41224133Sdim  case object_error::parse_failed:
42224133Sdim    return "Invalid data was encountered while parsing the file";
43224133Sdim  case object_error::unexpected_eof:
44224133Sdim    return "The end of the file was unexpectedly encountered";
45224133Sdim  }
46263508Sdim  llvm_unreachable("An enumerator of object_error does not have a message "
47263508Sdim                   "defined.");
48224133Sdim}
49224133Sdim
50224133Sdimerror_condition _object_error_category::default_error_condition(int ev) const {
51224133Sdim  if (ev == object_error::success)
52224133Sdim    return errc::success;
53224133Sdim  return errc::invalid_argument;
54224133Sdim}
55224133Sdim
56224133Sdimconst error_category &object::object_category() {
57224133Sdim  static _object_error_category o;
58224133Sdim  return o;
59224133Sdim}
60