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