Add raw_ostream::write_hex
authorDaniel Dunbar <daniel@zuster.org>
Thu, 30 Jul 2009 18:21:23 +0000 (18:21 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 30 Jul 2009 18:21:23 +0000 (18:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77614 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/raw_ostream.h
lib/Support/raw_ostream.cpp

index c8744d2dd3dcd9d78ad325dec7c9b9ab382f4e48..09ee03098f49df0de07594f64250f25e018c55f9 100644 (file)
@@ -198,6 +198,9 @@ public:
     return *this;
   }
 
+  /// write_hex - Output \arg N in hexadecimal, without any prefix or padding.
+  raw_ostream &write_hex(unsigned long long N);
+
   raw_ostream &write(unsigned char C);
   raw_ostream &write(const char *Ptr, size_t Size);
 
index 20e50efd2cc69b729fbefe02f1fde1f414e4008e..e3ab0c688a333feedf82c47962ab65233da3a05d 100644 (file)
@@ -113,10 +113,7 @@ raw_ostream &raw_ostream::operator<<(long long N) {
   return this->operator<<(static_cast<unsigned long long>(N));
 }
 
-raw_ostream &raw_ostream::operator<<(const void *P) {
-  uintptr_t N = (uintptr_t) P;
-  *this << '0' << 'x';
-  
+raw_ostream &raw_ostream::write_hex(unsigned long long N) {
   // Zero is a special case.
   if (N == 0)
     return *this << '0';
@@ -134,6 +131,12 @@ raw_ostream &raw_ostream::operator<<(const void *P) {
   return write(CurPtr, EndPtr-CurPtr);
 }
 
+raw_ostream &raw_ostream::operator<<(const void *P) {
+  *this << '0' << 'x';
+
+  return write_hex((uintptr_t) P);
+}
+
 void raw_ostream::flush_nonempty() {
   assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty.");
   write_impl(OutBufStart, OutBufCur - OutBufStart);