blob: 7e6f780c5d1a29ef245fdd60903b369d8df3708b [file] [log] [blame]
Eric Christopher9cad53c2013-04-03 18:31:38 +00001//===- Error.cpp - 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 defines a new error_category for the llvm-readobj tool.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Error.h"
15#include "llvm/Support/ErrorHandling.h"
16
17using namespace llvm;
18
19namespace {
Rafael Espindola25188c92014-06-12 01:45:43 +000020class _readobj_error_category : public std::error_category {
Eric Christopher9cad53c2013-04-03 18:31:38 +000021public:
Rafael Espindolaf5d07fa2014-06-10 21:26:47 +000022 const char* name() const LLVM_NOEXCEPT override;
Craig Toppere56917c2014-03-08 08:27:28 +000023 std::string message(int ev) const override;
Eric Christopher9cad53c2013-04-03 18:31:38 +000024};
25} // namespace
26
Reid Kleckner94add6b2014-11-03 20:35:30 +000027const char *_readobj_error_category::name() const LLVM_NOEXCEPT {
Eric Christopher9cad53c2013-04-03 18:31:38 +000028 return "llvm.readobj";
29}
30
Rafael Espindola933c9502014-06-11 01:22:20 +000031std::string _readobj_error_category::message(int EV) const {
32 switch (static_cast<readobj_error>(EV)) {
Eric Christopher9cad53c2013-04-03 18:31:38 +000033 case readobj_error::success: return "Success";
34 case readobj_error::file_not_found:
35 return "No such file.";
36 case readobj_error::unsupported_file_format:
37 return "The file was not recognized as a valid object file.";
38 case readobj_error::unrecognized_file_format:
39 return "Unrecognized file type.";
40 case readobj_error::unsupported_obj_file_format:
41 return "Unsupported object file format.";
42 case readobj_error::unknown_symbol:
43 return "Unknown symbol.";
Eric Christopher9cad53c2013-04-03 18:31:38 +000044 }
Rafael Espindola933c9502014-06-11 01:22:20 +000045 llvm_unreachable("An enumerator of readobj_error does not have a message "
46 "defined.");
Eric Christopher9cad53c2013-04-03 18:31:38 +000047}
48
Eric Christopher9cad53c2013-04-03 18:31:38 +000049namespace llvm {
Rafael Espindola25188c92014-06-12 01:45:43 +000050const std::error_category &readobj_category() {
Eric Christopher9cad53c2013-04-03 18:31:38 +000051 static _readobj_error_category o;
52 return o;
53}
54} // namespace llvm