[llvm] [llvm-readobj][COFF] Add JSON Output Style (PR #95074)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 10 21:52:36 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 6ffdcfa7fcb32192104b9742b02489395c4c6ad8 4d1be316958a01f009731309ee3b550e96d99b83 -- llvm/tools/llvm-readobj/COFFDumper.cpp llvm/tools/llvm-readobj/llvm-readobj.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index e05165a2a6..10c44568c4 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -109,13 +109,15 @@ public:
   void printStackMap() const override;
   void printAddrsig() override;
   void printCGProfile() override;
-  virtual void printImportedSymbols(iterator_range<imported_symbol_iterator> Range);
-  virtual void printDelayImportedSymbols(
-      const DelayImportDirectoryEntryRef &I,
-      iterator_range<imported_symbol_iterator> Range);
+  virtual void
+  printImportedSymbols(iterator_range<imported_symbol_iterator> Range);
+  virtual void
+  printDelayImportedSymbols(const DelayImportDirectoryEntryRef &I,
+                            iterator_range<imported_symbol_iterator> Range);
   typedef void (*PrintExtraCB)(raw_ostream &, const uint8_t *);
-  virtual void printRVATable(uint64_t TableVA, uint64_t Count, uint64_t EntrySize,
-                     PrintExtraCB PrintExtra = nullptr);
+  virtual void printRVATable(uint64_t TableVA, uint64_t Count,
+                             uint64_t EntrySize,
+                             PrintExtraCB PrintExtra = nullptr);
 
 protected:
   StringRef getSymbolName(uint32_t Index);
@@ -260,13 +262,22 @@ public:
                      PrintExtraCB PrintExtra = nullptr) override;
 
 private:
-  using ResourceEntryTy = std::pair<std::string, std::reference_wrapper<const coff_resource_dir_entry>>;
-  std::vector<ResourceEntryTy> getResourceTableEntries(ResourceSectionRef RSF, const coff_resource_dir_table &Table, bool SubDirEntriesOnly = true);
+  using ResourceEntryTy =
+      std::pair<std::string,
+                std::reference_wrapper<const coff_resource_dir_entry>>;
+  std::vector<ResourceEntryTy>
+  getResourceTableEntries(ResourceSectionRef RSF,
+                          const coff_resource_dir_table &Table,
+                          bool SubDirEntriesOnly = true);
   void printResourceDirectoryTable(const coff_resource_dir_table &Table);
-  void printResourceDirectoryTypeTable(ResourceSectionRef RSF,
-                                   const coff_resource_dir_table &TypeTable);
-  void printResourceDirectoryNameTable(ResourceSectionRef RSF, const coff_resource_dir_table &NameTable);
-  void printResourceDirectoryLanguageTable(ResourceSectionRef RSF, const coff_resource_dir_table &LanguageTable);
+  void
+  printResourceDirectoryTypeTable(ResourceSectionRef RSF,
+                                  const coff_resource_dir_table &TypeTable);
+  void
+  printResourceDirectoryNameTable(ResourceSectionRef RSF,
+                                  const coff_resource_dir_table &NameTable);
+  void printResourceDirectoryLanguageTable(
+      ResourceSectionRef RSF, const coff_resource_dir_table &LanguageTable);
 
   std::unique_ptr<DictScope> FileScope;
 };
@@ -2328,12 +2339,12 @@ void JSONCOFFDumper::printDelayImportedSymbols(
 }
 
 void JSONCOFFDumper::printRVATable(uint64_t TableVA, uint64_t Count,
-                               uint64_t EntrySize, PrintExtraCB PrintExtra) {
+                                   uint64_t EntrySize,
+                                   PrintExtraCB PrintExtra) {
   uintptr_t TableStart, TableEnd;
   if (Error E = Obj->getVaPtr(TableVA, TableStart))
     reportError(std::move(E), Obj->getFileName());
-  if (Error E =
-          Obj->getVaPtr(TableVA + Count * EntrySize - 1, TableEnd))
+  if (Error E = Obj->getVaPtr(TableVA + Count * EntrySize - 1, TableEnd))
     reportError(std::move(E), Obj->getFileName());
   TableEnd++;
   for (uintptr_t I = TableStart; I < TableEnd; I += EntrySize) {
@@ -2363,7 +2374,7 @@ void JSONCOFFDumper::printCOFFResources() {
       W.printNumber("Total Number of Resources",
                     countTotalTableEntries(RSF, TypeTable, "Type"));
       W.printHex("Base Table Address",
-                Obj->getCOFFSection(S)->PointerToRawData);
+                 Obj->getCOFFSection(S)->PointerToRawData);
       printResourceDirectoryTypeTable(RSF, TypeTable);
     }
     if (opts::SectionData)
@@ -2371,10 +2382,15 @@ void JSONCOFFDumper::printCOFFResources() {
   }
 }
 
