blob: 03d349440e6b62a1750aa5f0a8404d9d27cfd4d0 [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 {
Peter Collingbourne4718f8b2016-05-24 20:13:46 +000020// FIXME: This class is only here to support the transition to llvm::Error. It
21// will be removed once this transition is complete. Clients should prefer to
22// deal with the Error value directly, rather than converting to error_code.
Rafael Espindola25188c92014-06-12 01:45:43 +000023class _readobj_error_category : public std::error_category {
Eric Christopher9cad53c2013-04-03 18:31:38 +000024public:
Reid Kleckner990504e2016-10-19 23:52:38 +000025 const char* name() const noexcept override;
Craig Toppere56917c2014-03-08 08:27:28 +000026 std::string message(int ev) const override;
Eric Christopher9cad53c2013-04-03 18:31:38 +000027};
28} // namespace
29
Reid Kleckner990504e2016-10-19 23:52:38 +000030const char *_readobj_error_category::name() const noexcept {
Eric Christopher9cad53c2013-04-03 18:31:38 +000031 return "llvm.readobj";
32}
33
Rafael Espindola933c9502014-06-11 01:22:20 +000034std::string _readobj_error_category::message(int EV) const {
35 switch (static_cast<readobj_error>(EV)) {
Eric Christopher9cad53c2013-04-03 18:31:38 +000036 case readobj_error::success: return "Success";
37 case readobj_error::file_not_found:
38 return "No such file.";
39 case readobj_error::unsupported_file_format:
40 return "The file was not recognized as a valid object file.";
41 case readobj_error::unrecognized_file_format:
42 return "Unrecognized file type.";
43 case readobj_error::unsupported_obj_file_format:
44 return "Unsupported object file format.";
45 case readobj_error::unknown_symbol:
46 return "Unknown symbol.";
Eric Christopher9cad53c2013-04-03 18:31:38 +000047 }
Rafael Espindola933c9502014-06-11 01:22:20 +000048 llvm_unreachable("An enumerator of readobj_error does not have a message "
49 "defined.");
Eric Christopher9cad53c2013-04-03 18:31:38 +000050}
51
Eric Christopher9cad53c2013-04-03 18:31:38 +000052namespace llvm {
Rafael Espindola25188c92014-06-12 01:45:43 +000053const std::error_category &readobj_category() {
Eric Christopher9cad53c2013-04-03 18:31:38 +000054 static _readobj_error_category o;
55 return o;
56}
57} // namespace llvm