[llvm-exegesis] [NFC] Fixing typo.
[llvm-complete.git] / lib / Support / ScopedPrinter.cpp
blob981dfbff520a1282da4af08f7b8480c618f1817d
1 #include "llvm/Support/ScopedPrinter.h"
3 #include "llvm/Support/Format.h"
4 #include <cctype>
6 using namespace llvm::support;
8 namespace llvm {
10 raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value) {
11 OS << "0x" << to_hexString(Value.Value);
12 return OS;
15 const std::string to_hexString(uint64_t Value, bool UpperCase) {
16 std::string number;
17 llvm::raw_string_ostream stream(number);
18 stream << format_hex_no_prefix(Value, 1, UpperCase);
19 return stream.str();
22 void ScopedPrinter::printBinaryImpl(StringRef Label, StringRef Str,
23 ArrayRef<uint8_t> Data, bool Block,
24 uint32_t StartOffset) {
25 if (Data.size() > 16)
26 Block = true;
28 if (Block) {
29 startLine() << Label;
30 if (!Str.empty())
31 OS << ": " << Str;
32 OS << " (\n";
33 if (!Data.empty())
34 OS << format_bytes_with_ascii(Data, StartOffset, 16, 4,
35 (IndentLevel + 1) * 2, true)
36 << "\n";
37 startLine() << ")\n";
38 } else {
39 startLine() << Label << ":";
40 if (!Str.empty())
41 OS << " " << Str;
42 OS << " (" << format_bytes(Data, None, Data.size(), 1, 0, true) << ")\n";
46 } // namespace llvm