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/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" |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 if (ok()) { | 405 if (ok()) { |
406 TRACE("wasm-decode ok\n"); | 406 TRACE("wasm-decode ok\n"); |
407 } else { | 407 } else { |
408 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_), |
409 startrel(error_pc_), error_msg_.get()); | 409 startrel(error_pc_), error_msg_.get()); |
410 } | 410 } |
411 | 411 |
412 return toResult(tree); | 412 return toResult(tree); |
413 } | 413 } |
414 | 414 |
415 std::vector<LocalType>* DecodeLocalDeclsForTesting() { | 415 bool DecodeLocalDecls(AstLocalDecls& decls) { |
416 DecodeLocalDecls(); | 416 DecodeLocalDecls(); |
417 if (failed()) return nullptr; | 417 if (failed()) return false; |
418 auto result = new std::vector<LocalType>(); | 418 decls.decls_encoded_size = pc_offset(); |
419 result->reserve(local_type_vec_.size()); | 419 decls.total_local_count = 0; |
420 for (size_t i = 0; i < local_type_vec_.size(); i++) { | 420 decls.local_types.reserve(local_type_vec_.size()); |
421 result->push_back(local_type_vec_[i]); | 421 for (size_t pos = 0; pos < local_type_vec_.size();) { |
| 422 uint32_t count = 0; |
| 423 LocalType type = local_type_vec_[pos]; |
| 424 while (pos < local_type_vec_.size() && local_type_vec_[pos] == type) { |
| 425 pos++; |
| 426 count++; |
| 427 } |
| 428 decls.total_local_count += count; |
| 429 decls.local_types.push_back(std::pair<LocalType, uint32_t>(type, count)); |
422 } | 430 } |
423 return result; | 431 return true; |
424 } | 432 } |
425 | 433 |
426 BitVector* AnalyzeLoopAssignmentForTesting(const byte* pc, | 434 BitVector* AnalyzeLoopAssignmentForTesting(const byte* pc, |
427 size_t num_locals) { | 435 size_t num_locals) { |
428 total_locals_ = num_locals; | 436 total_locals_ = num_locals; |
429 local_type_vec_.reserve(num_locals); | 437 local_type_vec_.reserve(num_locals); |
430 if (num_locals > local_type_vec_.size()) { | 438 if (num_locals > local_type_vec_.size()) { |
431 local_type_vec_.insert(local_type_vec_.end(), | 439 local_type_vec_.insert(local_type_vec_.end(), |
432 num_locals - local_type_vec_.size(), kAstI32); | 440 num_locals - local_type_vec_.size(), kAstI32); |
433 } | 441 } |
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1619 while (arity_stack.back() == 0) { | 1627 while (arity_stack.back() == 0) { |
1620 arity_stack.pop_back(); | 1628 arity_stack.pop_back(); |
1621 if (arity_stack.empty()) return assigned; // reached end of loop | 1629 if (arity_stack.empty()) return assigned; // reached end of loop |
1622 arity_stack.back()--; | 1630 arity_stack.back()--; |
1623 } | 1631 } |
1624 } | 1632 } |
1625 return assigned; | 1633 return assigned; |
1626 } | 1634 } |
1627 }; | 1635 }; |
1628 | 1636 |
1629 std::vector<LocalType>* DecodeLocalDeclsForTesting( | 1637 bool DecodeLocalDecls(AstLocalDecls& decls, const byte* start, |
1630 base::AccountingAllocator* allocator, const byte* start, const byte* end) { | 1638 const byte* end) { |
1631 Zone zone(allocator); | 1639 base::AccountingAllocator allocator; |
| 1640 Zone tmp(&allocator); |
1632 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 1641 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
1633 SR_WasmDecoder decoder(&zone, nullptr, body); | 1642 SR_WasmDecoder decoder(&tmp, nullptr, body); |
1634 return decoder.DecodeLocalDeclsForTesting(); | 1643 return decoder.DecodeLocalDecls(decls); |
1635 } | 1644 } |
1636 | 1645 |
1637 TreeResult VerifyWasmCode(base::AccountingAllocator* allocator, | 1646 TreeResult VerifyWasmCode(base::AccountingAllocator* allocator, |
1638 FunctionBody& body) { | 1647 FunctionBody& body) { |
1639 Zone zone(allocator); | 1648 Zone zone(allocator); |
1640 SR_WasmDecoder decoder(&zone, nullptr, body); | 1649 SR_WasmDecoder decoder(&zone, nullptr, body); |
1641 TreeResult result = decoder.Decode(); | 1650 TreeResult result = decoder.Decode(); |
1642 return result; | 1651 return result; |
1643 } | 1652 } |
1644 | 1653 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 SR_WasmDecoder decoder(&zone, nullptr, body); | 1702 SR_WasmDecoder decoder(&zone, nullptr, body); |
1694 | 1703 |
1695 OFStream os(stdout); | 1704 OFStream os(stdout); |
1696 | 1705 |
1697 // Print the function signature. | 1706 // Print the function signature. |
1698 if (body.sig) { | 1707 if (body.sig) { |
1699 os << "// signature: " << *body.sig << std::endl; | 1708 os << "// signature: " << *body.sig << std::endl; |
1700 } | 1709 } |
1701 | 1710 |
1702 // Print the local declarations. | 1711 // Print the local declarations. |
1703 std::vector<LocalType>* decls = decoder.DecodeLocalDeclsForTesting(); | 1712 AstLocalDecls decls(&zone); |
| 1713 decoder.DecodeLocalDecls(decls); |
1704 const byte* pc = decoder.pc(); | 1714 const byte* pc = decoder.pc(); |
1705 if (body.start != decoder.pc()) { | 1715 if (body.start != decoder.pc()) { |
1706 printf("// locals:"); | 1716 printf("// locals:"); |
1707 size_t pos = 0; | 1717 for (auto p : decls.local_types) { |
1708 while (pos < decls->size()) { | 1718 LocalType type = p.first; |
1709 LocalType type = decls->at(pos++); | 1719 uint32_t count = p.second; |
1710 size_t count = 1; | |
1711 while (pos < decls->size() && decls->at(pos) == type) { | |
1712 pos++; | |
1713 count++; | |
1714 } | |
1715 | |
1716 os << " " << count << " " << WasmOpcodes::TypeName(type); | 1720 os << " " << count << " " << WasmOpcodes::TypeName(type); |
1717 } | 1721 } |
1718 os << std::endl; | 1722 os << std::endl; |
1719 | 1723 |
1720 for (const byte* locals = body.start; locals < pc; locals++) { | 1724 for (const byte* locals = body.start; locals < pc; locals++) { |
1721 printf(" 0x%02x,", *locals); | 1725 printf(" 0x%02x,", *locals); |
1722 } | 1726 } |
1723 printf("\n"); | 1727 printf("\n"); |
1724 } | 1728 } |
1725 delete decls; | |
1726 | 1729 |
1727 printf("// body: \n"); | 1730 printf("// body: \n"); |
1728 std::vector<int> arity_stack; | 1731 std::vector<int> arity_stack; |
1729 while (pc < body.end) { | 1732 while (pc < body.end) { |
1730 int arity = decoder.OpcodeArity(pc); | 1733 int arity = decoder.OpcodeArity(pc); |
1731 size_t length = decoder.OpcodeLength(pc); | 1734 size_t length = decoder.OpcodeLength(pc); |
1732 | 1735 |
1733 for (auto arity : arity_stack) { | 1736 for (auto arity : arity_stack) { |
1734 printf(" "); | 1737 printf(" "); |
1735 USE(arity); | 1738 USE(arity); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1785 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 1788 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
1786 const byte* start, const byte* end) { | 1789 const byte* start, const byte* end) { |
1787 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 1790 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
1788 SR_WasmDecoder decoder(zone, nullptr, body); | 1791 SR_WasmDecoder decoder(zone, nullptr, body); |
1789 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); | 1792 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); |
1790 } | 1793 } |
1791 | 1794 |
1792 } // namespace wasm | 1795 } // namespace wasm |
1793 } // namespace internal | 1796 } // namespace internal |
1794 } // namespace v8 | 1797 } // namespace v8 |
OLD | NEW |