Add raw_null_ostream and llvm::nulls(), a raw_ostream that discards output.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 16 Jul 2009 21:17:53 +0000 (21:17 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 16 Jul 2009 21:17:53 +0000 (21:17 +0000)
 - No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76103 91177308-0d34-0410-b5e6-96231b3b80d8

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

index aeeb7e3abc4e76e8c50522c4c669e28a82464c10..4c7338eac4c1b831a2afd916db5611a3306320ad 100644 (file)
@@ -327,6 +327,9 @@ raw_ostream &outs();
 /// Use it like: errs() << "foo" << "bar";
 raw_ostream &errs();
 
+/// nulls() - This returns a reference to a raw_ostream which simply discards
+/// output.
+raw_ostream &nulls();
 
 //===----------------------------------------------------------------------===//
 // Output Stream Adaptors
@@ -399,6 +402,19 @@ public:
   uint64_t tell();
 };
 
+/// raw_null_ostream - A raw_ostream that discards all output.
+class raw_null_ostream : public raw_ostream {
+  /// write_impl - See raw_ostream::write_impl.
+  virtual void write_impl(const char *Ptr, size_t size);
+  
+  /// current_pos - Return the current position within the stream, not
+  /// counting the bytes currently in the buffer.
+  virtual uint64_t current_pos();
+
+public:
+  explicit raw_null_ostream() {}
+};
+
 } // end llvm namespace
 
 #endif
index 397d2967c22c22b5f06f32a8d5087c9afaac32cf..3cec18b442ecf5b8ff38fa59a0edb604684ff5ef 100644 (file)
@@ -375,6 +375,12 @@ raw_ostream &llvm::errs() {
   return S;
 }
 
+/// nulls() - This returns a reference to a raw_ostream which discards output.
+raw_ostream &llvm::nulls() {
+  static raw_null_ostream S;
+  return S;
+}
+
 //===----------------------------------------------------------------------===//
 //  raw_os_ostream
 //===----------------------------------------------------------------------===//
@@ -422,3 +428,14 @@ uint64_t raw_svector_ostream::current_pos() { return OS.size(); }
 uint64_t raw_svector_ostream::tell() { 
   return OS.size() + GetNumBytesInBuffer(); 
 }
+
+//===----------------------------------------------------------------------===//
+//  raw_null_ostream
+//===----------------------------------------------------------------------===//
+
+void raw_null_ostream::write_impl(const char *Ptr, size_t Size) {
+}
+
+uint64_t raw_null_ostream::current_pos() {
+  return 0;
+}