[llvm-commits] [llvm] r78952 - in /llvm/trunk: include/llvm/Support/FormattedStream.h lib/VMCore/AsmWriter.cpp
Dan Gohman
gohman at apple.com
Thu Aug 13 16:16:59 PDT 2009
Author: djg
Date: Thu Aug 13 18:16:59 2009
New Revision: 78952
URL: http://llvm.org/viewvc/llvm-project?rev=78952&view=rev
Log:
Make formatted_raw_ostream restore the buffer settings of the
underlying stream when it is finished, so that clients don't
have to do this manually.
Modified:
llvm/trunk/include/llvm/Support/FormattedStream.h
llvm/trunk/lib/VMCore/AsmWriter.cpp
Modified: llvm/trunk/include/llvm/Support/FormattedStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FormattedStream.h?rev=78952&r1=78951&r2=78952&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FormattedStream.h (original)
+++ llvm/trunk/include/llvm/Support/FormattedStream.h Thu Aug 13 18:16:59 2009
@@ -101,13 +101,11 @@
~formatted_raw_ostream() {
flush();
- if (DeleteStream)
- delete TheStream;
+ releaseStream();
}
-
+
void setStream(raw_ostream &Stream, bool Delete = false) {
- if (DeleteStream)
- delete TheStream;
+ releaseStream();
TheStream = &Stream;
DeleteStream = Delete;
@@ -118,6 +116,8 @@
// had been using, and tell TheStream not to do its own buffering.
if (size_t BufferSize = TheStream->GetBufferSize())
SetBufferSize(BufferSize);
+ else
+ SetUnbuffered();
TheStream->SetUnbuffered();
Scanned = begin();
@@ -130,6 +130,20 @@
/// recent I/O, even if the current column + minpad > newcol.
///
void PadToColumn(unsigned NewCol, unsigned MinPad = 0);
+
+ private:
+ void releaseStream() {
+ // Delete the stream if needed. Otherwise, transfer the buffer
+ // settings from this raw_ostream back to the underlying stream.
+ if (!TheStream)
+ return;
+ if (DeleteStream)
+ delete TheStream;
+ else if (size_t BufferSize = GetBufferSize())
+ TheStream->SetBufferSize(BufferSize);
+ else
+ TheStream->SetUnbuffered();
+ }
};
/// fouts() - This returns a reference to a formatted_raw_ostream for
Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=78952&r1=78951&r2=78952&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Thu Aug 13 18:16:59 2009
@@ -2005,14 +2005,9 @@
}
void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
SlotTracker SlotTable(this);
- size_t OldBufferSize = ROS.GetBufferSize();
formatted_raw_ostream OS(ROS);
AssemblyWriter W(OS, SlotTable, this, AAW);
W.write(this);
- // formatted_raw_ostream forces the underlying raw_ostream to be
- // unbuffered. Reset it to its original buffer size.
- if (OldBufferSize != 0)
- ROS.SetBufferSize(OldBufferSize);
}
void Type::print(std::ostream &o) const {
@@ -2033,7 +2028,6 @@
ROS << "printing a <null> value\n";
return;
}
- size_t OldBufferSize = ROS.GetBufferSize();
formatted_raw_ostream OS(ROS);
if (const Instruction *I = dyn_cast<Instruction>(this)) {
const Function *F = I->getParent() ? I->getParent()->getParent() : 0;
@@ -2089,10 +2083,6 @@
} else {
llvm_unreachable("Unknown value to print out!");
}
- // formatted_raw_ostream forces the underlying raw_ostream to be
- // unbuffered. Reset it to its original buffer size.
- if (OldBufferSize != 0)
- ROS.SetBufferSize(OldBufferSize);
}
void Value::print(std::ostream &O, AssemblyAnnotationWriter *AAW) const {
More information about the llvm-commits
mailing list