Bug 1331034 - Make JSONSpewer inherit from JSONPrinter. r=h4writer

--HG--
rename : js/src/jit/JSONSpewer.h => js/src/jit/JSONPrinter.h
This commit is contained in:
Tom Schuster 2017-02-04 12:52:56 +01:00
Родитель 9ab799f409
Коммит f096742947
4 изменённых файлов: 63 добавлений и 153 удалений

55
js/src/jit/JSONPrinter.h Normal file
Просмотреть файл

@ -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 <stdio.h>
#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 */

Просмотреть файл

@ -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();

Просмотреть файл

@ -11,8 +11,8 @@
#include <stdio.h>
#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);

Просмотреть файл

@ -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',