summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-01-26 18:21:33 +0000
committerZachary Turner <zturner@google.com>2015-01-26 18:21:33 +0000
commit39571b37a38d289f0895ca060eb1d6f579300af6 (patch)
tree7110e3b78682eba2d4c67dc1864f8a4e9ddffd65 /llvm/lib/Support/raw_ostream.cpp
parent6ffc9bf6bafcb129300cac7ba333940609bf87c3 (diff)
downloadbcm5719-llvm-39571b37a38d289f0895ca060eb1d6f579300af6.tar.gz
bcm5719-llvm-39571b37a38d289f0895ca060eb1d6f579300af6.zip
Teach raw_ostream to support hex formatting without a prefix '0x'.
Previously using format_hex() would always print a 0x prior to the hex characters. This allows this to be optional, so that one can choose to print (e.g.) 255 as either 0xFF or just FF. Differential Revision: http://reviews.llvm.org/D7151 llvm-svn: 227108
Diffstat (limited to 'llvm/lib/Support/raw_ostream.cpp')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 1bcc31b40a4..aa618b9d392 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -410,9 +410,12 @@ raw_ostream &raw_ostream::operator<<(const FormattedString &FS) {
raw_ostream &raw_ostream::operator<<(const FormattedNumber &FN) {
if (FN.Hex) {
unsigned Nibbles = (64 - countLeadingZeros(FN.HexValue)+3)/4;
- unsigned Width = (FN.Width > Nibbles+2) ? FN.Width : Nibbles+2;
-
+ unsigned PrefixChars = FN.HexPrefix ? 2 : 0;
+ unsigned Width = std::max(FN.Width, Nibbles + PrefixChars);
+
char NumberBuffer[20] = "0x0000000000000000";
+ if (!FN.HexPrefix)
+ NumberBuffer[1] = '0';
char *EndPtr = NumberBuffer+Width;
char *CurPtr = EndPtr;
const char A = FN.Upper ? 'A' : 'a';
OpenPOWER on IntegriCloud