LLVM API Documentation

Object/Error.cpp
Go to the documentation of this file.
00001 //===- Error.cpp - system_error extensions for Object -----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This defines a new error_category for the Object library.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Object/Error.h"
00015 #include "llvm/Support/ErrorHandling.h"
00016 
00017 using namespace llvm;
00018 using namespace object;
00019 
00020 namespace {
00021 class _object_error_category : public std::error_category {
00022 public:
00023   const char* name() const LLVM_NOEXCEPT override;
00024   std::string message(int ev) const override;
00025 };
00026 }
00027 
00028 const char *_object_error_category::name() const LLVM_NOEXCEPT {
00029   return "llvm.object";
00030 }
00031 
00032 std::string _object_error_category::message(int EV) const {
00033   object_error E = static_cast<object_error>(EV);
00034   switch (E) {
00035   case object_error::success: return "Success";
00036   case object_error::arch_not_found:
00037     return "No object file for requested architecture";
00038   case object_error::invalid_file_type:
00039     return "The file was not recognized as a valid object file";
00040   case object_error::parse_failed:
00041     return "Invalid data was encountered while parsing the file";
00042   case object_error::unexpected_eof:
00043     return "The end of the file was unexpectedly encountered";
00044   }
00045   llvm_unreachable("An enumerator of object_error does not have a message "
00046                    "defined.");
00047 }
00048 
00049 const std::error_category &object::object_category() {
00050   static _object_error_category o;
00051   return o;
00052 }