[llvm-readobj] Teach readobj to dump .res files (WindowsResource).
This enables readobj to output Windows resource files (.res). This way,
we'll be able to test .res outputs without comparing them byte-by-byte
with "magic binary files" generated by MS toolchain.
Differential Revision: https://reviews.llvm.org/D38058
llvm-svn: 313790
diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp
index 7bfb18f..f24ce67 100644
--- a/llvm/tools/llvm-readobj/llvm-readobj.cpp
+++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp
@@ -22,12 +22,14 @@
#include "llvm-readobj.h"
#include "Error.h"
#include "ObjDumper.h"
+#include "WindowsResourceDumper.h"
#include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/COFFImportFile.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/MachOUniversal.h"
#include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/WindowsResource.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/DataTypes.h"
@@ -522,6 +524,15 @@
}
}
+/// @brief Dumps \a WinRes, Windows Resource (.res) file;
+static void dumpWindowsResourceFile(WindowsResource *WinRes) {
+ ScopedPrinter Printer{outs()};
+ WindowsRes::Dumper Dumper(WinRes, Printer);
+ if (auto Err = Dumper.printData())
+ reportError(WinRes->getFileName(), std::move(Err));
+}
+
+
/// @brief Opens \a File and dumps it.
static void dumpInput(StringRef File) {
@@ -540,6 +551,8 @@
dumpObject(Obj);
else if (COFFImportFile *Import = dyn_cast<COFFImportFile>(&Binary))
dumpCOFFImportFile(Import);
+ else if (WindowsResource *WinRes = dyn_cast<WindowsResource>(&Binary))
+ dumpWindowsResourceFile(WinRes);
else
reportError(File, readobj_error::unrecognized_file_format);
}