blob: 981dfbff520a1282da4af08f7b8480c618f1817d [file] [log] [blame]
Zachary Turner88bb1632016-05-03 00:28:04 +00001#include "llvm/Support/ScopedPrinter.h"
2
Eric Christopher9cad53c2013-04-03 18:31:38 +00003#include "llvm/Support/Format.h"
4#include <cctype>
5
6using namespace llvm::support;
7
8namespace llvm {
9
Zachary Turner88bb1632016-05-03 00:28:04 +000010raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value) {
Hemant Kulkarnid8a985e2016-02-10 20:40:55 +000011 OS << "0x" << to_hexString(Value.Value);
12 return OS;
13}
Eric Christopher9cad53c2013-04-03 18:31:38 +000014
Hemant Kulkarnid8a985e2016-02-10 20:40:55 +000015const 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();
20}
Eric Christopher9cad53c2013-04-03 18:31:38 +000021
Zachary Turner88bb1632016-05-03 00:28:04 +000022void ScopedPrinter::printBinaryImpl(StringRef Label, StringRef Str,
Zachary Turner7159ab92017-04-28 00:43:38 +000023 ArrayRef<uint8_t> Data, bool Block,
24 uint32_t StartOffset) {
Eric Christopher9cad53c2013-04-03 18:31:38 +000025 if (Data.size() > 16)
26 Block = true;
27
28 if (Block) {
29 startLine() << Label;
Zachary Turner4a86af02016-11-10 20:16:45 +000030 if (!Str.empty())
Eric Christopher9cad53c2013-04-03 18:31:38 +000031 OS << ": " << Str;
32 OS << " (\n";
Zachary Turner4a86af02016-11-10 20:16:45 +000033 if (!Data.empty())
Zachary Turner7159ab92017-04-28 00:43:38 +000034 OS << format_bytes_with_ascii(Data, StartOffset, 16, 4,
35 (IndentLevel + 1) * 2, true)
Zachary Turner4a86af02016-11-10 20:16:45 +000036 << "\n";
Eric Christopher9cad53c2013-04-03 18:31:38 +000037 startLine() << ")\n";
38 } else {
39 startLine() << Label << ":";
Zachary Turner4a86af02016-11-10 20:16:45 +000040 if (!Str.empty())
Eric Christopher9cad53c2013-04-03 18:31:38 +000041 OS << " " << Str;
Zachary Turner4a86af02016-11-10 20:16:45 +000042 OS << " (" << format_bytes(Data, None, Data.size(), 1, 0, true) << ")\n";
Eric Christopher9cad53c2013-04-03 18:31:38 +000043 }
44}
45
46} // namespace llvm