mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[llvm-cvtres] Reduce the set of dependencies of llvm-cvtres. NFC.
Don't use createBinary() but call the WindowsResource class directly. The createBinary() function references all supported object file types and ends up pulling way more from all the underlying libraries than what is necessary. This shrinks a stripped llvm-cvtres from 4.6 MB to 463 KB. Differential Revision: https://reviews.llvm.org/D100833
This commit is contained in:
parent
081c5cd9a4
commit
09f1330345
@ -1,4 +1,5 @@
|
||||
set(LLVM_LINK_COMPONENTS
|
||||
BinaryFormat
|
||||
Object
|
||||
Option
|
||||
Support
|
||||
|
@ -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 @@ static void reportError(StringRef Input, std::error_code EC) {
|
||||
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 @@ template <typename T> T error(Expected<T> EC) {
|
||||
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 @@ int main(int Argc, const char **Argv) {
|
||||
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 @@ int main(int Argc, const char **Argv) {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user