aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
diff options
context:
space:
mode:
authorSeiya Nuta <nuta@seiya.me>2019-06-25 00:02:04 +0000
committerSeiya Nuta <nuta@seiya.me>2019-06-25 00:02:04 +0000
commit545f001d1b9a7b58a68d75e70bfc36c841de8999 (patch)
tree1b673409a65874c1611e89ba852379e90acfda51 /llvm/tools/llvm-objcopy/llvm-objcopy.cpp
parentf895e1bded031fb503bd12ad25d7139d6a6ee6c0 (diff)
downloadllvm-545f001d1b9a7b58a68d75e70bfc36c841de8999.zip
llvm-545f001d1b9a7b58a68d75e70bfc36c841de8999.tar.gz
llvm-545f001d1b9a7b58a68d75e70bfc36c841de8999.tar.bz2
[llvm-objcopy][NFC] Refactor output target parsing
Summary: Use an enum instead of string to hold the output file format in Config.InputFormat and Config.OutputFormat. It's essential to support other output file formats other than ELF. Reviewers: espindola, alexshap, rupprecht, jhenderson Reviewed By: rupprecht, jhenderson Subscribers: jyknight, compnerd, emaste, arichardson, fedor.sergeev, jakehehrlich, MaskRay, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63239 llvm-svn: 364254
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 2ab77ea..44e0220 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -140,11 +140,16 @@ static Error executeObjcopyOnIHex(const CopyConfig &Config, MemoryBuffer &In,
/// of the output specified by the command line options.
static Error executeObjcopyOnRawBinary(const CopyConfig &Config,
MemoryBuffer &In, Buffer &Out) {
- // TODO: llvm-objcopy should parse CopyConfig.OutputFormat to recognize
- // formats other than ELF / "binary" and invoke
- // elf::executeObjcopyOnRawBinary, macho::executeObjcopyOnRawBinary or
- // coff::executeObjcopyOnRawBinary accordingly.
- return elf::executeObjcopyOnRawBinary(Config, In, Out);
+ switch (Config.OutputFormat) {
+ case FileFormat::ELF:
+ // FIXME: Currently, we call elf::executeObjcopyOnRawBinary even if the
+ // output format is binary/ihex or it's not given. This behavior differs from
+ // GNU objcopy. See https://bugs.llvm.org/show_bug.cgi?id=42171 for details.
+ case FileFormat::Binary:
+ case FileFormat::IHex:
+ case FileFormat::Unspecified:
+ return elf::executeObjcopyOnRawBinary(Config, In, Out);
+ }
}
/// The function executeObjcopyOnBinary does the dispatch based on the format
@@ -224,10 +229,17 @@ static Error executeObjcopy(const CopyConfig &Config) {
return createFileError(Config.InputFilename, EC);
typedef Error (*ProcessRawFn)(const CopyConfig &, MemoryBuffer &, Buffer &);
- auto ProcessRaw = StringSwitch<ProcessRawFn>(Config.InputFormat)
- .Case("binary", executeObjcopyOnRawBinary)
- .Case("ihex", executeObjcopyOnIHex)
- .Default(nullptr);
+ ProcessRawFn ProcessRaw;
+ switch (Config.InputFormat) {
+ case FileFormat::Binary:
+ ProcessRaw = executeObjcopyOnRawBinary;
+ break;
+ case FileFormat::IHex:
+ ProcessRaw = executeObjcopyOnIHex;
+ break;
+ default:
+ ProcessRaw = nullptr;
+ }
if (ProcessRaw) {
auto BufOrErr = MemoryBuffer::getFileOrSTDIN(Config.InputFilename);