OLD | NEW |
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/base/platform/elapsed-timer.h" | 5 #include "src/base/platform/elapsed-timer.h" |
6 #include "src/signature.h" | 6 #include "src/signature.h" |
7 | 7 |
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" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 if (trees_.size() == 0) { | 144 if (trees_.size() == 0) { |
145 if (function_env_->sig->return_count() > 0) { | 145 if (function_env_->sig->return_count() > 0) { |
146 error(start_, "no trees created"); | 146 error(start_, "no trees created"); |
147 } | 147 } |
148 } else { | 148 } else { |
149 tree = trees_[0]; | 149 tree = trees_[0]; |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 if (ok()) { | 153 if (ok()) { |
| 154 if (FLAG_trace_wasm_ast) { |
| 155 PrintAst(function_env, pc, end); |
| 156 } |
154 if (FLAG_trace_wasm_decode_time) { | 157 if (FLAG_trace_wasm_decode_time) { |
155 double ms = decode_timer.Elapsed().InMillisecondsF(); | 158 double ms = decode_timer.Elapsed().InMillisecondsF(); |
156 PrintF(" - decoding took %0.3f ms\n", ms); | 159 PrintF("wasm-decode ok (%0.3f ms)\n\n", ms); |
| 160 } else { |
| 161 TRACE("wasm-decode ok\n\n"); |
157 } | 162 } |
158 TRACE("wasm-decode ok\n\n"); | |
159 } else { | 163 } else { |
160 TRACE("wasm-error module+%-6d func+%d: %s\n\n", baserel(error_pc_), | 164 TRACE("wasm-error module+%-6d func+%d: %s\n\n", baserel(error_pc_), |
161 startrel(error_pc_), error_msg_.get()); | 165 startrel(error_pc_), error_msg_.get()); |
162 } | 166 } |
| 167 |
163 return toResult(tree); | 168 return toResult(tree); |
164 } | 169 } |
165 | 170 |
166 private: | 171 private: |
167 static const size_t kErrorMsgSize = 128; | 172 static const size_t kErrorMsgSize = 128; |
168 | 173 |
169 Zone* zone_; | 174 Zone* zone_; |
170 TFBuilder* builder_; | 175 TFBuilder* builder_; |
171 const byte* base_; | 176 const byte* base_; |
172 TreeResult result_; | 177 TreeResult result_; |
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 } | 1475 } |
1471 } | 1476 } |
1472 | 1477 |
1473 | 1478 |
1474 int OpcodeLength(const byte* pc) { | 1479 int OpcodeLength(const byte* pc) { |
1475 switch (static_cast<WasmOpcode>(*pc)) { | 1480 switch (static_cast<WasmOpcode>(*pc)) { |
1476 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: | 1481 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: |
1477 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) | 1482 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) |
1478 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) | 1483 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) |
1479 #undef DECLARE_OPCODE_CASE | 1484 #undef DECLARE_OPCODE_CASE |
1480 | 1485 { |
| 1486 // Loads and stores have an optional offset. |
| 1487 byte bitfield = pc[1]; |
| 1488 if (MemoryAccess::OffsetField::decode(bitfield)) { |
| 1489 int length; |
| 1490 uint32_t result = 0; |
| 1491 ReadUnsignedLEB128Operand(pc + 2, pc + 7, &length, &result); |
| 1492 return 2 + length; |
| 1493 } |
| 1494 return 2; |
| 1495 } |
1481 case kExprI8Const: | 1496 case kExprI8Const: |
1482 case kExprBlock: | 1497 case kExprBlock: |
1483 case kExprLoop: | 1498 case kExprLoop: |
1484 case kExprBr: | 1499 case kExprBr: |
1485 case kExprBrIf: | 1500 case kExprBrIf: |
1486 return 2; | 1501 return 2; |
1487 case kExprI32Const: | 1502 case kExprI32Const: |
1488 case kExprF32Const: | 1503 case kExprF32Const: |
1489 return 5; | 1504 return 5; |
1490 case kExprI64Const: | 1505 case kExprI64Const: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 | 1586 |
1572 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) | 1587 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) |
1573 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) | 1588 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) |
1574 FOREACH_MISC_MEM_OPCODE(DECLARE_OPCODE_CASE) | 1589 FOREACH_MISC_MEM_OPCODE(DECLARE_OPCODE_CASE) |
1575 FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE) | 1590 FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE) |
1576 #undef DECLARE_OPCODE_CASE | 1591 #undef DECLARE_OPCODE_CASE |
1577 } | 1592 } |
1578 UNREACHABLE(); | 1593 UNREACHABLE(); |
1579 return 0; | 1594 return 0; |
1580 } | 1595 } |
| 1596 |
| 1597 |
| 1598 void PrintAst(FunctionEnv* env, const byte* start, const byte* end) { |
| 1599 const byte* pc = start; |
| 1600 std::vector<int> arity_stack; |
| 1601 while (pc < end) { |
| 1602 int arity = OpcodeArity(env, pc); |
| 1603 size_t length = OpcodeLength(pc); |
| 1604 |
| 1605 for (auto arity : arity_stack) { |
| 1606 printf(" "); |
| 1607 USE(arity); |
| 1608 } |
| 1609 |
| 1610 WasmOpcode opcode = static_cast<WasmOpcode>(*pc); |
| 1611 printf("k%s,", WasmOpcodes::OpcodeName(opcode)); |
| 1612 |
| 1613 for (size_t i = 1; i < length; i++) { |
| 1614 printf(" 0x%02x,", pc[i]); |
| 1615 } |
| 1616 pc += length; |
| 1617 printf("\n"); |
| 1618 |
| 1619 arity_stack.push_back(arity); |
| 1620 while (arity_stack.back() == 0) { |
| 1621 arity_stack.pop_back(); |
| 1622 if (arity_stack.empty()) break; |
| 1623 arity_stack.back()--; |
| 1624 } |
| 1625 } |
| 1626 } |
1581 } // namespace wasm | 1627 } // namespace wasm |
1582 } // namespace internal | 1628 } // namespace internal |
1583 } // namespace v8 | 1629 } // namespace v8 |
OLD | NEW |