LLVM  4.0.0
ScopedPrinter.cpp
Go to the documentation of this file.
2 
4 #include "llvm/Support/Format.h"
5 #include <cctype>
6 
7 using namespace llvm::support;
8 
9 namespace llvm {
10 
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  if (Data.size() > 16)
26  Block = true;
27 
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, 0, 16, 4, (IndentLevel + 1) * 2, true)
35  << "\n";
36  startLine() << ")\n";
37  } else {
38  startLine() << Label << ":";
39  if (!Str.empty())
40  OS << " " << Str;
41  OS << " (" << format_bytes(Data, None, Data.size(), 1, 0, true) << ")\n";
42  }
43 }
44 
45 } // namespace llvm
FormattedBytes format_bytes_with_ascii(ArrayRef< uint8_t > Bytes, Optional< uint64_t > FirstByteOffset=None, uint32_t NumPerLine=16, uint8_t ByteGroupSize=4, uint32_t IndentLevel=0, bool Upper=false)
Definition: Format.h:238
FormattedBytes format_bytes(ArrayRef< uint8_t > Bytes, Optional< uint64_t > FirstByteOffset=None, uint32_t NumPerLine=16, uint8_t ByteGroupSize=4, uint32_t IndentLevel=0, bool Upper=false)
Definition: Format.h:230
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
Definition: raw_ostream.h:479
const std::string to_hexString(uint64_t Value, bool UpperCase=true)
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
Definition: Format.h:190
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1726
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:463
LLVM Value Representation.
Definition: Value.h:71
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44