[llvm] r359153 - llvm-cvtres: Make new dupe resource error a bit friendlier

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 16:26:30 PDT 2019


Author: nico
Date: Wed Apr 24 16:26:30 2019
New Revision: 359153

URL: http://llvm.org/viewvc/llvm-project?rev=359153&view=rev
Log:
llvm-cvtres: Make new dupe resource error a bit friendlier

For well-known type IDs, include the name of the type.

To not duplicate the ID->name map, make llvm-readobj call this new
function as well.  It has slightly different output, so this also
requires updating a few tests.

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

Modified:
    llvm/trunk/include/llvm/Object/WindowsResource.h
    llvm/trunk/lib/Object/WindowsResource.cpp
    llvm/trunk/test/tools/llvm-cvtres/combined.test
    llvm/trunk/test/tools/llvm-cvtres/duplicate.test
    llvm/trunk/test/tools/llvm-cvtres/object.test
    llvm/trunk/test/tools/llvm-readobj/coff-resources.test
    llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp
    llvm/trunk/tools/llvm-readobj/COFFDumper.cpp

Modified: llvm/trunk/include/llvm/Object/WindowsResource.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/WindowsResource.h?rev=359153&r1=359152&r2=359153&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/WindowsResource.h (original)
+++ llvm/trunk/include/llvm/Object/WindowsResource.h Wed Apr 24 16:26:30 2019
@@ -37,11 +37,14 @@
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/ScopedPrinter.h"
 
 #include <map>
 
 namespace llvm {
+
+class raw_ostream;
+class ScopedPrinter;
+
 namespace object {
 
 class WindowsResource;
@@ -230,6 +233,7 @@ Expected<std::unique_ptr<MemoryBuffer>>
 writeWindowsResourceCOFF(llvm::COFF::MachineTypes MachineType,
                          const WindowsResourceParser &Parser);
 
+void printResourceTypeName(uint16_t TypeID, raw_ostream &OS);
 } // namespace object
 } // namespace llvm
 

Modified: llvm/trunk/lib/Object/WindowsResource.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WindowsResource.cpp?rev=359153&r1=359152&r2=359153&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WindowsResource.cpp (original)
+++ llvm/trunk/lib/Object/WindowsResource.cpp Wed Apr 24 16:26:30 2019
@@ -15,6 +15,7 @@
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include <ctime>
 #include <queue>
 #include <system_error>
@@ -127,8 +128,35 @@ Error ResourceEntryRef::loadNext() {
 
 WindowsResourceParser::WindowsResourceParser() : Root(false) {}
 
-static Error duplicateResourceError(const ResourceEntryRef& Entry,
-                            StringRef File1, StringRef File2) {
+void printResourceTypeName(uint16_t TypeID, raw_ostream &OS) {
+  switch (TypeID) {
+  case  1: OS << "CURSOR (ID 1)"; break;
+  case  2: OS << "BITMAP (ID 2)"; break;
+  case  3: OS << "ICON (ID 3)"; break;
+  case  4: OS << "MENU (ID 4)"; break;
+  case  5: OS << "DIALOG (ID 5)"; break;
+  case  6: OS << "STRINGTABLE (ID 6)"; break;
+  case  7: OS << "FONTDIR (ID 7)"; break;
+  case  8: OS << "FONT (ID 8)"; break;
+  case  9: OS << "ACCELERATOR (ID 9)"; break;
+  case 10: OS << "RCDATA (ID 10)"; break;
+  case 11: OS << "MESSAGETABLE (ID 11)"; break;
+  case 12: OS << "GROUP_CURSOR (ID 12)"; break;
+  case 14: OS << "GROUP_ICON (ID 14)"; break;
+  case 16: OS << "VERSIONINFO (ID 16)"; break;
+  case 17: OS << "DLGINCLUDE (ID 17)"; break;
+  case 19: OS << "PLUGPLAY (ID 19)"; break;
+  case 20: OS << "VXD (ID 20)"; break;
+  case 21: OS << "ANICURSOR (ID 21)"; break;
+  case 22: OS << "ANIICON (ID 22)"; break;
+  case 23: OS << "HTML (ID 23)"; break;
+  case 24: OS << "MANIFEST (ID 24)"; break;
+  default: OS << "ID " << TypeID; break;
+  }
+}
+
+static Error makeDuplicateResourceError(const ResourceEntryRef &Entry,
+                                        StringRef File1, StringRef File2) {
   std::string Ret;
   raw_string_ostream OS(Ret);
 
@@ -140,9 +168,8 @@ static Error duplicateResourceError(cons
     if (!convertUTF16ToUTF8String(Entry.getTypeString(), UTF8))
       UTF8 = "(failed conversion from UTF16)";
     OS << '\"' << UTF8 << '\"';
-  } else {
-    OS << "ID " << Entry.getTypeID();
-  }
+  } else
+    printResourceTypeName(Entry.getTypeID(), OS);
 
   OS << "/name ";
   if (Entry.checkNameString()) {
@@ -190,8 +217,8 @@ Error WindowsResourceParser::parse(Windo
                                    IsNewTypeString, IsNewNameString, Node);
     InputFilenames.push_back(WR->getFileName());
     if (!IsNewNode)
-      return duplicateResourceError(Entry, InputFilenames[Node->Origin],
-                                    WR->getFileName());
+      return makeDuplicateResourceError(Entry, InputFilenames[Node->Origin],
+                                        WR->getFileName());
 
     if (IsNewTypeString)
       StringTable.push_back(Entry.getTypeString());

Modified: llvm/trunk/test/tools/llvm-cvtres/combined.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cvtres/combined.test?rev=359153&r1=359152&r2=359153&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cvtres/combined.test (original)
+++ llvm/trunk/test/tools/llvm-cvtres/combined.test Wed Apr 24 16:26:30 2019
@@ -32,7 +32,7 @@ CHECK-NEXT:        Characteristics: 0
 CHECK-NEXT:      ]
 CHECK-NEXT:    ]
 CHECK-NEXT:  ]
