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

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 04:25:58 PDT 2020


Author: Georgii Rymar
Date: 2020-08-26T14:25:11+03:00
New Revision: 357dc1ed125e4bf55f1e99fb141fc054c285edbf

URL: https://github.com/llvm/llvm-project/commit/357dc1ed125e4bf55f1e99fb141fc054c285edbf
DIFF: https://github.com/llvm/llvm-project/commit/357dc1ed125e4bf55f1e99fb141fc054c285edbf.diff

LOG: [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

Added: 
    

Modified: 
    llvm/tools/obj2yaml/CMakeLists.txt
    llvm/tools/obj2yaml/dwarf2yaml.cpp
    llvm/tools/obj2yaml/elf2yaml.cpp
    llvm/tools/obj2yaml/macho2yaml.cpp
    llvm/tools/obj2yaml/minidump2yaml.cpp
    llvm/tools/obj2yaml/obj2yaml.cpp

Removed: 
    llvm/tools/obj2yaml/Error.cpp
    llvm/tools/obj2yaml/Error.h


################################################################################
diff  --git a/llvm/tools/obj2yaml/CMakeLists.txt b/llvm/tools/obj2yaml/CMakeLists.txt
index f76983e0e8ec..d543e3670efb 100644
--- a/llvm/tools/obj2yaml/CMakeLists.txt
+++ b/llvm/tools/obj2yaml/CMakeLists.txt
@@ -16,5 +16,4 @@ add_llvm_tool(obj2yaml
   minidump2yaml.cpp
   xcoff2yaml.cpp
   wasm2yaml.cpp
-  Error.cpp
   )

diff  --git a/llvm/tools/obj2yaml/Error.cpp b/llvm/tools/obj2yaml/Error.cpp
deleted file mode 100644
index d11d47b5b227..000000000000
--- a/llvm/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<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

diff  --git a/llvm/tools/obj2yaml/Error.h b/llvm/tools/obj2yaml/Error.h
deleted file mode 100644
index 8985338c9295..000000000000
--- a/llvm/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 <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

diff  --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp
index 0f9794f1a403..fdb8c4c41c96 100644
--- a/llvm/tools/obj2yaml/dwarf2yaml.cpp
+++ b/llvm/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/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 58ab2c0bbdd2..632ec1bc9af4 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/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 <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::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 <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::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/llvm/tools/obj2yaml/macho2yaml.cpp b/llvm/tools/obj2yaml/macho2yaml.cpp
index d5be0acb1527..3a93d5c6846b 100644
--- a/llvm/tools/obj2yaml/macho2yaml.cpp
+++ b/llvm/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<object::MachOUniversalBinary>(&Binary)) {
-    if (auto Err = macho2yaml(Out, *MachOObj)) {
-      return Err;
-    }
-    return Error::success();
-  }
+  if (const auto *MachOObj = dyn_cast<object::MachOUniversalBinary>(&Binary))
+    return macho2yaml(Out, *MachOObj);
 
-  if (const auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Binary)) {
-    if (auto Err = macho2yaml(Out, *MachOObj)) {
-      return Err;
-    }
-    return Error::success();
-  }
+  if (const auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Binary))
+    return macho2yaml(Out, *MachOObj);
 
-  return errorCodeToError(obj2yaml_error::unsupported_obj_file_format);
+  llvm_unreachable("unexpected Mach-O file format");
 }

diff  --git a/llvm/tools/obj2yaml/minidump2yaml.cpp b/llvm/tools/obj2yaml/minidump2yaml.cpp
index 50c883edb271..7b25b1869c6b 100644
--- a/llvm/tools/obj2yaml/minidump2yaml.cpp
+++ b/llvm/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/llvm/tools/obj2yaml/obj2yaml.cpp b/llvm/tools/obj2yaml/obj2yaml.cpp
index 67ba0e416e68..16fc428755e2 100644
--- a/llvm/tools/obj2yaml/obj2yaml.cpp
+++ b/llvm/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<WasmObjectFile>(Obj)));
 
-  return errorCodeToError(obj2yaml_error::unsupported_obj_file_format);
+  llvm_unreachable("unexpected object file format");
 }
 
 static Error dumpInput(StringRef File) {


        


More information about the llvm-commits mailing list