diff options
author | Chris Lattner <sabre@nondot.org> | 2008-08-17 04:13:37 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-08-17 04:13:37 +0000 |
commit | d3723fc8a2fd8d88b45441e217b6b0f6c8c7381f (patch) | |
tree | 614392c67af22991a2a4f9f0b75ceac96b3aab53 /llvm/lib | |
parent | 7459c86a2958207ce6785b387f5424d0d4e5d325 (diff) | |
download | bcm5719-llvm-d3723fc8a2fd8d88b45441e217b6b0f6c8c7381f.tar.gz bcm5719-llvm-d3723fc8a2fd8d88b45441e217b6b0f6c8c7381f.zip |
add support for a cout/cerr analog (outs()/errs()) as well as
a simple adaptor class to give raw output capabilities to
something that wants to write to an ostream.
llvm-svn: 54865
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/raw_ostream.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp index a4dc797f01c..96864277170 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/raw_ostream.h" +#include <ostream> using namespace llvm; #if !defined(_MSC_VER) @@ -62,6 +63,9 @@ void raw_fd_ostream::flush_impl() { HandleFlush(); } +//===----------------------------------------------------------------------===// +// raw_stdout/err_ostream +//===----------------------------------------------------------------------===// raw_stdout_ostream::raw_stdout_ostream():raw_fd_ostream(STDOUT_FILENO, false) {} raw_stderr_ostream::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false) {} @@ -69,3 +73,30 @@ raw_stderr_ostream::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false) {} // An out of line virtual method to provide a home for the class vtable. void raw_stdout_ostream::handle() {} void raw_stderr_ostream::handle() {} + +/// outs() - This returns a reference to a raw_ostream for standard output. +/// Use it like: outs() << "foo" << "bar"; +raw_ostream &outs() { + static raw_stdout_ostream S; + return S; +} + +/// errs() - This returns a reference to a raw_ostream for standard error. +/// Use it like: errs() << "foo" << "bar"; +raw_ostream &errs() { + static raw_stderr_ostream S; + return S; +} + +//===----------------------------------------------------------------------===// +// raw_os_ostream +//===----------------------------------------------------------------------===// + +/// flush_impl - The is the piece of the class that is implemented by +/// subclasses. This outputs the currently buffered data and resets the +/// buffer to empty. +void raw_os_ostream::flush_impl() { + if (OutBufCur-OutBufStart) + OS.write(OutBufStart, OutBufCur-OutBufStart); + HandleFlush(); +} |