Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(685)

Side by Side Diff: src/compiler/graph-visualizer.cc

Issue 2255263002: [turbolizer] Also escape backslashes in JSON strings. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/graph-visualizer.h" 5 #include "src/compiler/graph-visualizer.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 10
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 static int SafeId(Node* node) { return node == nullptr ? -1 : node->id(); } 78 static int SafeId(Node* node) { return node == nullptr ? -1 : node->id(); }
79 static const char* SafeMnemonic(Node* node) { 79 static const char* SafeMnemonic(Node* node) {
80 return node == nullptr ? "null" : node->op()->mnemonic(); 80 return node == nullptr ? "null" : node->op()->mnemonic();
81 } 81 }
82 82
83 #define DEAD_COLOR "#999999" 83 #define DEAD_COLOR "#999999"
84 84
85 class Escaped { 85 class Escaped {
86 public: 86 public:
87 explicit Escaped(const std::ostringstream& os, 87 explicit Escaped(const std::ostringstream& os,
88 const char* escaped_chars = "<>|{}") 88 const char* escaped_chars = "<>|{}\\")
89 : str_(os.str()), escaped_chars_(escaped_chars) {} 89 : str_(os.str()), escaped_chars_(escaped_chars) {}
90 90
91 friend std::ostream& operator<<(std::ostream& os, const Escaped& e) { 91 friend std::ostream& operator<<(std::ostream& os, const Escaped& e) {
92 for (std::string::const_iterator i = e.str_.begin(); i != e.str_.end(); 92 for (std::string::const_iterator i = e.str_.begin(); i != e.str_.end();
93 ++i) { 93 ++i) {
94 if (e.needs_escape(*i)) os << "\\"; 94 if (e.needs_escape(*i)) os << "\\";
95 os << *i; 95 os << *i;
96 } 96 }
97 return os; 97 return os;
98 } 98 }
(...skipping 28 matching lines...) Expand all
127 void PrintNode(Node* node) { 127 void PrintNode(Node* node) {
128 if (first_node_) { 128 if (first_node_) {
129 first_node_ = false; 129 first_node_ = false;
130 } else { 130 } else {
131 os_ << ",\n"; 131 os_ << ",\n";
132 } 132 }
133 std::ostringstream label, title, properties; 133 std::ostringstream label, title, properties;
134 node->op()->PrintTo(label, Operator::PrintVerbosity::kSilent); 134 node->op()->PrintTo(label, Operator::PrintVerbosity::kSilent);
135 node->op()->PrintTo(title, Operator::PrintVerbosity::kVerbose); 135 node->op()->PrintTo(title, Operator::PrintVerbosity::kVerbose);
136 node->op()->PrintPropsTo(properties); 136 node->op()->PrintPropsTo(properties);
137 os_ << "{\"id\":" << SafeId(node) << ",\"label\":\"" << Escaped(label, "\"") 137 os_ << "{\"id\":" << SafeId(node) << ",\"label\":\""
138 << "\"" 138 << Escaped(label, "\"\\") << "\""
139 << ",\"title\":\"" << Escaped(title, "\"") << "\"" 139 << ",\"title\":\"" << Escaped(title, "\"\\") << "\""
140 << ",\"live\": " << (live_.IsLive(node) ? "true" : "false") 140 << ",\"live\": " << (live_.IsLive(node) ? "true" : "false")
141 << ",\"properties\":\"" << Escaped(properties, "\"") << "\""; 141 << ",\"properties\":\"" << Escaped(properties, "\"\\") << "\"";
142 IrOpcode::Value opcode = node->opcode(); 142 IrOpcode::Value opcode = node->opcode();
143 if (IrOpcode::IsPhiOpcode(opcode)) { 143 if (IrOpcode::IsPhiOpcode(opcode)) {
144 os_ << ",\"rankInputs\":[0," << NodeProperties::FirstControlIndex(node) 144 os_ << ",\"rankInputs\":[0," << NodeProperties::FirstControlIndex(node)
145 << "]"; 145 << "]";
146 os_ << ",\"rankWithInput\":[" << NodeProperties::FirstControlIndex(node) 146 os_ << ",\"rankWithInput\":[" << NodeProperties::FirstControlIndex(node)
147 << "]"; 147 << "]";
148 } else if (opcode == IrOpcode::kIfTrue || opcode == IrOpcode::kIfFalse || 148 } else if (opcode == IrOpcode::kIfTrue || opcode == IrOpcode::kIfFalse ||
149 opcode == IrOpcode::kLoop) { 149 opcode == IrOpcode::kLoop) {
150 os_ << ",\"rankInputs\":[" << NodeProperties::FirstControlIndex(node) 150 os_ << ",\"rankInputs\":[" << NodeProperties::FirstControlIndex(node)
151 << "]"; 151 << "]";
(...skipping 11 matching lines...) Expand all
163 os_ << ",\"opinfo\":\"" << node->op()->ValueInputCount() << " v " 163 os_ << ",\"opinfo\":\"" << node->op()->ValueInputCount() << " v "
164 << node->op()->EffectInputCount() << " eff " 164 << node->op()->EffectInputCount() << " eff "
165 << node->op()->ControlInputCount() << " ctrl in, " 165 << node->op()->ControlInputCount() << " ctrl in, "
166 << node->op()->ValueOutputCount() << " v " 166 << node->op()->ValueOutputCount() << " v "
167 << node->op()->EffectOutputCount() << " eff " 167 << node->op()->EffectOutputCount() << " eff "
168 << node->op()->ControlOutputCount() << " ctrl out\""; 168 << node->op()->ControlOutputCount() << " ctrl out\"";
169 if (NodeProperties::IsTyped(node)) { 169 if (NodeProperties::IsTyped(node)) {
170 Type* type = NodeProperties::GetType(node); 170 Type* type = NodeProperties::GetType(node);
171 std::ostringstream type_out; 171 std::ostringstream type_out;
172 type->PrintTo(type_out); 172 type->PrintTo(type_out);
173 os_ << ",\"type\":\"" << Escaped(type_out, "\"") << "\""; 173 os_ << ",\"type\":\"" << Escaped(type_out, "\"\\") << "\"";
174 } 174 }
175 os_ << "}"; 175 os_ << "}";
176 } 176 }
177 177
178 private: 178 private:
179 std::ostream& os_; 179 std::ostream& os_;
180 AllNodes all_; 180 AllNodes all_;
181 AllNodes live_; 181 AllNodes live_;
182 const SourcePositionTable* positions_; 182 const SourcePositionTable* positions_;
183 bool first_node_; 183 bool first_node_;
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 os << "]"; 707 os << "]";
708 } 708 }
709 os << std::endl; 709 os << std::endl;
710 } 710 }
711 } 711 }
712 return os; 712 return os;
713 } 713 }
714 } // namespace compiler 714 } // namespace compiler
715 } // namespace internal 715 } // namespace internal
716 } // namespace v8 716 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698