Any function that can log things should be able to easily log them to a memory buffer as well
https://bugs.webkit.org/show_bug.cgi?id=103000
Reviewed by Sam Weinig.
Source/JavaScriptCore:
Change all users of WTF::dataFile() to expect a PrintStream& rather than a FILE*.
* bytecode/Operands.h:
(JSC::OperandValueTraits::dump):
(JSC::dumpOperands):
(JSC):
* dfg/DFGAbstractState.cpp:
(JSC::DFG::AbstractState::dump):
* dfg/DFGAbstractState.h:
(AbstractState):
* dfg/DFGAbstractValue.h:
(JSC::DFG::AbstractValue::dump):
* dfg/DFGCommon.h:
(JSC::DFG::NodeIndexTraits::dump):
* dfg/DFGStructureAbstractValue.h:
(JSC::DFG::StructureAbstractValue::dump):
* dfg/DFGVariableEvent.cpp:
(JSC::DFG::VariableEvent::dump):
(JSC::DFG::VariableEvent::dumpFillInfo):
(JSC::DFG::VariableEvent::dumpSpillInfo):
* dfg/DFGVariableEvent.h:
(VariableEvent):
* disassembler/Disassembler.h:
(JSC):
(JSC::tryToDisassemble):
* disassembler/UDis86Disassembler.cpp:
(JSC::tryToDisassemble):
Source/WTF:
We have a number of places where we pass around a FILE* as a target to which to print
some logging information. But the purpose of passing FILE* instead of always assuming
that we should dump to stderr is that it may be sometimes useful to send the logging
information elsewhere. Unfortunately, FILE* isn't quite powerful enough: it's combersome
to use it to send logging to a string, for example.
We could get around this by using <iostream> and <sstream>, but so far this aspect of
C++ has not been part of the WebKit coding conventions. Personally I find <iostream>
awkward due to its abuse of operator overloading.
So this patch introduces the PrintStream abstract class, which offers printf-like
functionality while completely abstracting the destination and mechanism of the printing
output. It would be trivial to implement a StringPrintStream, for example. This will feed
into work on https://bugs.webkit.org/show_bug.cgi?id=102999.
This also sets us up for creating templatized print() and println() methods that will
allow us to say things like out.print("count = ", count, "\n"), but that is the topic
of https://bugs.webkit.org/show_bug.cgi?id=103009.
This patch also changes dataLog() to use FilePrintStream internally, and WTF::dataFile()
now returns a FilePrintStream&. Any previous users of WTF::dataFile() have been changed
to expect a PrintStream&.
* GNUmakefile.list.am:
* WTF.pro:
* WTF.vcproj/WTF.vcproj:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/DataLog.cpp:
(WTF):
(WTF::initializeLogFileOnce):
(WTF::initializeLogFile):
(WTF::dataFile):
(WTF::dataLogV):
(WTF::dataLogString):
* wtf/DataLog.h:
(WTF):
* wtf/FilePrintStream.cpp: Added.
(WTF):
(WTF::FilePrintStream::FilePrintStream):
(WTF::FilePrintStream::~FilePrintStream):
(WTF::FilePrintStream::vprintf):
(WTF::FilePrintStream::flush):
* wtf/FilePrintStream.h: Added.
(WTF):
(FilePrintStream):
(WTF::FilePrintStream::file):
* wtf/PrintStream.cpp: Added.
(WTF):
(WTF::PrintStream::PrintStream):
(WTF::PrintStream::~PrintStream):
(WTF::PrintStream::printf):
(WTF::PrintStream::print):
(WTF::PrintStream::println):
(WTF::PrintStream::flush):
(WTF::print):
* wtf/PrintStream.h: Added.
(WTF):
(PrintStream):
(WTF::print):
(WTF::println):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@135640 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/dfg/DFGVariableEvent.cpp b/Source/JavaScriptCore/dfg/DFGVariableEvent.cpp
index 3e84a6b..8ea568b 100644
--- a/Source/JavaScriptCore/dfg/DFGVariableEvent.cpp
+++ b/Source/JavaScriptCore/dfg/DFGVariableEvent.cpp
@@ -33,11 +33,11 @@
namespace JSC { namespace DFG {
-void VariableEvent::dump(FILE* out) const
+void VariableEvent::dump(PrintStream& out) const
{
switch (kind()) {
case Reset:
- fprintf(out, "Reset");
+ out.printf("Reset");
break;
case BirthToFill:
dumpFillInfo("BirthToFill", out);
@@ -52,13 +52,13 @@
dumpSpillInfo("Spill", out);
break;
case Death:
- fprintf(out, "Death(@%u)", nodeIndex());
+ out.printf("Death(@%u)", nodeIndex());
break;
case MovHint:
- fprintf(out, "MovHint(@%u, r%d)", nodeIndex(), operand());
+ out.printf("MovHint(@%u, r%d)", nodeIndex(), operand());
break;
case SetLocalEvent:
- fprintf(out, "SetLocal(r%d, %s)", operand(), dataFormatToString(dataFormat()));
+ out.printf("SetLocal(r%d, %s)", operand(), dataFormatToString(dataFormat()));
break;
default:
ASSERT_NOT_REACHED();
@@ -66,23 +66,23 @@
}
}
-void VariableEvent::dumpFillInfo(const char* name, FILE* out) const
+void VariableEvent::dumpFillInfo(const char* name, PrintStream& out) const
{
- fprintf(out, "%s(@%u, ", name, nodeIndex());
+ out.printf("%s(@%u, ", name, nodeIndex());
if (dataFormat() == DataFormatDouble)
- fprintf(out, "%s", FPRInfo::debugName(fpr()));
+ out.printf("%s", FPRInfo::debugName(fpr()));
#if USE(JSVALUE32_64)
else if (dataFormat() & DataFormatJS)
- fprintf(out, "%s:%s", GPRInfo::debugName(tagGPR()), GPRInfo::debugName(payloadGPR()));
+ out.printf("%s:%s", GPRInfo::debugName(tagGPR()), GPRInfo::debugName(payloadGPR()));
#endif
else
- fprintf(out, "%s", GPRInfo::debugName(gpr()));
- fprintf(out, ", %s)", dataFormatToString(dataFormat()));
+ out.printf("%s", GPRInfo::debugName(gpr()));
+ out.printf(", %s)", dataFormatToString(dataFormat()));
}
-void VariableEvent::dumpSpillInfo(const char* name, FILE* out) const
+void VariableEvent::dumpSpillInfo(const char* name, PrintStream& out) const
{
- fprintf(out, "%s(@%u, r%d, %s)", name, nodeIndex(), virtualRegister(), dataFormatToString(dataFormat()));
+ out.printf("%s(@%u, r%d, %s)", name, nodeIndex(), virtualRegister(), dataFormatToString(dataFormat()));
}
} } // namespace JSC::DFG