Ignore:
Timestamp:
Nov 23, 2012, 7:16:47 PM (13 years ago)
Author:
[email protected]
Message:

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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/dfg/DFGVariableEvent.cpp

    r121717 r135640  
    3434namespace JSC { namespace DFG {
    3535
    36 void VariableEvent::dump(FILE* out) const
     36void VariableEvent::dump(PrintStream& out) const
    3737{
    3838    switch (kind()) {
    3939    case Reset:
    40         fprintf(out, "Reset");
     40        out.printf("Reset");
    4141        break;
    4242    case BirthToFill:
     
    5353        break;
    5454    case Death:
    55         fprintf(out, "Death(@%u)", nodeIndex());
     55        out.printf("Death(@%u)", nodeIndex());
    5656        break;
    5757    case MovHint:
    58         fprintf(out, "MovHint(@%u, r%d)", nodeIndex(), operand());
     58        out.printf("MovHint(@%u, r%d)", nodeIndex(), operand());
    5959        break;
    6060    case SetLocalEvent:
    61         fprintf(out, "SetLocal(r%d, %s)", operand(), dataFormatToString(dataFormat()));
     61        out.printf("SetLocal(r%d, %s)", operand(), dataFormatToString(dataFormat()));
    6262        break;
    6363    default:
     
    6767}
    6868
    69 void VariableEvent::dumpFillInfo(const char* name, FILE* out) const
     69void VariableEvent::dumpFillInfo(const char* name, PrintStream& out) const
    7070{
    71     fprintf(out, "%s(@%u, ", name, nodeIndex());
     71    out.printf("%s(@%u, ", name, nodeIndex());
    7272    if (dataFormat() == DataFormatDouble)
    73         fprintf(out, "%s", FPRInfo::debugName(fpr()));
     73        out.printf("%s", FPRInfo::debugName(fpr()));
    7474#if USE(JSVALUE32_64)
    7575    else if (dataFormat() & DataFormatJS)
    76         fprintf(out, "%s:%s", GPRInfo::debugName(tagGPR()), GPRInfo::debugName(payloadGPR()));
     76        out.printf("%s:%s", GPRInfo::debugName(tagGPR()), GPRInfo::debugName(payloadGPR()));
    7777#endif
    7878    else
    79         fprintf(out, "%s", GPRInfo::debugName(gpr()));
    80     fprintf(out, ", %s)", dataFormatToString(dataFormat()));
     79        out.printf("%s", GPRInfo::debugName(gpr()));
     80    out.printf(", %s)", dataFormatToString(dataFormat()));
    8181}
    8282
    83 void VariableEvent::dumpSpillInfo(const char* name, FILE* out) const
     83void VariableEvent::dumpSpillInfo(const char* name, PrintStream& out) const
    8484{
    85     fprintf(out, "%s(@%u, r%d, %s)", name, nodeIndex(), virtualRegister(), dataFormatToString(dataFormat()));
     85    out.printf("%s(@%u, r%d, %s)", name, nodeIndex(), virtualRegister(), dataFormatToString(dataFormat()));
    8686}
    8787
Note: See TracChangeset for help on using the changeset viewer.