-CHECK-NEXT:  Type: kRT_BITMAP (ID 2) [
+CHECK-NEXT:  Type: BITMAP (ID 2) [
 CHECK-NEXT:    Table Offset: 0x58
 CHECK-NEXT:    Number of String Entries: 2
 CHECK-NEXT:    Number of ID Entries: 0
@@ -61,7 +61,7 @@ CHECK-NEXT:        Characteristics: 0
 CHECK-NEXT:      ]
 CHECK-NEXT:    ]
 CHECK-NEXT:  ]
-CHECK-NEXT:  Type: kRT_MENU (ID 4) [
+CHECK-NEXT:  Type: MENU (ID 4) [
 CHECK-NEXT:    Table Offset: 0x78
 CHECK-NEXT:    Number of String Entries: 1
 CHECK-NEXT:    Number of ID Entries: 1
@@ -90,7 +90,7 @@ CHECK-NEXT:        Characteristics: 0
 CHECK-NEXT:      ]
 CHECK-NEXT:    ]
 CHECK-NEXT:  ]
-CHECK-NEXT:  Type: kRT_DIALOG (ID 5) [
+CHECK-NEXT:  Type: DIALOG (ID 5) [
 CHECK-NEXT:    Table Offset: 0x98
 CHECK-NEXT:    Number of String Entries: 1
 CHECK-NEXT:    Number of ID Entries: 0
@@ -107,7 +107,7 @@ CHECK-NEXT:        Characteristics: 0
 CHECK-NEXT:      ]
 CHECK-NEXT:    ]
 CHECK-NEXT:  ]
-CHECK-NEXT:  Type: kRT_ACCELERATOR (ID 9) [
+CHECK-NEXT:  Type: ACCELERATOR (ID 9) [
 CHECK-NEXT:    Table Offset: 0xB0
 CHECK-NEXT:    Number of String Entries: 1
 CHECK-NEXT:    Number of ID Entries: 1
@@ -143,7 +143,7 @@ CHECK-NEXT:        Characteristics: 0
 CHECK-NEXT:      ]
 CHECK-NEXT:    ]
 CHECK-NEXT:  ]
-CHECK-NEXT:  Type: kRT_RCDATA (ID 10) [
+CHECK-NEXT:  Type: RCDATA (ID 10) [
 CHECK-NEXT:    Table Offset: 0xD0
 CHECK-NEXT:    Number of String Entries: 1
 CHECK-NEXT:    Number of ID Entries: 0

Modified: llvm/trunk/test/tools/llvm-cvtres/duplicate.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cvtres/duplicate.test?rev=359153&r1=359152&r2=359153&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cvtres/duplicate.test (original)
+++ llvm/trunk/test/tools/llvm-cvtres/duplicate.test Wed Apr 24 16:26:30 2019
@@ -10,7 +10,7 @@ RUN: cp %S/Inputs/id.res %t.dir/id1.res
 RUN: cp %S/Inputs/id.res %t.dir/id2.res
 RUN: not llvm-cvtres /machine:X86 %t.dir/id1.res %t.dir/id2.res 2>&1 | \
 RUN:     FileCheck -check-prefix=ID %s
-ID: duplicate resource: type ID 6/name ID 3/language 1033, in {{.*}}id1.res and in {{.*}}id2.res
+ID: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in {{.*}}id1.res and in {{.*}}id2.res
 
 RUN: cp %S/Inputs/name.res %t.dir/name1.res
 RUN: cp %S/Inputs/name.res %t.dir/name2.res

Modified: llvm/trunk/test/tools/llvm-cvtres/object.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cvtres/object.test?rev=359153&r1=359152&r2=359153&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cvtres/object.test (original)
+++ llvm/trunk/test/tools/llvm-cvtres/object.test Wed Apr 24 16:26:30 2019
@@ -31,7 +31,7 @@ CHECK-NEXT:        Characteristics: 0
 CHECK-NEXT:      ]
 CHECK-NEXT:    ]
 CHECK-NEXT:  ]
