add raw_ostream method for emitting an unsigned.
authorChris Lattner <sabre@nondot.org>
Tue, 19 Aug 2008 04:23:02 +0000 (04:23 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 19 Aug 2008 04:23:02 +0000 (04:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54972 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/raw_ostream.h

index fc73bab06b22eacab2e9e451af14461e084d39a2..16945200846e03779ba57893c7d7014852b1761a 100644 (file)
@@ -72,6 +72,23 @@ public:
     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();