]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Support/ScopedPrinter.cpp
MFhead@r325422
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Support / ScopedPrinter.cpp
1 #include "llvm/Support/ScopedPrinter.h"
2
3 #include "llvm/ADT/StringExtras.h"
4 #include "llvm/Support/Format.h"
5 #include <cctype>
6
7 using namespace llvm::support;
8
9 namespace llvm {
10
11 raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value) {
12   OS << "0x" << to_hexString(Value.Value);
13   return OS;
14 }
15
16 const std::string to_hexString(uint64_t Value, bool UpperCase) {
17   std::string number;
18   llvm::raw_string_ostream stream(number);
19   stream << format_hex_no_prefix(Value, 1, UpperCase);
20   return stream.str();
21 }
22
23 void ScopedPrinter::printBinaryImpl(StringRef Label, StringRef Str,
24                                     ArrayRef<uint8_t> Data, bool Block,
25                                     uint32_t StartOffset) {
26   if (Data.size() > 16)
27     Block = true;
28
29   if (Block) {
30     startLine() << Label;
31     if (!Str.empty())
32       OS << ": " << Str;
33     OS << " (\n";
34     if (!Data.empty())
35       OS << format_bytes_with_ascii(Data, StartOffset, 16, 4,
36                                     (IndentLevel + 1) * 2, true)
37          << "\n";
38     startLine() << ")\n";
39   } else {
40     startLine() << Label << ":";
41     if (!Str.empty())
42       OS << " " << Str;
43     OS << " (" << format_bytes(Data, None, Data.size(), 1, 0, true) << ")\n";
44   }
45 }
46
47 } // namespace llvm