aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Support/raw_ostream.h22
-rw-r--r--lib/Support/raw_ostream.cpp6
2 files changed, 23 insertions, 5 deletions
diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h
index 84fef39..0f1bee3 100644
--- a/include/llvm/Support/raw_ostream.h
+++ b/include/llvm/Support/raw_ostream.h
@@ -32,8 +32,10 @@ namespace llvm {
class raw_ostream {
protected:
char *OutBufStart, *OutBufEnd, *OutBufCur;
+ bool Unbuffered;
+
public:
- raw_ostream() {
+ raw_ostream(bool unbuffered=false) : Unbuffered(unbuffered) {
// Start out ready to flush.
OutBufStart = OutBufEnd = OutBufCur = 0;
}
@@ -59,6 +61,16 @@ public:
OutBufCur = OutBufStart;
}
+ /// SetUnbuffered - Set the streams buffering status. When
+ /// unbuffered the stream will flush after every write. This routine
+ /// will also flush the buffer immediately when the stream is being
+ /// set to unbuffered.
+ void SetUnbuffered(bool unbuffered) {
+ Unbuffered = unbuffered;
+ if (Unbuffered)
+ flush();
+ }
+
//===--------------------------------------------------------------------===//
// Data Output Interface
//===--------------------------------------------------------------------===//
@@ -165,9 +177,11 @@ public:
raw_fd_ostream(const char *Filename, bool Binary, std::string &ErrorInfo);
/// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
- /// ShouldClose is true, this closes the file when
- raw_fd_ostream(int fd, bool shouldClose) : FD(fd), ShouldClose(shouldClose) {}
-
+ /// ShouldClose is true, this closes the file when the stream is destroyed.
+ raw_fd_ostream(int fd, bool shouldClose,
+ bool unbuffered=false) : raw_ostream(unbuffered), FD(fd),
+ ShouldClose(shouldClose) {}
+
~raw_fd_ostream();
/// flush_impl - The is the piece of the class that is implemented by
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 29665dc..5a99a0c 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -141,6 +141,9 @@ raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
break;
}
OutBufCur += Size;
+
+ if (Unbuffered)
+ flush_impl();
return *this;
}
@@ -266,7 +269,8 @@ uint64_t raw_fd_ostream::seek(uint64_t off) {
//===----------------------------------------------------------------------===//
raw_stdout_ostream::raw_stdout_ostream():raw_fd_ostream(STDOUT_FILENO, false) {}
-raw_stderr_ostream::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false) {}
+raw_stderr_ostream::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false,
+ true) {}
// An out of line virtual method to provide a home for the class vtable.
void raw_stdout_ostream::handle() {}