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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 error(pc, pc + 1, "arity mismatch in import call (expected %u, got %u)", | 185 error(pc, pc + 1, "arity mismatch in import call (expected %u, got %u)", |
186 expected, operand.arity); | 186 expected, operand.arity); |
187 return false; | 187 return false; |
188 } | 188 } |
189 return true; | 189 return true; |
190 } | 190 } |
191 error(pc, pc + 1, "invalid signature index"); | 191 error(pc, pc + 1, "invalid signature index"); |
192 return false; | 192 return false; |
193 } | 193 } |
194 | 194 |
195 inline bool Complete(const byte* pc, JITSingleFunctionOperand& operand) { | |
196 ModuleEnv* m = module_; | |
197 if (m && m->module && operand.sig_index < m->module->signatures.size()) { | |
198 operand.sig = m->module->signatures[operand.sig_index]; | |
199 return true; | |
200 } | |
201 return false; | |
202 } | |
203 | |
204 inline bool Validate(const byte* pc, JITSingleFunctionOperand& operand) { | |
205 if (Complete(pc, operand)) { | |
206 return true; | |
207 } | |
208 error(pc, pc + 1, "invalid signature index"); | |
209 return false; | |
210 } | |
211 | |
212 inline bool Validate(const byte* pc, BreakDepthOperand& operand, | 195 inline bool Validate(const byte* pc, BreakDepthOperand& operand, |
213 ZoneVector<Control>& control) { | 196 ZoneVector<Control>& control) { |
214 if (operand.arity > 1) { | 197 if (operand.arity > 1) { |
215 error(pc, pc + 1, "invalid arity for br or br_if"); | 198 error(pc, pc + 1, "invalid arity for br or br_if"); |
216 return false; | 199 return false; |
217 } | 200 } |
218 if (operand.depth < control.size()) { | 201 if (operand.depth < control.size()) { |
219 operand.target = &control[control.size() - operand.depth - 1]; | 202 operand.target = &control[control.size() - operand.depth - 1]; |
220 return true; | 203 return true; |
221 } | 204 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 return 1 + operand.arity; | 279 return 1 + operand.arity; |
297 } | 280 } |
298 case kExprCallImport: { | 281 case kExprCallImport: { |
299 CallImportOperand operand(this, pc); | 282 CallImportOperand operand(this, pc); |
300 return operand.arity; | 283 return operand.arity; |
301 } | 284 } |
302 case kExprReturn: { | 285 case kExprReturn: { |
303 ReturnArityOperand operand(this, pc); | 286 ReturnArityOperand operand(this, pc); |
304 return operand.arity; | 287 return operand.arity; |
305 } | 288 } |
306 case kExprJITSingleFunction: | |
307 return 3; | |
308 | 289 |
309 #define DECLARE_OPCODE_CASE(name, opcode, sig) \ | 290 #define DECLARE_OPCODE_CASE(name, opcode, sig) \ |
310 case kExpr##name: \ | 291 case kExpr##name: \ |
311 return kArity_##sig; | 292 return kArity_##sig; |
312 | 293 |
313 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) | 294 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) |
314 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) | 295 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) |
315 FOREACH_MISC_MEM_OPCODE(DECLARE_OPCODE_CASE) | 296 FOREACH_MISC_MEM_OPCODE(DECLARE_OPCODE_CASE) |
316 FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE) | 297 FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE) |
317 FOREACH_SIMPLE_MEM_OPCODE(DECLARE_OPCODE_CASE) | 298 FOREACH_SIMPLE_MEM_OPCODE(DECLARE_OPCODE_CASE) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 332 } |
352 case kExprCallIndirect: { | 333 case kExprCallIndirect: { |
353 CallIndirectOperand operand(this, pc); | 334 CallIndirectOperand operand(this, pc); |
354 return 1 + operand.length; | 335 return 1 + operand.length; |
355 } | 336 } |
356 case kExprCallImport: { | 337 case kExprCallImport: { |
357 CallImportOperand operand(this, pc); | 338 CallImportOperand operand(this, pc); |
358 return 1 + operand.length; | 339 return 1 + operand.length; |
359 } | 340 } |
360 | 341 |
361 case kExprJITSingleFunction: { | |
362 JITSingleFunctionOperand operand(this, pc); | |
363 return 1 + operand.length; | |
364 } | |
365 case kExprSetLocal: | 342 case kExprSetLocal: |
366 case kExprGetLocal: { | 343 case kExprGetLocal: { |
367 LocalIndexOperand operand(this, pc); | 344 LocalIndexOperand operand(this, pc); |
368 return 1 + operand.length; | 345 return 1 + operand.length; |
369 } | 346 } |
370 case kExprBrTable: { | 347 case kExprBrTable: { |
371 BranchTableOperand operand(this, pc); | 348 BranchTableOperand operand(this, pc); |
372 return 1 + operand.length; | 349 return 1 + operand.length; |
373 } | 350 } |
374 case kExprI32Const: { | 351 case kExprI32Const: { |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 } | 997 } |
1021 case kSimdPrefix: { | 998 case kSimdPrefix: { |
1022 if (FLAG_wasm_simd_prototype) { | 999 if (FLAG_wasm_simd_prototype) { |
1023 len++; | 1000 len++; |
1024 byte simd_index = *(pc_ + 1); | 1001 byte simd_index = *(pc_ + 1); |
1025 opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index); | 1002 opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index); |
1026 DecodeSimdOpcode(opcode); | 1003 DecodeSimdOpcode(opcode); |
1027 break; | 1004 break; |
1028 } | 1005 } |
1029 } | 1006 } |
1030 case kExprJITSingleFunction: { | |
1031 if (FLAG_wasm_jit_prototype) { | |
1032 JITSingleFunctionOperand operand(this, pc_); | |
1033 if (Validate(pc_, operand)) { | |
1034 Value index = Pop(2, kAstI32); | |
1035 Value length = Pop(1, kAstI32); | |
1036 Value base = Pop(0, kAstI32); | |
1037 TFNode* call = | |
1038 BUILD(JITSingleFunction, base.node, length.node, index.node, | |
1039 operand.sig_index, operand.sig, position()); | |
1040 Push(kAstI32, call); | |
1041 break; | |
1042 } | |
1043 } | |
1044 } | |
1045 default: | 1007 default: |
1046 error("Invalid opcode"); | 1008 error("Invalid opcode"); |
1047 return; | 1009 return; |
1048 } | 1010 } |
1049 } // end complex bytecode | 1011 } // end complex bytecode |
1050 | 1012 |
1051 #if DEBUG | 1013 #if DEBUG |
1052 if (FLAG_trace_wasm_decoder) { | 1014 if (FLAG_trace_wasm_decoder) { |
1053 for (size_t i = 0; i < stack_.size(); ++i) { | 1015 for (size_t i = 0; i < stack_.size(); ++i) { |
1054 Value& val = stack_[i]; | 1016 Value& val = stack_[i]; |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 } | 1632 } |
1671 case kExprCallFunction: { | 1633 case kExprCallFunction: { |
1672 CallFunctionOperand operand(&i, i.pc()); | 1634 CallFunctionOperand operand(&i, i.pc()); |
1673 if (decoder.Complete(i.pc(), operand)) { | 1635 if (decoder.Complete(i.pc(), operand)) { |
1674 os << " // function #" << operand.index << ": " << *operand.sig; | 1636 os << " // function #" << operand.index << ": " << *operand.sig; |
1675 } else { | 1637 } else { |
1676 os << " // arity=" << operand.arity << " function #" << operand.index; | 1638 os << " // arity=" << operand.arity << " function #" << operand.index; |
1677 } | 1639 } |
1678 break; | 1640 break; |
1679 } | 1641 } |
1680 case kExprJITSingleFunction: { | |
1681 JITSingleFunctionOperand operand(&i, i.pc()); | |
1682 if (decoder.Complete(i.pc(), operand)) { | |
1683 os << " // sig #" << operand.sig_index << ": " << *operand.sig; | |
1684 } | |
1685 break; | |
1686 } | |
1687 case kExprReturn: { | 1642 case kExprReturn: { |
1688 ReturnArityOperand operand(&i, i.pc()); | 1643 ReturnArityOperand operand(&i, i.pc()); |
1689 os << " // arity=" << operand.arity; | 1644 os << " // arity=" << operand.arity; |
1690 break; | 1645 break; |
1691 } | 1646 } |
1692 default: | 1647 default: |
1693 break; | 1648 break; |
1694 } | 1649 } |
1695 os << std::endl; | 1650 os << std::endl; |
1696 ++line_nr; | 1651 ++line_nr; |
1697 } | 1652 } |
1698 | 1653 |
1699 return decoder.ok(); | 1654 return decoder.ok(); |
1700 } | 1655 } |
1701 | 1656 |
1702 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 1657 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
1703 const byte* start, const byte* end) { | 1658 const byte* start, const byte* end) { |
1704 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 1659 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
1705 WasmFullDecoder decoder(zone, nullptr, body); | 1660 WasmFullDecoder decoder(zone, nullptr, body); |
1706 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); | 1661 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); |
1707 } | 1662 } |
1708 | 1663 |
1709 } // namespace wasm | 1664 } // namespace wasm |
1710 } // namespace internal | 1665 } // namespace internal |
1711 } // namespace v8 | 1666 } // namespace v8 |
OLD | NEW |