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/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" | 17 #include "src/ostreams.h" |
18 | 18 |
19 #include "src/compiler/wasm-compiler.h" | 19 #include "src/compiler/wasm-compiler.h" |
20 | 20 |
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1643 UNREACHABLE(); | 1643 UNREACHABLE(); |
1644 node = nullptr; | 1644 node = nullptr; |
1645 break; | 1645 break; |
1646 } | 1646 } |
1647 Push(GetReturnType(sig), node); | 1647 Push(GetReturnType(sig), node); |
1648 } | 1648 } |
1649 }; | 1649 }; |
1650 | 1650 |
1651 bool DecodeLocalDecls(AstLocalDecls& decls, const byte* start, | 1651 bool DecodeLocalDecls(AstLocalDecls& decls, const byte* start, |
1652 const byte* end) { | 1652 const byte* end) { |
1653 base::AccountingAllocator allocator; | 1653 AccountingAllocator allocator; |
1654 Zone tmp(&allocator); | 1654 Zone tmp(&allocator); |
1655 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 1655 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
1656 WasmFullDecoder decoder(&tmp, nullptr, body); | 1656 WasmFullDecoder decoder(&tmp, nullptr, body); |
1657 return decoder.DecodeLocalDecls(decls); | 1657 return decoder.DecodeLocalDecls(decls); |
1658 } | 1658 } |
1659 | 1659 |
1660 BytecodeIterator::BytecodeIterator(const byte* start, const byte* end, | 1660 BytecodeIterator::BytecodeIterator(const byte* start, const byte* end, |
1661 AstLocalDecls* decls) | 1661 AstLocalDecls* decls) |
1662 : Decoder(start, end) { | 1662 : Decoder(start, end) { |
1663 if (decls != nullptr) { | 1663 if (decls != nullptr) { |
1664 if (DecodeLocalDecls(*decls, start, end)) { | 1664 if (DecodeLocalDecls(*decls, start, end)) { |
1665 pc_ += decls->decls_encoded_size; | 1665 pc_ += decls->decls_encoded_size; |
1666 if (pc_ > end_) pc_ = end_; | 1666 if (pc_ > end_) pc_ = end_; |
1667 } | 1667 } |
1668 } | 1668 } |
1669 } | 1669 } |
1670 | 1670 |
1671 DecodeResult VerifyWasmCode(base::AccountingAllocator* allocator, | 1671 DecodeResult VerifyWasmCode(AccountingAllocator* allocator, |
1672 FunctionBody& body) { | 1672 FunctionBody& body) { |
1673 Zone zone(allocator); | 1673 Zone zone(allocator); |
1674 WasmFullDecoder decoder(&zone, nullptr, body); | 1674 WasmFullDecoder decoder(&zone, nullptr, body); |
1675 decoder.Decode(); | 1675 decoder.Decode(); |
1676 return decoder.toResult<DecodeStruct*>(nullptr); | 1676 return decoder.toResult<DecodeStruct*>(nullptr); |
1677 } | 1677 } |
1678 | 1678 |
1679 DecodeResult BuildTFGraph(base::AccountingAllocator* allocator, | 1679 DecodeResult BuildTFGraph(AccountingAllocator* allocator, TFBuilder* builder, |
1680 TFBuilder* builder, FunctionBody& body) { | 1680 FunctionBody& body) { |
1681 Zone zone(allocator); | 1681 Zone zone(allocator); |
1682 WasmFullDecoder decoder(&zone, builder, body); | 1682 WasmFullDecoder decoder(&zone, builder, body); |
1683 decoder.Decode(); | 1683 decoder.Decode(); |
1684 return decoder.toResult<DecodeStruct*>(nullptr); | 1684 return decoder.toResult<DecodeStruct*>(nullptr); |
1685 } | 1685 } |
1686 | 1686 |
1687 unsigned OpcodeLength(const byte* pc, const byte* end) { | 1687 unsigned OpcodeLength(const byte* pc, const byte* end) { |
1688 WasmDecoder decoder(nullptr, nullptr, pc, end); | 1688 WasmDecoder decoder(nullptr, nullptr, pc, end); |
1689 return decoder.OpcodeLength(pc); | 1689 return decoder.OpcodeLength(pc); |
1690 } | 1690 } |
1691 | 1691 |
1692 unsigned OpcodeArity(const byte* pc, const byte* end) { | 1692 unsigned OpcodeArity(const byte* pc, const byte* end) { |
1693 WasmDecoder decoder(nullptr, nullptr, pc, end); | 1693 WasmDecoder decoder(nullptr, nullptr, pc, end); |
1694 return decoder.OpcodeArity(pc); | 1694 return decoder.OpcodeArity(pc); |
1695 } | 1695 } |
1696 | 1696 |
1697 void PrintAstForDebugging(const byte* start, const byte* end) { | 1697 void PrintAstForDebugging(const byte* start, const byte* end) { |
1698 base::AccountingAllocator allocator; | 1698 AccountingAllocator allocator; |
1699 OFStream os(stdout); | 1699 OFStream os(stdout); |
1700 PrintAst(&allocator, FunctionBodyForTesting(start, end), os, nullptr); | 1700 PrintAst(&allocator, FunctionBodyForTesting(start, end), os, nullptr); |
1701 } | 1701 } |
1702 | 1702 |
1703 bool PrintAst(base::AccountingAllocator* allocator, const FunctionBody& body, | 1703 bool PrintAst(AccountingAllocator* allocator, const FunctionBody& body, |
1704 std::ostream& os, | 1704 std::ostream& os, |
1705 std::vector<std::tuple<uint32_t, int, int>>* offset_table) { | 1705 std::vector<std::tuple<uint32_t, int, int>>* offset_table) { |
1706 Zone zone(allocator); | 1706 Zone zone(allocator); |
1707 WasmFullDecoder decoder(&zone, nullptr, body); | 1707 WasmFullDecoder decoder(&zone, nullptr, body); |
1708 int line_nr = 0; | 1708 int line_nr = 0; |
1709 | 1709 |
1710 // Print the function signature. | 1710 // Print the function signature. |
1711 if (body.sig) { | 1711 if (body.sig) { |
1712 os << "// signature: " << *body.sig << std::endl; | 1712 os << "// signature: " << *body.sig << std::endl; |
1713 ++line_nr; | 1713 ++line_nr; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1832 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 1832 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
1833 const byte* start, const byte* end) { | 1833 const byte* start, const byte* end) { |
1834 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 1834 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
1835 WasmFullDecoder decoder(zone, nullptr, body); | 1835 WasmFullDecoder decoder(zone, nullptr, body); |
1836 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); | 1836 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); |
1837 } | 1837 } |
1838 | 1838 |
1839 } // namespace wasm | 1839 } // namespace wasm |
1840 } // namespace internal | 1840 } // namespace internal |
1841 } // namespace v8 | 1841 } // namespace v8 |
OLD | NEW |