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

Side by Side Diff: src/wasm/ast-decoder.cc

Issue 1802353002: [wasm] Add --trace-wasm-ast-start and --trace-wasm-ast-end options and improve tracing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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 | « src/flag-definitions.h ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/signature.h" 5 #include "src/signature.h"
6 6
7 #include "src/bit-vector.h" 7 #include "src/bit-vector.h"
8 #include "src/flags.h" 8 #include "src/flags.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/zone-containers.h" 10 #include "src/zone-containers.h"
11 11
12 #include "src/wasm/ast-decoder.h" 12 #include "src/wasm/ast-decoder.h"
13 #include "src/wasm/decoder.h" 13 #include "src/wasm/decoder.h"
14 #include "src/wasm/wasm-module.h" 14 #include "src/wasm/wasm-module.h"
15 #include "src/wasm/wasm-opcodes.h" 15 #include "src/wasm/wasm-opcodes.h"
16 16
17 #include "src/ostreams.h"
18
17 #include "src/compiler/wasm-compiler.h" 19 #include "src/compiler/wasm-compiler.h"
18 20
19 namespace v8 { 21 namespace v8 {
20 namespace internal { 22 namespace internal {
21 namespace wasm { 23 namespace wasm {
22 24
23 #if DEBUG 25 #if DEBUG
24 #define TRACE(...) \ 26 #define TRACE(...) \
25 do { \ 27 do { \
26 if (FLAG_trace_wasm_decoder) PrintF(__VA_ARGS__); \ 28 if (FLAG_trace_wasm_decoder) PrintF(__VA_ARGS__); \
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (trees_.size() == 0) { 396 if (trees_.size() == 0) {
395 if (sig_->return_count() > 0) { 397 if (sig_->return_count() > 0) {
396 error(start_, "no trees created"); 398 error(start_, "no trees created");
397 } 399 }
398 } else { 400 } else {
399 tree = trees_[0]; 401 tree = trees_[0];
400 } 402 }
401 } 403 }
402 404
403 if (ok()) { 405 if (ok()) {
404 if (FLAG_trace_wasm_ast) {
405 FunctionBody body = {module_, sig_, base_, start_, end_};
406 PrintAst(body);
407 }
408 TRACE("wasm-decode ok\n"); 406 TRACE("wasm-decode ok\n");
409 } else { 407 } else {
410 TRACE("wasm-error module+%-6d func+%d: %s\n\n", baserel(error_pc_), 408 TRACE("wasm-error module+%-6d func+%d: %s\n\n", baserel(error_pc_),
411 startrel(error_pc_), error_msg_.get()); 409 startrel(error_pc_), error_msg_.get());
412 } 410 }
413 411
414 return toResult(tree); 412 return toResult(tree);
415 } 413 }
416 414
417 std::vector<LocalType>* DecodeLocalDeclsForTesting() { 415 std::vector<LocalType>* DecodeLocalDeclsForTesting() {
(...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 return decoder.OpcodeLength(pc); 1680 return decoder.OpcodeLength(pc);
1683 } 1681 }
1684 1682
1685 int OpcodeArity(ModuleEnv* module, FunctionSig* sig, const byte* pc, 1683 int OpcodeArity(ModuleEnv* module, FunctionSig* sig, const byte* pc,
1686 const byte* end) { 1684 const byte* end) {
1687 WasmDecoder decoder(module, sig, pc, end); 1685 WasmDecoder decoder(module, sig, pc, end);
1688 return decoder.OpcodeArity(pc); 1686 return decoder.OpcodeArity(pc);
1689 } 1687 }
1690 1688
1691 void PrintAst(FunctionBody& body) { 1689 void PrintAst(FunctionBody& body) {
1692 WasmDecoder decoder(body.module, body.sig, body.start, body.end); 1690 Zone zone;
1693 const byte* pc = body.start; 1691 SR_WasmDecoder decoder(&zone, nullptr, body);
1692
1693 OFStream os(stdout);
1694
1695 // Print the function signature.
1696 if (body.sig) {
1697 os << "// signature: " << *body.sig << std::endl;
1698 }
1699
1700 // Print the local declarations.
1701 std::vector<LocalType>* decls = decoder.DecodeLocalDeclsForTesting();
1702 const byte* pc = decoder.pc();
1703 if (body.start != decoder.pc()) {
1704 printf("// locals:");
1705 size_t pos = 0;
1706 while (pos < decls->size()) {
1707 LocalType type = decls->at(pos++);
1708 size_t count = 1;
1709 while (pos < decls->size() && decls->at(pos) == type) {
1710 pos++;
1711 count++;
1712 }
1713
1714 os << " " << count << " " << WasmOpcodes::TypeName(type);
1715 }
1716 os << std::endl;
1717
1718 for (const byte* locals = body.start; locals < pc; locals++) {
1719 printf(" 0x%02x,", *locals);
1720 }
1721 printf("\n");
1722 }
1723 delete decls;
1724
1725 printf("// body: \n");
1694 std::vector<int> arity_stack; 1726 std::vector<int> arity_stack;
1695 while (pc < body.end) { 1727 while (pc < body.end) {
1696 int arity = decoder.OpcodeArity(pc); 1728 int arity = decoder.OpcodeArity(pc);
1697 size_t length = decoder.OpcodeLength(pc); 1729 size_t length = decoder.OpcodeLength(pc);
1698 1730
1699 for (auto arity : arity_stack) { 1731 for (auto arity : arity_stack) {
1700 printf(" "); 1732 printf(" ");
1701 USE(arity); 1733 USE(arity);
1702 } 1734 }
1703 1735
1704 WasmOpcode opcode = static_cast<WasmOpcode>(*pc); 1736 WasmOpcode opcode = static_cast<WasmOpcode>(*pc);
1705 printf("k%s,", WasmOpcodes::OpcodeName(opcode)); 1737 printf("k%s,", WasmOpcodes::OpcodeName(opcode));
1706 1738
1707 for (size_t i = 1; i < length; i++) { 1739 for (size_t i = 1; i < length; i++) {
1708 printf(" 0x%02x,", pc[i]); 1740 printf(" 0x%02x,", pc[i]);
1709 } 1741 }
1742
1743 if (body.module) {
1744 switch (opcode) {
1745 case kExprCallIndirect: {
1746 SignatureIndexOperand operand(&decoder, pc);
1747 if (decoder.Validate(pc, operand)) {
1748 os << " // sig #" << operand.index << ": " << *operand.sig;
1749 }
1750 break;
1751 }
1752 case kExprCallImport: {
1753 ImportIndexOperand operand(&decoder, pc);
1754 if (decoder.Validate(pc, operand)) {
1755 os << " // import #" << operand.index << ": " << *operand.sig;
1756 }
1757 break;
1758 }
1759 case kExprCallFunction: {
1760 FunctionIndexOperand operand(&decoder, pc);
1761 if (decoder.Validate(pc, operand)) {
1762 os << " // function #" << operand.index << ": " << *operand.sig;
1763 }
1764 break;
1765 }
1766 default:
1767 break;
1768 }
1769 }
1770
1710 pc += length; 1771 pc += length;
1711 printf("\n"); 1772 printf("\n");
1712 1773
1713 arity_stack.push_back(arity); 1774 arity_stack.push_back(arity);
1714 while (arity_stack.back() == 0) { 1775 while (arity_stack.back() == 0) {
1715 arity_stack.pop_back(); 1776 arity_stack.pop_back();
1716 if (arity_stack.empty()) break; 1777 if (arity_stack.empty()) break;
1717 arity_stack.back()--; 1778 arity_stack.back()--;
1718 } 1779 }
1719 } 1780 }
1720 } 1781 }
1721 1782
1722 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, 1783 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
1723 const byte* start, const byte* end) { 1784 const byte* start, const byte* end) {
1724 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; 1785 FunctionBody body = {nullptr, nullptr, nullptr, start, end};
1725 SR_WasmDecoder decoder(zone, nullptr, body); 1786 SR_WasmDecoder decoder(zone, nullptr, body);
1726 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); 1787 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals);
1727 } 1788 }
1728 1789
1729 } // namespace wasm 1790 } // namespace wasm
1730 } // namespace internal 1791 } // namespace internal
1731 } // namespace v8 1792 } // namespace v8
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698