aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-10-17 20:57:45 +0000
committerZachary Turner <zturner@google.com>2016-10-17 20:57:45 +0000
commit99eef2d736bd4cbfef02eb8714a59db442ff8643 (patch)
treece9cb58bf9ed8e9020ff8590aa6255c346bcdd92 /llvm/lib/Support/raw_ostream.cpp
parent523cd8290a68821124de2fe52240c1c1f1439895 (diff)
downloadllvm-99eef2d736bd4cbfef02eb8714a59db442ff8643.zip
llvm-99eef2d736bd4cbfef02eb8714a59db442ff8643.tar.gz
llvm-99eef2d736bd4cbfef02eb8714a59db442ff8643.tar.bz2
[Support] Add support for "advanced" number formatting.
raw_ostream has not afforded a lot of flexibility in terms of how to format numbers when outputting. Wrap this all up into a set of low level helper functions that can be used to output numbers with arbitrary precision, alignment, format, etc and then update raw_ostream to use these functions. This will be useful for upcoming improvements to llvm's string formatting libraries, but are still useful independently. Differential Revision: https://reviews.llvm.org/D25497 llvm-svn: 284425
Diffstat (limited to 'llvm/lib/Support/raw_ostream.cpp')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 8101bc1..b040e0a 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -114,27 +114,27 @@ void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size,
}
raw_ostream &raw_ostream::operator<<(unsigned long N) {
- write_ulong(*this, N, 0);
+ write_ulong(*this, N, IntegerStyle::Integer);
return *this;
}
raw_ostream &raw_ostream::operator<<(long N) {
- write_long(*this, N, 0);
+ write_long(*this, N, IntegerStyle::Integer);
return *this;
}
raw_ostream &raw_ostream::operator<<(unsigned long long N) {
- write_ulonglong(*this, N, 0);
+ write_ulonglong(*this, N, IntegerStyle::Integer);
return *this;
}
raw_ostream &raw_ostream::operator<<(long long N) {
- write_longlong(*this, N, 0);
+ write_longlong(*this, N, IntegerStyle::Integer);
return *this;
}
raw_ostream &raw_ostream::write_hex(unsigned long long N) {
- llvm::write_hex(*this, N, 0, false, false);
+ llvm::write_hex(*this, N, HexStyle::Lower);
return *this;
}
@@ -179,12 +179,12 @@ raw_ostream &raw_ostream::write_escaped(StringRef Str,
}
raw_ostream &raw_ostream::operator<<(const void *P) {
- llvm::write_hex(*this, (uintptr_t)P, 0, false, true);
+ llvm::write_hex(*this, (uintptr_t)P, HexStyle::PrefixLower);
return *this;
}
raw_ostream &raw_ostream::operator<<(double N) {
- llvm::write_double(*this, N, 0, 0, FloatStyle::Exponent);
+ llvm::write_double(*this, N, FloatStyle::Exponent);
return *this;
}
@@ -331,9 +331,19 @@ raw_ostream &raw_ostream::operator<<(const FormattedString &FS) {
raw_ostream &raw_ostream::operator<<(const FormattedNumber &FN) {
if (FN.Hex) {
- llvm::write_hex(*this, FN.HexValue, FN.Width, FN.Upper, FN.HexPrefix);
+ HexStyle Style;
+ if (FN.Upper && FN.HexPrefix)
+ Style = HexStyle::PrefixUpper;
+ else if (FN.Upper && !FN.HexPrefix)
+ Style = HexStyle::Upper;
+ else if (!FN.Upper && FN.HexPrefix)
+ Style = HexStyle::PrefixLower;
+ else
+ Style = HexStyle::Lower;
+ llvm::write_hex(*this, FN.HexValue, Style, FN.Width, None);
} else {
- llvm::write_longlong(*this, FN.DecValue, FN.Width);
+ llvm::write_longlong(*this, FN.DecValue, IntegerStyle::Integer, None,
+ FN.Width);
}
return *this;
}