diff --git a/tools/obj2yaml/CMakeLists.txt b/tools/obj2yaml/CMakeLists.txt index f76983e0e8e..d543e3670ef 100644 --- a/tools/obj2yaml/CMakeLists.txt +++ b/tools/obj2yaml/CMakeLists.txt @@ -16,5 +16,4 @@ add_llvm_tool(obj2yaml minidump2yaml.cpp xcoff2yaml.cpp wasm2yaml.cpp - Error.cpp ) diff --git a/tools/obj2yaml/Error.cpp b/tools/obj2yaml/Error.cpp deleted file mode 100644 index d11d47b5b22..00000000000 --- a/tools/obj2yaml/Error.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===- Error.cpp - system_error extensions for obj2yaml ---------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "Error.h" -#include "llvm/Support/ErrorHandling.h" - -using namespace llvm; - -namespace { -// FIXME: This class is only here to support the transition to llvm::Error. It -// will be removed once this transition is complete. Clients should prefer to -// deal with the Error value directly, rather than converting to error_code. -class _obj2yaml_error_category : public std::error_category { -public: - const char *name() const noexcept override; - std::string message(int ev) const override; -}; -} // namespace - -const char *_obj2yaml_error_category::name() const noexcept { - return "obj2yaml"; -} - -std::string _obj2yaml_error_category::message(int ev) const { - switch (static_cast(ev)) { - case obj2yaml_error::success: - return "Success"; - case obj2yaml_error::file_not_found: - return "No such file."; - case obj2yaml_error::unrecognized_file_format: - return "Unrecognized file type."; - case obj2yaml_error::unsupported_obj_file_format: - return "Unsupported object file format."; - case obj2yaml_error::not_implemented: - return "Feature not yet implemented."; - } - llvm_unreachable("An enumerator of obj2yaml_error does not have a message " - "defined."); -} - -namespace llvm { - -const std::error_category &obj2yaml_category() { - static _obj2yaml_error_category o; - return o; -} - -char Obj2YamlError::ID = 0; - -void Obj2YamlError::log(raw_ostream &OS) const { OS << ErrMsg; } - -std::error_code Obj2YamlError::convertToErrorCode() const { - return std::error_code(static_cast(Code), obj2yaml_category()); -} - -} // namespace llvm diff --git a/tools/obj2yaml/Error.h b/tools/obj2yaml/Error.h deleted file mode 100644 index 8985338c929..00000000000 --- a/tools/obj2yaml/Error.h +++ /dev/null @@ -1,53 +0,0 @@ -//===- Error.h - system_error extensions for obj2yaml -----------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TOOLS_OBJ2YAML_ERROR_H -#define LLVM_TOOLS_OBJ2YAML_ERROR_H - -#include "llvm/Support/Error.h" - -#include - -namespace llvm { -const std::error_category &obj2yaml_category(); - -enum class obj2yaml_error { - success = 0, - file_not_found, - unrecognized_file_format, - unsupported_obj_file_format, - not_implemented -}; - -inline std::error_code make_error_code(obj2yaml_error e) { - return std::error_code(static_cast(e), obj2yaml_category()); -} - -class Obj2YamlError : public ErrorInfo { -public: - static char ID; - Obj2YamlError(obj2yaml_error C) : Code(C) {} - Obj2YamlError(std::string ErrMsg) : ErrMsg(std::move(ErrMsg)) {} - Obj2YamlError(obj2yaml_error C, std::string ErrMsg) - : ErrMsg(std::move(ErrMsg)), Code(C) {} - void log(raw_ostream &OS) const override; - const std::string &getErrorMessage() const { return ErrMsg; } - std::error_code convertToErrorCode() const override; - -private: - std::string ErrMsg; - obj2yaml_error Code = obj2yaml_error::success; -}; - -} // namespace llvm - -namespace std { -template <> struct is_error_code_enum : std::true_type {}; -} - -#endif diff --git a/tools/obj2yaml/dwarf2yaml.cpp b/tools/obj2yaml/dwarf2yaml.cpp index 0f9794f1a40..fdb8c4c41c9 100644 --- a/tools/obj2yaml/dwarf2yaml.cpp +++ b/tools/obj2yaml/dwarf2yaml.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "Error.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h" diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp index 58ab2c0bbdd..632ec1bc9af 100644 --- a/tools/obj2yaml/elf2yaml.cpp +++ b/tools/obj2yaml/elf2yaml.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "Error.h" #include "obj2yaml.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" @@ -257,8 +256,9 @@ template Expected ELFDumper::dump() { // ABI allows us to have one SHT_SYMTAB_SHNDX for each symbol table. // We only support having the SHT_SYMTAB_SHNDX for SHT_SYMTAB now. if (SymTabShndx) - return createStringError(obj2yaml_error::not_implemented, - "multiple SHT_SYMTAB_SHNDX sections are not supported"); + return createStringError( + errc::not_supported, + "multiple SHT_SYMTAB_SHNDX sections are not supported"); SymTabShndx = &Sec; } } @@ -269,7 +269,7 @@ template Expected ELFDumper::dump() { if (!SymTab || SymTabShndx->sh_link != (unsigned)(SymTab - Sections.begin())) return createStringError( - obj2yaml_error::not_implemented, + errc::not_supported, "only SHT_SYMTAB_SHNDX associated with SHT_SYMTAB are supported"); auto TableOrErr = Obj.getSHNDXTable(*SymTabShndx); diff --git a/tools/obj2yaml/macho2yaml.cpp b/tools/obj2yaml/macho2yaml.cpp index d5be0acb152..3a93d5c6846 100644 --- a/tools/obj2yaml/macho2yaml.cpp +++ b/tools/obj2yaml/macho2yaml.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "Error.h" #include "obj2yaml.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/Object/MachOUniversal.h" @@ -640,19 +639,11 @@ Error macho2yaml(raw_ostream &Out, const object::MachOUniversalBinary &Obj) { } Error macho2yaml(raw_ostream &Out, const object::Binary &Binary) { - if (const auto *MachOObj = dyn_cast(&Binary)) { - if (auto Err = macho2yaml(Out, *MachOObj)) { - return Err; - } - return Error::success(); - } + if (const auto *MachOObj = dyn_cast(&Binary)) + return macho2yaml(Out, *MachOObj); - if (const auto *MachOObj = dyn_cast(&Binary)) { - if (auto Err = macho2yaml(Out, *MachOObj)) { - return Err; - } - return Error::success(); - } + if (const auto *MachOObj = dyn_cast(&Binary)) + return macho2yaml(Out, *MachOObj); - return errorCodeToError(obj2yaml_error::unsupported_obj_file_format); + llvm_unreachable("unexpected Mach-O file format"); } diff --git a/tools/obj2yaml/minidump2yaml.cpp b/tools/obj2yaml/minidump2yaml.cpp index 50c883edb27..7b25b1869c6 100644 --- a/tools/obj2yaml/minidump2yaml.cpp +++ b/tools/obj2yaml/minidump2yaml.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "Error.h" #include "obj2yaml.h" #include "llvm/Object/Minidump.h" #include "llvm/ObjectYAML/MinidumpYAML.h" diff --git a/tools/obj2yaml/obj2yaml.cpp b/tools/obj2yaml/obj2yaml.cpp index 67ba0e416e6..16fc428755e 100644 --- a/tools/obj2yaml/obj2yaml.cpp +++ b/tools/obj2yaml/obj2yaml.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "obj2yaml.h" -#include "Error.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" #include "llvm/Object/Minidump.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Errc.h" #include "llvm/Support/InitLLVM.h" using namespace llvm; @@ -30,7 +30,7 @@ static Error dumpObject(const ObjectFile &Obj) { if (Obj.isWasm()) return errorCodeToError(wasm2yaml(outs(), cast(Obj))); - return errorCodeToError(obj2yaml_error::unsupported_obj_file_format); + llvm_unreachable("unexpected object file format"); } static Error dumpInput(StringRef File) {