[PATCH] D100833: [llvm-cvtres] Reduce the set of dependencies of llvm-cvtres. NFC.
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 21 01:50:53 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee34ca34c667: [llvm-cvtres] Reduce the set of dependencies of llvm-cvtres. NFC. (authored by mstorsjo).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100833/new/
https://reviews.llvm.org/D100833
Files:
llvm/tools/llvm-cvtres/CMakeLists.txt
llvm/tools/llvm-cvtres/llvm-cvtres.cpp
Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp
===================================================================
--- llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/WindowsMachineFlag.h"
#include "llvm/Object/WindowsResource.h"
@@ -75,6 +76,14 @@
reportError(Twine(Input) + ": " + EC.message() + ".\n");
}
+static void error(StringRef Input, Error EC) {
+ if (!EC)
+ return;
+ handleAllErrors(std::move(EC), [&](const ErrorInfoBase &EI) {
+ reportError(Twine(Input) + ": " + EI.message() + ".\n");
+ });
+}
+
static void error(Error EC) {
if (!EC)
return;
@@ -95,6 +104,16 @@
return std::move(EC.get());
}
+template <typename T> T error(StringRef Input, Expected<T> EC) {
+ if (!EC)
+ error(Input, EC.takeError());
+ return std::move(EC.get());
+}
+
+template <typename T> T error(StringRef Input, ErrorOr<T> &&EC) {
+ return error(Input, errorOrToExpected(std::move(EC)));
+}
+
int main(int Argc, const char **Argv) {
InitLLVM X(Argc, Argv);
@@ -155,15 +174,17 @@
WindowsResourceParser Parser;
for (const auto &File : InputFiles) {
- Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(File);
- if (!BinaryOrErr)
- reportError(File, errorToErrorCode(BinaryOrErr.takeError()));
-
- Binary &Binary = *BinaryOrErr.get().getBinary();
-
- WindowsResource *RF = dyn_cast<WindowsResource>(&Binary);
- if (!RF)
+ std::unique_ptr<MemoryBuffer> Buffer = error(
+ File, MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false,
+ /*RequiresNullTerminator=*/false));
+ file_magic Type = identify_magic(Buffer->getMemBufferRef().getBuffer());
+ if (Type != file_magic::windows_resource)
reportError(File + ": unrecognized file format.\n");
+ std::unique_ptr<WindowsResource> Binary = error(
+ File,
+ WindowsResource::createWindowsResource(Buffer->getMemBufferRef()));
+
+ WindowsResource *RF = Binary.get();
if (Verbose) {
int EntryNumber = 0;
@@ -199,12 +220,14 @@
error(FileBuffer->commit());
if (Verbose) {
- Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(OutputFile);
- if (!BinaryOrErr)
- reportError(OutputFile, errorToErrorCode(BinaryOrErr.takeError()));
- Binary &Binary = *BinaryOrErr.get().getBinary();
+ std::unique_ptr<MemoryBuffer> Buffer =
+ error(OutputFile,
+ MemoryBuffer::getFileOrSTDIN(OutputFile, /*IsText=*/false,
+ /*RequiresNullTerminator=*/false));
+
ScopedPrinter W(errs());
- W.printBinaryBlock("Output File Raw Data", Binary.getData());
+ W.printBinaryBlock("Output File Raw Data",
+ Buffer->getMemBufferRef().getBuffer());
}
return 0;
Index: llvm/tools/llvm-cvtres/CMakeLists.txt
===================================================================
--- llvm/tools/llvm-cvtres/CMakeLists.txt
+++ llvm/tools/llvm-cvtres/CMakeLists.txt
@@ -1,4 +1,5 @@
set(LLVM_LINK_COMPONENTS
+ BinaryFormat
Object
Option
Support
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100833.339140.patch
Type: text/x-patch
Size: 3283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210421/7d21ded4/attachment.bin>
More information about the llvm-commits
mailing list