2016-05-03 08:28:04 +08:00
|
|
|
#include "llvm/Support/ScopedPrinter.h"
|
|
|
|
|
2013-04-04 02:31:38 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include <cctype>
|
|
|
|
|
|
|
|
using namespace llvm::support;
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2016-05-03 08:28:04 +08:00
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value) {
|
2016-02-11 04:40:55 +08:00
|
|
|
OS << "0x" << to_hexString(Value.Value);
|
|
|
|
return OS;
|
|
|
|
}
|
2016-02-11 02:21:01 +08:00
|
|
|
|
2021-02-04 12:41:16 +08:00
|
|
|
std::string to_hexString(uint64_t Value, bool UpperCase) {
|
2016-02-11 04:40:55 +08:00
|
|
|
std::string number;
|
|
|
|
llvm::raw_string_ostream stream(number);
|
|
|
|
stream << format_hex_no_prefix(Value, 1, UpperCase);
|
|
|
|
return stream.str();
|
|
|
|
}
|
2013-04-04 02:31:38 +08:00
|
|
|
|
2016-05-03 08:28:04 +08:00
|
|
|
void ScopedPrinter::printBinaryImpl(StringRef Label, StringRef Str,
|
2017-04-28 08:43:38 +08:00
|
|
|
ArrayRef<uint8_t> Data, bool Block,
|
|
|
|
uint32_t StartOffset) {
|
2013-04-04 02:31:38 +08:00
|
|
|
if (Data.size() > 16)
|
|
|
|
Block = true;
|
|
|
|
|
|
|
|
if (Block) {
|
|
|
|
startLine() << Label;
|
2016-11-11 04:16:45 +08:00
|
|
|
if (!Str.empty())
|
2013-04-04 02:31:38 +08:00
|
|
|
OS << ": " << Str;
|
|
|
|
OS << " (\n";
|
2016-11-11 04:16:45 +08:00
|
|
|
if (!Data.empty())
|
2017-04-28 08:43:38 +08:00
|
|
|
OS << format_bytes_with_ascii(Data, StartOffset, 16, 4,
|
|
|
|
(IndentLevel + 1) * 2, true)
|
2016-11-11 04:16:45 +08:00
|
|
|
<< "\n";
|
2013-04-04 02:31:38 +08:00
|
|
|
startLine() << ")\n";
|
|
|
|
} else {
|
|
|
|
startLine() << Label << ":";
|
2016-11-11 04:16:45 +08:00
|
|
|
if (!Str.empty())
|
2013-04-04 02:31:38 +08:00
|
|
|
OS << " " << Str;
|
2016-11-11 04:16:45 +08:00
|
|
|
OS << " (" << format_bytes(Data, None, Data.size(), 1, 0, true) << ")\n";
|
2013-04-04 02:31:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace llvm
|