[llvm-commits] [llvm] r54972 - /llvm/trunk/include/llvm/Support/raw_ostream.h

Chris Lattner sabre at nondot.org
Mon Aug 18 21:23:04 PDT 2008


Author: lattner
Date: Mon Aug 18 23:23:02 2008
New Revision: 54972

URL: http://llvm.org/viewvc/llvm-project?rev=54972&view=rev
Log:
add raw_ostream method for emitting an unsigned.

Modified:
    llvm/trunk/include/llvm/Support/raw_ostream.h

Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=54972&r1=54971&r2=54972&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Mon Aug 18 23:23:02 2008
@@ -72,6 +72,23 @@
     return write(Str, strlen(Str));
   }
   
+  raw_ostream &operator<<(unsigned N) {
+    // Zero is a special case.
+    if (N == 0)
+      return *this << '0';
+    
+    char NumberBuffer[20];
+    char *EndPtr = NumberBuffer+sizeof(NumberBuffer);
+    char *CurPtr = EndPtr;
+    
+    while (N) {
+      *--CurPtr = '0' + char(N % 10);
+      N /= 10;
+    }
+    return write(CurPtr, EndPtr-CurPtr);
+  }
+  
+  
   raw_ostream &write(const char *Ptr, unsigned Size) {
     if (OutBufCur+Size > OutBufEnd)
       flush_impl();





More information about the llvm-commits mailing list