[obj2yaml] - Cleanup error reporting (remove Error.cpp/.h files)

This removes Error.cpp/.h files from obj2yaml.
These files are not needed because we are
using `Error`s instead of error codes widely and do
not need a logic related to obj2yaml specific
error codes anymore.

I had to adjust just a few lines of tool's code
to remove remaining dependencies.

Differential revision: https://reviews.llvm.org/D86536
This commit is contained in:
Georgii Rymar 2020-08-25 14:55:25 +03:00
parent 691f3730a9
commit fbecfa6986
8 changed files with 11 additions and 137 deletions

View File

@ -16,5 +16,4 @@ add_llvm_tool(obj2yaml
minidump2yaml.cpp minidump2yaml.cpp
xcoff2yaml.cpp xcoff2yaml.cpp
wasm2yaml.cpp wasm2yaml.cpp
Error.cpp
) )

View File

@ -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<obj2yaml_error>(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<int>(Code), obj2yaml_category());
}
} // namespace llvm

View File

@ -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 <system_error>
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<int>(e), obj2yaml_category());
}
class Obj2YamlError : public ErrorInfo<Obj2YamlError> {
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<llvm::obj2yaml_error> : std::true_type {};
}
#endif

View File

@ -6,7 +6,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "Error.h"
#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h" #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"

View File

@ -6,7 +6,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "Error.h"
#include "obj2yaml.h" #include "obj2yaml.h"
#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
@ -257,8 +256,9 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
// ABI allows us to have one SHT_SYMTAB_SHNDX for each symbol table. // 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. // We only support having the SHT_SYMTAB_SHNDX for SHT_SYMTAB now.
if (SymTabShndx) if (SymTabShndx)
return createStringError(obj2yaml_error::not_implemented, return createStringError(
"multiple SHT_SYMTAB_SHNDX sections are not supported"); errc::not_supported,
"multiple SHT_SYMTAB_SHNDX sections are not supported");
SymTabShndx = &Sec; SymTabShndx = &Sec;
} }
} }
@ -269,7 +269,7 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
if (!SymTab || if (!SymTab ||
SymTabShndx->sh_link != (unsigned)(SymTab - Sections.begin())) SymTabShndx->sh_link != (unsigned)(SymTab - Sections.begin()))
return createStringError( return createStringError(
obj2yaml_error::not_implemented, errc::not_supported,
"only SHT_SYMTAB_SHNDX associated with SHT_SYMTAB are supported"); "only SHT_SYMTAB_SHNDX associated with SHT_SYMTAB are supported");
auto TableOrErr = Obj.getSHNDXTable(*SymTabShndx); auto TableOrErr = Obj.getSHNDXTable(*SymTabShndx);

View File

@ -6,7 +6,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "Error.h"
#include "obj2yaml.h" #include "obj2yaml.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/Object/MachOUniversal.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) { Error macho2yaml(raw_ostream &Out, const object::Binary &Binary) {
if (const auto *MachOObj = dyn_cast<object::MachOUniversalBinary>(&Binary)) { if (const auto *MachOObj = dyn_cast<object::MachOUniversalBinary>(&Binary))
if (auto Err = macho2yaml(Out, *MachOObj)) { return macho2yaml(Out, *MachOObj);
return Err;
}
return Error::success();
}
if (const auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Binary)) { if (const auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Binary))
if (auto Err = macho2yaml(Out, *MachOObj)) { return macho2yaml(Out, *MachOObj);
return Err;
}
return Error::success();
}
return errorCodeToError(obj2yaml_error::unsupported_obj_file_format); llvm_unreachable("unexpected Mach-O file format");
} }

View File

@ -6,7 +6,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "Error.h"
#include "obj2yaml.h" #include "obj2yaml.h"
#include "llvm/Object/Minidump.h" #include "llvm/Object/Minidump.h"
#include "llvm/ObjectYAML/MinidumpYAML.h" #include "llvm/ObjectYAML/MinidumpYAML.h"

View File

@ -7,11 +7,11 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "obj2yaml.h" #include "obj2yaml.h"
#include "Error.h"
#include "llvm/Object/Archive.h" #include "llvm/Object/Archive.h"
#include "llvm/Object/COFF.h" #include "llvm/Object/COFF.h"
#include "llvm/Object/Minidump.h" #include "llvm/Object/Minidump.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/InitLLVM.h" #include "llvm/Support/InitLLVM.h"
using namespace llvm; using namespace llvm;
@ -30,7 +30,7 @@ static Error dumpObject(const ObjectFile &Obj) {
if (Obj.isWasm()) if (Obj.isWasm())
return errorCodeToError(wasm2yaml(outs(), cast<WasmObjectFile>(Obj))); return errorCodeToError(wasm2yaml(outs(), cast<WasmObjectFile>(Obj)));
return errorCodeToError(obj2yaml_error::unsupported_obj_file_format); llvm_unreachable("unexpected object file format");
} }
static Error dumpInput(StringRef File) { static Error dumpInput(StringRef File) {