diff options
| author | Zachary Turner <zturner@google.com> | 2016-11-10 20:16:45 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2016-11-10 20:16:45 +0000 |
| commit | 4a86af07a23a7a8ce0b8f41b912c4e77bbb984d0 (patch) | |
| tree | f52e225f81c1fbd84370a9adb0a3c50b7f1c1b45 /llvm/lib/Support/ScopedPrinter.cpp | |
| parent | 811cdc979b1c51659887e1af7ba72a6f0adcac0b (diff) | |
| download | bcm5719-llvm-4a86af07a23a7a8ce0b8f41b912c4e77bbb984d0.tar.gz bcm5719-llvm-4a86af07a23a7a8ce0b8f41b912c4e77bbb984d0.zip | |
[Support] Improve flexibility of binary blob formatter.
This makes it possible to indent a binary blob by a certain
number of bytes, and also makes some things more idiomatic.
Finally, it integrates this binary blob formatter into ScopedPrinter
which used to have its own implementation of this algorithm.
Differential Revision: https://reviews.llvm.org/D26477
llvm-svn: 286495
Diffstat (limited to 'llvm/lib/Support/ScopedPrinter.cpp')
| -rw-r--r-- | llvm/lib/Support/ScopedPrinter.cpp | 39 |
1 files changed, 6 insertions, 33 deletions
diff --git a/llvm/lib/Support/ScopedPrinter.cpp b/llvm/lib/Support/ScopedPrinter.cpp index 0225f01156a..d8ee1efd8f3 100644 --- a/llvm/lib/Support/ScopedPrinter.cpp +++ b/llvm/lib/Support/ScopedPrinter.cpp @@ -27,45 +27,18 @@ void ScopedPrinter::printBinaryImpl(StringRef Label, StringRef Str, if (Block) { startLine() << Label; - if (Str.size() > 0) + if (!Str.empty()) OS << ": " << Str; OS << " (\n"; - for (size_t addr = 0, end = Data.size(); addr < end; addr += 16) { - startLine() << format(" %04" PRIX64 ": ", uint64_t(addr)); - // Dump line of hex. - for (size_t i = 0; i < 16; ++i) { - if (i != 0 && i % 4 == 0) - OS << ' '; - if (addr + i < end) - OS << hexdigit((Data[addr + i] >> 4) & 0xF, false) - << hexdigit(Data[addr + i] & 0xF, false); - else - OS << " "; - } - // Print ascii. - OS << " |"; - for (std::size_t i = 0; i < 16 && addr + i < end; ++i) { - if (std::isprint(Data[addr + i] & 0xFF)) - OS << Data[addr + i]; - else - OS << "."; - } - OS << "|\n"; - } - + if (!Data.empty()) + OS << format_bytes_with_ascii(Data, 0, 16, 4, (IndentLevel + 1) * 2, true) + << "\n"; startLine() << ")\n"; } else { startLine() << Label << ":"; - if (Str.size() > 0) + if (!Str.empty()) OS << " " << Str; - OS << " ("; - for (size_t i = 0; i < Data.size(); ++i) { - if (i > 0) - OS << " "; - - OS << format("%02X", static_cast<int>(Data[i])); - } - OS << ")\n"; + OS << " (" << format_bytes(Data, None, Data.size(), 1, 0, true) << ")\n"; } } |

