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

Side by Side Diff: src/wasm/wasm-text.cc

Issue 2529383002: [inspector] Split off interface-types.h (Closed)
Patch Set: Rebase Created 4 years 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
« src/debug/interface-types.h ('K') | « src/wasm/wasm-text.h ('k') | 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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/wasm/wasm-text.h" 5 #include "src/wasm/wasm-text.h"
6 6
7 #include "src/debug/interface-types.h"
7 #include "src/ostreams.h" 8 #include "src/ostreams.h"
8 #include "src/vector.h" 9 #include "src/vector.h"
9 #include "src/wasm/ast-decoder.h" 10 #include "src/wasm/ast-decoder.h"
10 #include "src/wasm/wasm-module.h" 11 #include "src/wasm/wasm-module.h"
11 #include "src/wasm/wasm-opcodes.h" 12 #include "src/wasm/wasm-opcodes.h"
12 #include "src/zone/zone.h" 13 #include "src/zone/zone.h"
13 14
15 using namespace v8;
14 using namespace v8::internal; 16 using namespace v8::internal;
15 using namespace v8::internal::wasm; 17 using namespace v8::internal::wasm;
16 18
17 namespace { 19 namespace {
18 const char *GetOpName(WasmOpcode opcode) { 20 const char *GetOpName(WasmOpcode opcode) {
19 #define CASE_OP(name, str) \ 21 #define CASE_OP(name, str) \
20 case kExpr##name: \ 22 case kExpr##name: \
21 return str; 23 return str;
22 #define CASE_I32_OP(name, str) CASE_OP(I32##name, "i32." str) 24 #define CASE_I32_OP(name, str) CASE_OP(I32##name, "i32." str)
23 #define CASE_I64_OP(name, str) CASE_OP(I64##name, "i64." str) 25 #define CASE_I64_OP(name, str) CASE_OP(I64##name, "i64." str)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 for (char c : name) { 122 for (char c : name) {
121 bool valid_char = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || 123 bool valid_char = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
122 (c >= 'A' && c <= 'Z') || strchr(special_chars, c); 124 (c >= 'A' && c <= 'Z') || strchr(special_chars, c);
123 if (!valid_char) return false; 125 if (!valid_char) return false;
124 } 126 }
125 return true; 127 return true;
126 } 128 }
127 129
128 } // namespace 130 } // namespace
129 131
130 void wasm::PrintWasmText( 132 void wasm::PrintWasmText(const WasmModule *module,
131 const WasmModule *module, const ModuleWireBytes &wire_bytes, 133 const ModuleWireBytes &wire_bytes, uint32_t func_index,
132 uint32_t func_index, std::ostream &os, 134 std::ostream &os,
133 std::vector<std::tuple<uint32_t, int, int>> *offset_table) { 135 debug::WasmDisassembly::OffsetTable *offset_table) {
134 DCHECK_NOT_NULL(module); 136 DCHECK_NOT_NULL(module);
135 DCHECK_GT(module->functions.size(), func_index); 137 DCHECK_GT(module->functions.size(), func_index);
136 const WasmFunction *fun = &module->functions[func_index]; 138 const WasmFunction *fun = &module->functions[func_index];
137 139
138 AccountingAllocator allocator; 140 AccountingAllocator allocator;
139 Zone zone(&allocator, ZONE_NAME); 141 Zone zone(&allocator, ZONE_NAME);
140 int line_nr = 0; 142 int line_nr = 0;
141 int control_depth = 0; 143 int control_depth = 0;
142 144
143 // Print the function signature. 145 // Print the function signature.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 183 }
182 184
183 for (; i.has_next(); i.next()) { 185 for (; i.has_next(); i.next()) {
184 WasmOpcode opcode = i.current(); 186 WasmOpcode opcode = i.current();
185 if (opcode == kExprElse || opcode == kExprEnd) --control_depth; 187 if (opcode == kExprElse || opcode == kExprEnd) --control_depth;
186 188
187 DCHECK_LE(0, control_depth); 189 DCHECK_LE(0, control_depth);
188 const int kMaxIndentation = 64; 190 const int kMaxIndentation = 64;
189 int indentation = std::min(kMaxIndentation, 2 * control_depth); 191 int indentation = std::min(kMaxIndentation, 2 * control_depth);
190 if (offset_table) { 192 if (offset_table) {
191 offset_table->push_back( 193 offset_table->push_back(debug::WasmDisassemblyOffsetTableEntry(
192 std::make_tuple(i.pc_offset(), line_nr, indentation)); 194 i.pc_offset(), line_nr, indentation));
193 } 195 }
194 196
195 // 64 whitespaces 197 // 64 whitespaces
196 const char padding[kMaxIndentation + 1] = 198 const char padding[kMaxIndentation + 1] =
197 " "; 199 " ";
198 os.write(padding, indentation); 200 os.write(padding, indentation);
199 201
200 switch (opcode) { 202 switch (opcode) {
201 case kExprLoop: 203 case kExprLoop:
202 case kExprIf: 204 case kExprIf:
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 default: 303 default:
302 UNREACHABLE(); 304 UNREACHABLE();
303 break; 305 break;
304 } 306 }
305 os << '\n'; 307 os << '\n';
306 ++line_nr; 308 ++line_nr;
307 } 309 }
308 DCHECK_EQ(0, control_depth); 310 DCHECK_EQ(0, control_depth);
309 DCHECK(i.ok()); 311 DCHECK(i.ok());
310 } 312 }
OLDNEW
« src/debug/interface-types.h ('K') | « src/wasm/wasm-text.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698