-CHECK-NEXT:  Type: kRT_BITMAP (ID 2) [
+CHECK-NEXT:  Type: BITMAP (ID 2) [
 CHECK-NEXT:    Table Offset: 0x50
 CHECK-NEXT:    Number of String Entries: 2
 CHECK-NEXT:    Number of ID Entries: 0
@@ -60,7 +60,7 @@ CHECK-NEXT:        Characteristics: 0
 CHECK-NEXT:      ]
 CHECK-NEXT:    ]
 CHECK-NEXT:  ]
-CHECK-NEXT:  Type: kRT_MENU (ID 4) [
+CHECK-NEXT:  Type: MENU (ID 4) [
 CHECK-NEXT:    Table Offset: 0x70
 CHECK-NEXT:    Number of String Entries: 1
 CHECK-NEXT:    Number of ID Entries: 1
@@ -89,7 +89,7 @@ CHECK-NEXT:        Characteristics: 0
 CHECK-NEXT:      ]
 CHECK-NEXT:    ]
 CHECK-NEXT:  ]
-CHECK-NEXT:  Type: kRT_DIALOG (ID 5) [
+CHECK-NEXT:  Type: DIALOG (ID 5) [
 CHECK-NEXT:    Table Offset: 0x90
 CHECK-NEXT:    Number of String Entries: 1
 CHECK-NEXT:    Number of ID Entries: 0
@@ -106,7 +106,7 @@ CHECK-NEXT:        Characteristics: 0
 CHECK-NEXT:      ]
 CHECK-NEXT:    ]
 CHECK-NEXT:  ]
