diff --git a/js/src/jit/JSONPrinter.h b/js/src/jit/JSONPrinter.h new file mode 100644 index 000000000000..6ab4a5b9a6f8 --- /dev/null +++ b/js/src/jit/JSONPrinter.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jit_JSONPrinter_h +#define jit_JSONPrinter_h + +#ifdef JS_JITSPEW + +#include + +#include "js/TypeDecls.h" +#include "vm/Printer.h" + +namespace js { +namespace jit { + +class JSONPrinter +{ + protected: + int indentLevel_; + bool first_; + GenericPrinter& out_; + + void indent(); + + void property(const char* name); + void beginObject(); + void beginObjectProperty(const char* name); + void beginListProperty(const char* name); + void stringValue(const char* format, ...) MOZ_FORMAT_PRINTF(2, 3); + void stringProperty(const char* name, const char* format, ...) MOZ_FORMAT_PRINTF(3, 4); + void beginStringProperty(const char* name); + void endStringProperty(); + void integerValue(int value); + void integerProperty(const char* name, int value); + void endObject(); + void endList(); + + public: + explicit JSONPrinter(GenericPrinter& out) + : indentLevel_(0), + first_(true), + out_(out) + { } +}; + +} // namespace jit +} // namespace js + +#endif /* JS_JITSPEW */ + +#endif /* jit_JSONPrinter_h */ diff --git a/js/src/jit/JSONSpewer.cpp b/js/src/jit/JSONSpewer.cpp index 39d2118060f8..e9d3e8bb8876 100644 --- a/js/src/jit/JSONSpewer.cpp +++ b/js/src/jit/JSONSpewer.cpp @@ -21,128 +21,6 @@ using namespace js; using namespace js::jit; -void -JSONSpewer::indent() -{ - MOZ_ASSERT(indentLevel_ >= 0); - out_.printf("\n"); - for (int i = 0; i < indentLevel_; i++) - out_.printf(" "); -} - -void -JSONSpewer::property(const char* name) -{ - if (!first_) - out_.printf(","); - indent(); - out_.printf("\"%s\":", name); - first_ = false; -} - -void -JSONSpewer::beginObject() -{ - if (!first_) { - out_.printf(","); - indent(); - } - out_.printf("{"); - indentLevel_++; - first_ = true; -} - -void -JSONSpewer::beginObjectProperty(const char* name) -{ - property(name); - out_.printf("{"); - indentLevel_++; - first_ = true; -} - -void -JSONSpewer::beginListProperty(const char* name) -{ - property(name); - out_.printf("["); - first_ = true; -} - -void -JSONSpewer::beginStringProperty(const char* name) -{ - property(name); - out_.printf("\""); -} - -void -JSONSpewer::endStringProperty() -{ - out_.printf("\""); -} - -void -JSONSpewer::stringProperty(const char* name, const char* format, ...) -{ - va_list ap; - va_start(ap, format); - - beginStringProperty(name); - out_.vprintf(format, ap); - endStringProperty(); - - va_end(ap); -} - -void -JSONSpewer::stringValue(const char* format, ...) -{ - va_list ap; - va_start(ap, format); - - if (!first_) - out_.printf(","); - out_.printf("\""); - out_.vprintf(format, ap); - out_.printf("\""); - - va_end(ap); - first_ = false; -} - -void -JSONSpewer::integerProperty(const char* name, int value) -{ - property(name); - out_.printf("%d", value); -} - -void -JSONSpewer::integerValue(int value) -{ - if (!first_) - out_.printf(","); - out_.printf("%d", value); - first_ = false; -} - -void -JSONSpewer::endObject() -{ - indentLevel_--; - indent(); - out_.printf("}"); - first_ = false; -} - -void -JSONSpewer::endList() -{ - out_.printf("]"); - first_ = false; -} - void JSONSpewer::beginFunction(JSScript* script) { @@ -172,16 +50,15 @@ JSONSpewer::spewMResumePoint(MResumePoint* rp) if (rp->caller()) integerProperty("caller", rp->caller()->block()->id()); - property("mode"); switch (rp->mode()) { case MResumePoint::ResumeAt: - out_.printf("\"At\""); + stringProperty("mode", "%s", "At"); break; case MResumePoint::ResumeAfter: - out_.printf("\"After\""); + stringProperty("mode", "%s", "After"); break; case MResumePoint::Outer: - out_.printf("\"Outer\""); + stringProperty("mode", "%s", "Outer"); break; } @@ -374,8 +251,7 @@ JSONSpewer::spewRanges(BacktrackingAllocator* regalloc) LiveRange* range = LiveRange::get(*iter); beginObject(); - property("allocation"); - out_.printf("\"%s\"", range->bundle()->allocation().toString().get()); + stringProperty("allocation", "%s", range->bundle()->allocation().toString().get()); integerProperty("start", range->from().bits()); integerProperty("end", range->to().bits()); endObject(); diff --git a/js/src/jit/JSONSpewer.h b/js/src/jit/JSONSpewer.h index 02f449c7ab04..45200ffa1641 100644 --- a/js/src/jit/JSONSpewer.h +++ b/js/src/jit/JSONSpewer.h @@ -11,8 +11,8 @@ #include +#include "jit/JSONPrinter.h" #include "js/TypeDecls.h" -#include "vm/Printer.h" namespace js { namespace jit { @@ -23,33 +23,11 @@ class MIRGraph; class MResumePoint; class LNode; -class JSONSpewer +class JSONSpewer : JSONPrinter { - private: - int indentLevel_; - bool first_; - GenericPrinter& out_; - - void indent(); - - void property(const char* name); - void beginObject(); - void beginObjectProperty(const char* name); - void beginListProperty(const char* name); - void stringValue(const char* format, ...) MOZ_FORMAT_PRINTF(2, 3); - void stringProperty(const char* name, const char* format, ...) MOZ_FORMAT_PRINTF(3, 4); - void beginStringProperty(const char* name); - void endStringProperty(); - void integerValue(int value); - void integerProperty(const char* name, int value); - void endObject(); - void endList(); - public: explicit JSONSpewer(GenericPrinter& out) - : indentLevel_(0), - first_(true), - out_(out) + : JSONPrinter(out) { } void beginFunction(JSScript* script); diff --git a/js/src/moz.build b/js/src/moz.build index 197be027bb23..d230c2c27fbb 100644 --- a/js/src/moz.build +++ b/js/src/moz.build @@ -248,6 +248,7 @@ UNIFIED_SOURCES += [ 'jit/JitFrames.cpp', 'jit/JitOptions.cpp', 'jit/JitSpewer.cpp', + 'jit/JSONPrinter.cpp', 'jit/JSONSpewer.cpp', 'jit/LICM.cpp', 'jit/Linker.cpp',