Home | History | Annotate | Download | only in obj2yaml
      1 //===- Error.cpp - 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 #include "Error.h"
     11 #include "llvm/Support/ErrorHandling.h"
     12 
     13 using namespace llvm;
     14 
     15 namespace {
     16 // FIXME: This class is only here to support the transition to llvm::Error. It
     17 // will be removed once this transition is complete. Clients should prefer to
     18 // deal with the Error value directly, rather than converting to error_code.
     19 class _obj2yaml_error_category : public std::error_category {
     20 public:
     21   const char *name() const noexcept override;
     22   std::string message(int ev) const override;
     23 };
     24 } // namespace
     25 
     26 const char *_obj2yaml_error_category::name() const noexcept {
     27   return "obj2yaml";
     28 }
     29 
     30 std::string _obj2yaml_error_category::message(int ev) const {
     31   switch (static_cast<obj2yaml_error>(ev)) {
     32   case obj2yaml_error::success:
     33     return "Success";
     34   case obj2yaml_error::file_not_found:
     35     return "No such file.";
     36   case obj2yaml_error::unrecognized_file_format:
     37     return "Unrecognized file type.";
     38   case obj2yaml_error::unsupported_obj_file_format:
     39     return "Unsupported object file format.";
     40   case obj2yaml_error::not_implemented:
     41     return "Feature not yet implemented.";
     42   }
     43   llvm_unreachable("An enumerator of obj2yaml_error does not have a message "
     44                    "defined.");
     45 }
     46 
     47 namespace llvm {
     48 
     49 const std::error_category &obj2yaml_category() {
     50   static _obj2yaml_error_category o;
     51   return o;
     52 }
     53 
     54 char Obj2YamlError::ID = 0;
     55 
     56 void Obj2YamlError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
     57 
     58 std::error_code Obj2YamlError::convertToErrorCode() const {
     59   return std::error_code(static_cast<int>(Code), obj2yaml_category());
     60 }
     61 
     62 } // namespace llvm
     63