blob: d8ee1efd8f3e6934932e1aa1b6f9bafc47abfa49 [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/ADT/StringExtras.h"
4#include "llvm/Support/Format.h"
5#include <cctype>
6
7using namespace llvm::support;
8
9namespace llvm {
10
Zachary Turner88bb1632016-05-03 00:28:04 +000011raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value) {
Hemant Kulkarnid8a985e2016-02-10 20:40:55 +000012 OS << "0x" << to_hexString(Value.Value);
13 return OS;
14}
Eric Christopher9cad53c2013-04-03 18:31:38 +000015
Hemant Kulkarnid8a985e2016-02-10 20:40:55 +000016const 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}
Eric Christopher9cad53c2013-04-03 18:31:38 +000022
Zachary Turner88bb1632016-05-03 00:28:04 +000023void ScopedPrinter::printBinaryImpl(StringRef Label, StringRef Str,
24 ArrayRef<uint8_t> Data, bool Block) {
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())
34 OS << format_bytes_with_ascii(Data, 0, 16, 4, (IndentLevel + 1) * 2, true)
35 << "\n";
Eric Christopher9cad53c2013-04-03 18:31:38 +000036 startLine() << ")\n";
37 } else {
38 startLine() << Label << ":";
Zachary Turner4a86af02016-11-10 20:16:45 +000039 if (!Str.empty())
Eric Christopher9cad53c2013-04-03 18:31:38 +000040 OS << " " << Str;
Zachary Turner4a86af02016-11-10 20:16:45 +000041 OS << " (" << format_bytes(Data, None, Data.size(), 1, 0, true) << ")\n";
Eric Christopher9cad53c2013-04-03 18:31:38 +000042 }
43}
44
45} // namespace llvm