-CHECK-NEXT:  Type: kRT_ACCELERATOR (ID 9) [
+CHECK-NEXT:  Type: ACCELERATOR (ID 9) [
 CHECK-NEXT:    Table Offset: 0xA8
 CHECK-NEXT:    Number of String Entries: 1
 CHECK-NEXT:    Number of ID Entries: 1

Modified: llvm/trunk/test/tools/llvm-readobj/coff-resources.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/coff-resources.test?rev=359153&r1=359152&r2=359153&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/coff-resources.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/coff-resources.test Wed Apr 24 16:26:30 2019
@@ -14,7 +14,7 @@ ZERO-NEXT:  Total Number of Resources: 1
 ZERO-NEXT:  Base Table Address: 0x188
 ZERO-DAG:   Number of String Entries: 0
 ZERO-NEXT:  Number of ID Entries: 1
-ZERO-NEXT:  Type: kRT_STRING (ID 6) [
+ZERO-NEXT:  Type: STRINGTABLE (ID 6) [
 ZERO-NEXT:    Table Offset: 0x18
 ZERO-NEXT:    Number of String Entries: 0
 ZERO-NEXT:    Number of ID Entries: 1
@@ -37,7 +37,7 @@ TEST_RES-NEXT:  Total Number of Resource
 TEST_RES-NEXT:  Base Table Address: 0x1C0  
 TEST_RES-DAG:   Number of String Entries: 0
 TEST_RES-NEXT:  Number of ID Entries: 4
-TEST_RES-NEXT:  Type: kRT_BITMAP (ID 2) [
+TEST_RES-NEXT:  Type: BITMAP (ID 2) [
 TEST_RES-NEXT:    Table Offset: 0x30
 TEST_RES-NEXT:    Number of String Entries: 2
 TEST_RES-NEXT:    Number of ID Entries: 0
@@ -66,7 +66,7 @@ TEST_RES-NEXT:        Characteristics: 0
 TEST_RES-NEXT:      ]
 TEST_RES-NEXT:    ]
 TEST_RES-NEXT:  ]
-TEST_RES-NEXT:  Type: kRT_MENU (ID 4) [
+TEST_RES-NEXT:  Type: MENU (ID 4) [
 TEST_RES-NEXT:    Table Offset: 0x50
 TEST_RES-NEXT:    Number of String Entries: 1
 TEST_RES-NEXT:    Number of ID Entries: 1
@@ -95,7 +95,7 @@ TEST_RES-NEXT:        Characteristics: 0
 TEST_RES-NEXT:      ]
 TEST_RES-NEXT:    ]
 TEST_RES-NEXT:  ]
-TEST_RES-NEXT:  Type: kRT_DIALOG (ID 5) [
+TEST_RES-NEXT:  Type: DIALOG (ID 5) [
 TEST_RES-NEXT:    Table Offset: 0x70
 TEST_RES-NEXT:    Number of String Entries: 1
 TEST_RES-NEXT:    Number of ID Entries: 0
@@ -112,7 +112,7 @@ TEST_RES-NEXT:        Characteristics: 0
 TEST_RES-NEXT:      ]
 TEST_RES-NEXT:    ]
 TEST_RES-NEXT:  ]
-TEST_RES-NEXT:  Type: kRT_ACCELERATOR (ID 9) [
+TEST_RES-NEXT:  Type: ACCELERATOR (ID 9) [
 TEST_RES-NEXT:    Table Offset: 0x88
 TEST_RES-NEXT:    Number of String Entries: 1
 TEST_RES-NEXT:    Number of ID Entries: 1

Modified: llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp?rev=359153&r1=359152&r2=359153&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp (original)
+++ llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp Wed Apr 24 16:26:30 2019
@@ -24,6 +24,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
 

Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=359153&r1=359152&r2=359153&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Wed Apr 24 16:26:30 2019
@@ -43,6 +43,7 @@
 #include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
 #include "llvm/Object/COFF.h"
 #include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/WindowsResource.h"
 #include "llvm/Support/BinaryStreamReader.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
@@ -569,29 +570,6 @@ static const EnumEntry<uint8_t> FileChec
   LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, SHA256),
 };
 
-static const EnumEntry<COFF::ResourceTypeID> ResourceTypeNames[]{
-    {"kRT_CURSOR (ID 1)", COFF::RID_Cursor},
-    {"kRT_BITMAP (ID 2)", COFF::RID_Bitmap},
-    {"kRT_ICON (ID 3)", COFF::RID_Icon},
-    {"kRT_MENU (ID 4)", COFF::RID_Menu},
-    {"kRT_DIALOG (ID 5)", COFF::RID_Dialog},
-    {"kRT_STRING (ID 6)", COFF::RID_String},
-    {"kRT_FONTDIR (ID 7)", COFF::RID_FontDir},
-    {"kRT_FONT (ID 8)", COFF::RID_Font},
-    {"kRT_ACCELERATOR (ID 9)", COFF::RID_Accelerator},
-    {"kRT_RCDATA (ID 10)", COFF::RID_RCData},
-    {"kRT_MESSAGETABLE (ID 11)", COFF::RID_MessageTable},
-    {"kRT_GROUP_CURSOR (ID 12)", COFF::RID_Group_Cursor},
-    {"kRT_GROUP_ICON (ID 14)", COFF::RID_Group_Icon},
-    {"kRT_VERSION (ID 16)", COFF::RID_Version},
-    {"kRT_DLGINCLUDE (ID 17)", COFF::RID_DLGInclude},
-    {"kRT_PLUGPLAY (ID 19)", COFF::RID_PlugPlay},
-    {"kRT_VXD (ID 20)", COFF::RID_VXD},
-    {"kRT_ANICURSOR (ID 21)", COFF::RID_AniCursor},
-    {"kRT_ANIICON (ID 22)", COFF::RID_AniIcon},
-    {"kRT_HTML (ID 23)", COFF::RID_HTML},
-    {"kRT_MANIFEST (ID 24)", COFF::RID_Manifest}};
-
 template <typename T>
 static std::error_code getSymbolAuxData(const COFFObjectFile *Obj,
                                         COFFSymbolRef Symbol,
@@ -1805,9 +1783,8 @@ void COFFDumper::printResourceDirectoryT
       OS << EntryNameString;
     } else {
       if (Level == "Type") {
-        ScopedPrinter Printer(OS);
-        Printer.printEnum("", Entry.Identifier.ID,
-                          makeArrayRef(ResourceTypeNames));
+        OS << ": ";
+        printResourceTypeName(Entry.Identifier.ID, OS);
         IDStr = IDStr.slice(0, IDStr.find_first_of(")", 0) + 1);
       } else {
         OS << ": (ID " << Entry.Identifier.ID << ")";




More information about the llvm-commits mailing list