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/disassembler/Disassembler.h

    r135466 r135640  
    2727#define Disassembler_h
    2828
    29 #include <stdio.h>
    3029#include <wtf/Platform.h>
    31 #include <wtf/StdLibExtras.h>
     30#include <wtf/PrintStream.h>
    3231
    3332namespace JSC {
     
    3635
    3736#if ENABLE(DISASSEMBLER)
    38 bool tryToDisassemble(const MacroAssemblerCodePtr&, size_t, const char* prefix, FILE* out);
     37bool tryToDisassemble(const MacroAssemblerCodePtr&, size_t, const char* prefix, PrintStream&);
    3938#else
    40 inline bool tryToDisassemble(const MacroAssemblerCodePtr&, size_t, const char*, FILE*)
     39inline bool tryToDisassemble(const MacroAssemblerCodePtr&, size_t, const char*, PrintStream&)
    4140{
    4241    return false;
     
    4645// Prints either the disassembly, or a line of text indicating that disassembly failed and
    4746// the range of machine code addresses.
    48 void disassemble(const MacroAssemblerCodePtr&, size_t, const char* prefix, FILE* out);
     47void disassemble(const MacroAssemblerCodePtr&, size_t, const char* prefix, PrintStream& out);
    4948
    5049} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.