[llvm] b184923 - [llvm-dwarfdump] Interface cleanup. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 09:24:57 PDT 2020


Author: Fangrui Song
Date: 2020-04-10T09:22:56-07:00
New Revision: b1849231517e05640887714c8174a5bdb8bee950

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

LOG: [llvm-dwarfdump] Interface cleanup. NFC

This patch moves interface declarations into llvm-dwarfdump.h and wrap
declarations in anonymous namespaces as appropriate. At the same time,
the externals are moved into the `llvm::dwarfdump` namespace`.

Reviewed By: djtodoro

Differential Revision: https://reviews.llvm.org/D77848

Added: 
    llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h

Modified: 
    llvm/tools/llvm-dwarfdump/SectionSizes.cpp
    llvm/tools/llvm-dwarfdump/Statistics.cpp
    llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp

Removed: 
    llvm/tools/llvm-dwarfdump/SectionSizes.h


################################################################################
diff  --git a/llvm/tools/llvm-dwarfdump/SectionSizes.cpp b/llvm/tools/llvm-dwarfdump/SectionSizes.cpp
index 21bbee57e19d..8c456d50baa7 100644
--- a/llvm/tools/llvm-dwarfdump/SectionSizes.cpp
+++ b/llvm/tools/llvm-dwarfdump/SectionSizes.cpp
@@ -6,12 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "SectionSizes.h"
+#include "llvm-dwarfdump.h"
 
 #define DEBUG_TYPE "dwarfdump"
 
 using namespace llvm;
-using namespace object;
+using namespace llvm::dwarfdump;
+using namespace llvm::object;
 
 static size_t getNameColumnWidth(const SectionSizes &Sizes,
                                  const StringRef SectionNameTitle) {
@@ -77,8 +78,9 @@ static void prettyPrintSectionSizes(const ObjectFile &Obj,
   OS << "----------------------------------------------------" << '\n';
 }
 
-void llvm::calculateSectionSizes(const ObjectFile &Obj, SectionSizes &Sizes,
-                                 const Twine &Filename) {
+void dwarfdump::calculateSectionSizes(const ObjectFile &Obj,
+                                      SectionSizes &Sizes,
+                                      const Twine &Filename) {
   // Get total size.
   Sizes.TotalObjectSize = Obj.getData().size();
 
@@ -101,8 +103,10 @@ void llvm::calculateSectionSizes(const ObjectFile &Obj, SectionSizes &Sizes,
   }
 }
 
-bool collectObjectSectionSizes(ObjectFile &Obj, DWARFContext & /*DICtx*/,
-                               const Twine &Filename, raw_ostream &OS) {
+bool dwarfdump::collectObjectSectionSizes(ObjectFile &Obj,
+                                          DWARFContext & /*DICtx*/,
+                                          const Twine &Filename,
+                                          raw_ostream &OS) {
   SectionSizes Sizes;
 
   // Get the section sizes.

diff  --git a/llvm/tools/llvm-dwarfdump/Statistics.cpp b/llvm/tools/llvm-dwarfdump/Statistics.cpp
index ca94426519fd..b4f4d97b4e12 100644
--- a/llvm/tools/llvm-dwarfdump/Statistics.cpp
+++ b/llvm/tools/llvm-dwarfdump/Statistics.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm-dwarfdump.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSet.h"
@@ -15,11 +16,10 @@
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/JSON.h"
 
-#include "SectionSizes.h"
-
 #define DEBUG_TYPE "dwarfdump"
 using namespace llvm;
-using namespace object;
+using namespace llvm::dwarfdump;
+using namespace llvm::object;
 
 /// This represents the number of categories of debug location coverage being
 /// calculated. The first category is the number of variables with 0% location
@@ -27,6 +27,7 @@ using namespace object;
 /// location coverage.
 constexpr int NumOfCoverageCategories = 12;
 
+namespace {
 /// Holds statistics for one function (or other entity that has a PC range and
 /// contains variables, such as a compile unit).
 struct PerFunctionStats {
@@ -141,6 +142,7 @@ struct LocationStats {
   /// Total number of local variables processed.
   unsigned NumVar = 0;
 };
+} // namespace
 
 /// Collect debug location statistics for one DIE.
 static void collectLocStats(uint64_t BytesCovered, uint64_t BytesInScope,
@@ -510,8 +512,9 @@ static void printSectionSizes(raw_ostream &OS, const SectionSizes &Sizes) {
 /// of particular optimizations. The raw numbers themselves are not particularly
 /// useful, only the delta between compiling the same program with 
diff erent
 /// compilers is.
-bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
-                               const Twine &Filename, raw_ostream &OS) {
+bool dwarfdump::collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
+                                          const Twine &Filename,
+                                          raw_ostream &OS) {
   StringRef FormatName = Obj.getFileFormatName();
   GlobalStats GlobalStats;
   LocationStats LocStats;

diff  --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index 7d4b0598da3d..14115c8eb998 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -10,6 +10,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm-dwarfdump.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/Triple.h"
@@ -32,8 +33,10 @@
 #include <cstdlib>
 
 using namespace llvm;
-using namespace object;
+using namespace llvm::dwarfdump;
+using namespace llvm::object;
 
+namespace {
 /// Parser for options that take an optional offest argument.
 /// @{
 struct OffsetOption {
@@ -41,6 +44,7 @@ struct OffsetOption {
   bool HasValue = false;
   bool IsRequested = false;
 };
+} // namespace
 
 namespace llvm {
 namespace cl {
@@ -82,8 +86,8 @@ class parser<OffsetOption> final : public basic_parser<OffsetOption> {
   // An out-of-line virtual method to provide a 'home' for this class.
   void anchor() override {};
 };
-} // cl
-} // llvm
+} // namespace cl
+} // namespace llvm
 
 /// @}
 /// Command line options.
@@ -416,12 +420,6 @@ static bool lookup(ObjectFile &Obj, DWARFContext &DICtx, uint64_t Address,
   return true;
 }
 
-bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
-                               const Twine &Filename, raw_ostream &OS);
-
-bool collectObjectSectionSizes(ObjectFile &Obj, DWARFContext & /*DICtx*/,
-                               const Twine &Filename, raw_ostream &OS);
-
 static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
                            const Twine &Filename, raw_ostream &OS) {
   logAllUnhandledErrors(DICtx.loadRegisterInfo(Obj), errs(),

diff  --git a/llvm/tools/llvm-dwarfdump/SectionSizes.h b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h
similarity index 58%
rename from llvm/tools/llvm-dwarfdump/SectionSizes.h
rename to llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h
index 1664b1a236d6..86a2f1b553a9 100644
--- a/llvm/tools/llvm-dwarfdump/SectionSizes.h
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h
@@ -1,28 +1,28 @@
-//===- SectionSizes.h - Debug section sizes ---------------------*- C++ -*-===//
+//===-- llvm-dwarfdump - Debug info dumping utility -------------*- 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_SECTION_SIZES_H
-#define LLVM_TOOLS_SECTION_SIZES_H
+#ifndef LLVM_TOOLS_LLVM_DWARFDUMP_LLVM_DWARFDUMP_H
+#define LLVM_TOOLS_LLVM_DWARFDUMP_LLVM_DWARFDUMP_H
 
-#include "llvm/DebugInfo/DIContext.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/WithColor.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
-
-using SectionSizeMap = StringMap<uint64_t>;
+namespace dwarfdump {
 
 /// Holds cumulative section sizes for an object file.
 struct SectionSizes {
   /// Map of .debug section names and their sizes across all such-named
   /// sections.
-  SectionSizeMap DebugSectionSizes;
+  StringMap<uint64_t> DebugSectionSizes;
   /// Total number of bytes of all sections.
   uint64_t TotalObjectSize = 0;
   /// Total number of bytes of all debug sections.
@@ -33,6 +33,12 @@ struct SectionSizes {
 void calculateSectionSizes(const object::ObjectFile &Obj, SectionSizes &Sizes,
                            const Twine &Filename);
 
-} // end namespace llvm
+bool collectStatsForObjectFile(object::ObjectFile &Obj, DWARFContext &DICtx,
+                               const Twine &Filename, raw_ostream &OS);
+bool collectObjectSectionSizes(object::ObjectFile &Obj, DWARFContext &DICtx,
+                               const Twine &Filename, raw_ostream &OS);
+
+} // namespace dwarfdump
+} // namespace llvm
 
-#endif // LLVM_TOOLS_SECTION_SIZES_H
+#endif


        


More information about the llvm-commits mailing list