| Index: src/compiler/graph-visualizer.cc
|
| diff --git a/src/compiler/graph-visualizer.cc b/src/compiler/graph-visualizer.cc
|
| index d810c3785ac71d8a415958ddddc1c9559df01f90..f30effe830065858327b1df82a435d72c04ae636 100644
|
| --- a/src/compiler/graph-visualizer.cc
|
| +++ b/src/compiler/graph-visualizer.cc
|
| @@ -81,33 +81,28 @@ static const char* SafeMnemonic(Node* node) {
|
| return node == nullptr ? "null" : node->op()->mnemonic();
|
| }
|
|
|
| -#define DEAD_COLOR "#999999"
|
| -
|
| -class Escaped {
|
| +class JSONEscaped {
|
| public:
|
| - explicit Escaped(const std::ostringstream& os,
|
| - const char* escaped_chars = "<>|{}\\")
|
| - : str_(os.str()), escaped_chars_(escaped_chars) {}
|
| -
|
| - friend std::ostream& operator<<(std::ostream& os, const Escaped& e) {
|
| - for (std::string::const_iterator i = e.str_.begin(); i != e.str_.end();
|
| - ++i) {
|
| - if (e.needs_escape(*i)) os << "\\";
|
| - os << *i;
|
| - }
|
| + explicit JSONEscaped(const std::ostringstream& os) : str_(os.str()) {}
|
| +
|
| + friend std::ostream& operator<<(std::ostream& os, const JSONEscaped& e) {
|
| + for (char c : e.str_) PipeCharacter(os, c);
|
| return os;
|
| }
|
|
|
| private:
|
| - bool needs_escape(char ch) const {
|
| - for (size_t i = 0; i < strlen(escaped_chars_); ++i) {
|
| - if (ch == escaped_chars_[i]) return true;
|
| - }
|
| - return false;
|
| + static std::ostream& PipeCharacter(std::ostream& os, char c) {
|
| + if (c == '"') return os << "\\\"";
|
| + if (c == '\\') return os << "\\\\";
|
| + if (c == '\b') return os << "\\b";
|
| + if (c == '\f') return os << "\\f";
|
| + if (c == '\n') return os << "\\n";
|
| + if (c == '\r') return os << "\\r";
|
| + if (c == '\t') return os << "\\t";
|
| + return os << c;
|
| }
|
|
|
| const std::string str_;
|
| - const char* const escaped_chars_;
|
| };
|
|
|
| class JSONGraphNodeWriter {
|
| @@ -135,11 +130,11 @@ class JSONGraphNodeWriter {
|
| node->op()->PrintTo(label, Operator::PrintVerbosity::kSilent);
|
| node->op()->PrintTo(title, Operator::PrintVerbosity::kVerbose);
|
| node->op()->PrintPropsTo(properties);
|
| - os_ << "{\"id\":" << SafeId(node) << ",\"label\":\""
|
| - << Escaped(label, "\"\\") << "\""
|
| - << ",\"title\":\"" << Escaped(title, "\"\\") << "\""
|
| + os_ << "{\"id\":" << SafeId(node) << ",\"label\":\"" << JSONEscaped(label)
|
| + << "\""
|
| + << ",\"title\":\"" << JSONEscaped(title) << "\""
|
| << ",\"live\": " << (live_.IsLive(node) ? "true" : "false")
|
| - << ",\"properties\":\"" << Escaped(properties, "\"\\") << "\"";
|
| + << ",\"properties\":\"" << JSONEscaped(properties) << "\"";
|
| IrOpcode::Value opcode = node->opcode();
|
| if (IrOpcode::IsPhiOpcode(opcode)) {
|
| os_ << ",\"rankInputs\":[0," << NodeProperties::FirstControlIndex(node)
|
| @@ -171,7 +166,7 @@ class JSONGraphNodeWriter {
|
| Type* type = NodeProperties::GetType(node);
|
| std::ostringstream type_out;
|
| type->PrintTo(type_out);
|
| - os_ << ",\"type\":\"" << Escaped(type_out, "\"\\") << "\"";
|
| + os_ << ",\"type\":\"" << JSONEscaped(type_out) << "\"";
|
| }
|
| os_ << "}";
|
| }
|
|
|