-std::vector<JSONCOFFDumper::ResourceEntryTy> JSONCOFFDumper::getResourceTableEntries(ResourceSectionRef RSF, const coff_resource_dir_table &Table, bool SubDirEntriesOnly) {
+std::vector<JSONCOFFDumper::ResourceEntryTy>
+JSONCOFFDumper::getResourceTableEntries(ResourceSectionRef RSF,
+                                        const coff_resource_dir_table &Table,
+                                        bool SubDirEntriesOnly) {
   std::vector<ResourceEntryTy> TableEntries;
-  for (int i = 0; i < Table.NumberOfNameEntries + Table.NumberOfIDEntries; ++i) {
-    auto &Entry = unwrapOrError(Obj->getFileName(), RSF.getTableEntry(Table, i));
+  for (int i = 0; i < Table.NumberOfNameEntries + Table.NumberOfIDEntries;
+       ++i) {
+    auto &Entry =
+        unwrapOrError(Obj->getFileName(), RSF.getTableEntry(Table, i));
 
     std::string Name;
 
@@ -2392,7 +2408,7 @@ std::vector<JSONCOFFDumper::ResourceEntryTy> JSONCOFFDumper::getResourceTableEnt
       if (!llvm::convertUTF16ToUTF8String(RawEntryNameString, Name))
         reportError(errorCodeToError(object_error::parse_failed),
                     Obj->getFileName());
-    } 
+    }
 
     if (Entry.Offset.isSubDir()) {
       TableEntries.push_back({Name, Entry});
@@ -2406,66 +2422,72 @@ std::vector<JSONCOFFDumper::ResourceEntryTy> JSONCOFFDumper::getResourceTableEnt
   return TableEntries;
 }
 
-void JSONCOFFDumper::printResourceDirectoryTable(const coff_resource_dir_table &Table) {
-    W.printNumber("Number of String Entries", Table.NumberOfNameEntries);
-    W.printNumber("Number of ID Entries", Table.NumberOfIDEntries);
+void JSONCOFFDumper::printResourceDirectoryTable(
+    const coff_resource_dir_table &Table) {
+  W.printNumber("Number of String Entries", Table.NumberOfNameEntries);
+  W.printNumber("Number of ID Entries", Table.NumberOfIDEntries);
 }
 
-void JSONCOFFDumper::printResourceDirectoryLanguageTable(ResourceSectionRef RSF, const coff_resource_dir_table &LanguageTable) {
+void JSONCOFFDumper::printResourceDirectoryLanguageTable(
+    ResourceSectionRef RSF, const coff_resource_dir_table &LanguageTable) {
   DictScope D(W, "Resource Language Table");
   printResourceDirectoryTable(LanguageTable);
 
-  std::vector<ResourceEntryTy> LanguageTableEntries = getResourceTableEntries(RSF, LanguageTable, false);
+  std::vector<ResourceEntryTy> LanguageTableEntries =
+      getResourceTableEntries(RSF, LanguageTable, false);
 
   ListScope LLS(W, "Entries");
   for (auto &LTP : LanguageTableEntries) {
-     const auto &LanguageTableEntry = LTP.second.get();
-
-     DictScope LD(W);
-     W.printHex("Entry Offset", LanguageTableEntry.Offset.value());
-     char FormattedTime[20] = {};
-     time_t TDS = time_t(LanguageTable.TimeDateStamp);
-     strftime(FormattedTime, 20, "%Y-%m-%d %H:%M:%S", gmtime(&TDS));
-     W.printHex("Time/Date Stamp", FormattedTime, LanguageTable.TimeDateStamp);
-     W.printNumber("Major Version", LanguageTable.MajorVersion);
-     W.printNumber("Minor Version", LanguageTable.MinorVersion);
-     W.printNumber("Characteristics", LanguageTable.Characteristics);
-     DictScope DataScope(W, "Data");
-     auto &DataEntry =
-         unwrapOrError(Obj->getFileName(), RSF.getEntryData(LanguageTableEntry));
-     W.printHex("DataRVA", DataEntry.DataRVA);
-     W.printNumber("DataSize", DataEntry.DataSize);
-     W.printNumber("Codepage", DataEntry.Codepage);
-     W.printNumber("Reserved", DataEntry.Reserved);
-     StringRef Contents =
-         unwrapOrError(Obj->getFileName(), RSF.getContents(DataEntry));
-     W.printBinaryBlock("Data", Contents);
+    const auto &LanguageTableEntry = LTP.second.get();
+
+    DictScope LD(W);
+    W.printHex("Entry Offset", LanguageTableEntry.Offset.value());
+    char FormattedTime[20] = {};
+    time_t TDS = time_t(LanguageTable.TimeDateStamp);
+    strftime(FormattedTime, 20, "%Y-%m-%d %H:%M:%S", gmtime(&TDS));
+    W.printHex("Time/Date Stamp", FormattedTime, LanguageTable.TimeDateStamp);
+    W.printNumber("Major Version", LanguageTable.MajorVersion);
+    W.printNumber("Minor Version", LanguageTable.MinorVersion);
+    W.printNumber("Characteristics", LanguageTable.Characteristics);
+    DictScope DataScope(W, "Data");
+    auto &DataEntry =
+        unwrapOrError(Obj->getFileName(), RSF.getEntryData(LanguageTableEntry));
+    W.printHex("DataRVA", DataEntry.DataRVA);
+    W.printNumber("DataSize", DataEntry.DataSize);
+    W.printNumber("Codepage", DataEntry.Codepage);
+    W.printNumber("Reserved", DataEntry.Reserved);
+    StringRef Contents =
+        unwrapOrError(Obj->getFileName(), RSF.getContents(DataEntry));
+    W.printBinaryBlock("Data", Contents);
   }
 }
 
-void JSONCOFFDumper::printResourceDirectoryNameTable(ResourceSectionRef RSF, const coff_resource_dir_table &NameTable) {
-    DictScope D(W, "Resource Name Table");
-    printResourceDirectoryTable(NameTable);
+void JSONCOFFDumper::printResourceDirectoryNameTable(
+    ResourceSectionRef RSF, const coff_resource_dir_table &NameTable) {
+  DictScope D(W, "Resource Name Table");
+  printResourceDirectoryTable(NameTable);
 
-    std::vector<ResourceEntryTy> NameTableEntries = getResourceTableEntries(RSF, NameTable); 
+  std::vector<ResourceEntryTy> NameTableEntries =
+      getResourceTableEntries(RSF, NameTable);
 
-    ListScope NLS(W, "Entries");
-    for (auto &NTP : NameTableEntries) {
-      auto &Name = NTP.first;
-      const auto &NameTableEntry = NTP.second.get();
-      DictScope ND(W);
+  ListScope NLS(W, "Entries");
+  for (auto &NTP : NameTableEntries) {
+    auto &Name = NTP.first;
+    const auto &NameTableEntry = NTP.second.get();
+    DictScope ND(W);
 
-      W.printHex("Table Offset", NameTableEntry.Offset.value());
-      W.printString("Name", Name);
+    W.printHex("Table Offset", NameTableEntry.Offset.value());
+    W.printString("Name", Name);
 
-      // The ID can be ignored if name is non-empty. We emit the "ID" so data is consistent.
-      auto ID = !Name.empty() ? 0 : NameTableEntry.Identifier.ID;
-      W.printNumber("ID", ID);
+    // The ID can be ignored if name is non-empty. We emit the "ID" so data is
+    // consistent.
+    auto ID = !Name.empty() ? 0 : NameTableEntry.Identifier.ID;
+    W.printNumber("ID", ID);
 
-      auto &LanguageTable =
-          unwrapOrError(Obj->getFileName(), RSF.getEntrySubDir(NameTableEntry));
-      printResourceDirectoryLanguageTable(RSF, LanguageTable);
-    }
+    auto &LanguageTable =
+        unwrapOrError(Obj->getFileName(), RSF.getEntrySubDir(NameTableEntry));
+    printResourceDirectoryLanguageTable(RSF, LanguageTable);
+  }
 }
 
 void JSONCOFFDumper::printResourceDirectoryTypeTable(
@@ -2475,7 +2497,8 @@ void JSONCOFFDumper::printResourceDirectoryTypeTable(
   printResourceDirectoryTable(TypeTable);
 
   ListScope LS(W, "Entries");
-  std::vector<ResourceEntryTy> TypeTableEntries = getResourceTableEntries(RSF, TypeTable); 
+  std::vector<ResourceEntryTy> TypeTableEntries =
+      getResourceTableEntries(RSF, TypeTable);
 
   for (auto &TTP : TypeTableEntries) {
     const auto &TypeTableEntry = TTP.second.get();
@@ -2487,6 +2510,6 @@ void JSONCOFFDumper::printResourceDirectoryTypeTable(
     auto &NameTable =
         unwrapOrError(Obj->getFileName(), RSF.getEntrySubDir(TypeTableEntry));
 
-    printResourceDirectoryNameTable(RSF, NameTable); 
+    printResourceDirectoryNameTable(RSF, NameTable);
   }
 }
\ No newline at end of file

``````````

</details>


https://github.com/llvm/llvm-project/pull/95074


More information about the llvm-commits mailing list