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) { | |
Mircea Trofin
2016/07/12 02:49:13
Coding convention says pass-by-reference parameter
ritesht
2016/07/13 23:58:45
The other functions don't seem to use this. Maybe
| |
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)) { | |
Mircea Trofin
2016/07/12 02:49:13
same as above
ritesht
2016/07/13 23:58:45
Acknowledged.
| |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 return 1 + operand.length; | 351 return 1 + operand.length; |
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 case kExprJITSingleFunction: { |
362 JITSingleFunctionOperand operand(this, pc); | |
363 return 1 + operand.length; | |
364 } | |
343 case kExprSetLocal: | 365 case kExprSetLocal: |
344 case kExprGetLocal: { | 366 case kExprGetLocal: { |
345 LocalIndexOperand operand(this, pc); | 367 LocalIndexOperand operand(this, pc); |
346 return 1 + operand.length; | 368 return 1 + operand.length; |
347 } | 369 } |
348 case kExprBrTable: { | 370 case kExprBrTable: { |
349 BranchTableOperand operand(this, pc); | 371 BranchTableOperand operand(this, pc); |
350 return 1 + operand.length; | 372 return 1 + operand.length; |
351 } | 373 } |
352 case kExprI32Const: { | 374 case kExprI32Const: { |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
989 CallImportOperand operand(this, pc_); | 1011 CallImportOperand operand(this, pc_); |
990 if (Validate(pc_, operand)) { | 1012 if (Validate(pc_, operand)) { |
991 TFNode** buffer = PopArgs(operand.sig); | 1013 TFNode** buffer = PopArgs(operand.sig); |
992 TFNode* call = | 1014 TFNode* call = |
993 BUILD(CallImport, operand.index, buffer, position()); | 1015 BUILD(CallImport, operand.index, buffer, position()); |
994 Push(GetReturnType(operand.sig), call); | 1016 Push(GetReturnType(operand.sig), call); |
995 } | 1017 } |
996 len = 1 + operand.length; | 1018 len = 1 + operand.length; |
997 break; | 1019 break; |
998 } | 1020 } |
1021 case kExprJITSingleFunction: { | |
1022 if (FLAG_wasm_jit_prototype) { | |
1023 JITSingleFunctionOperand operand(this, pc_); | |
1024 if (Validate(pc_, operand)) { | |
1025 Value index = Pop(2, kAstI32); | |
1026 Value length = Pop(1, kAstI32); | |
1027 Value base = Pop(0, kAstI32); | |
1028 TFNode* call = | |
1029 BUILD(JITSingleFunction, base.node, length.node, index.node, | |
1030 operand.sig_index, operand.sig); | |
1031 Push(kAstI32, call); | |
1032 break; | |
1033 } | |
1034 } | |
1035 } | |
999 default: | 1036 default: |
1000 error("Invalid opcode"); | 1037 error("Invalid opcode"); |
1001 return; | 1038 return; |
1002 } | 1039 } |
1003 } // end complex bytecode | 1040 } // end complex bytecode |
1004 | 1041 |
1005 #if DEBUG | 1042 #if DEBUG |
1006 if (FLAG_trace_wasm_decoder) { | 1043 if (FLAG_trace_wasm_decoder) { |
1007 for (size_t i = 0; i < stack_.size(); ++i) { | 1044 for (size_t i = 0; i < stack_.size(); ++i) { |
1008 Value& val = stack_[i]; | 1045 Value& val = stack_[i]; |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1613 } | 1650 } |
1614 case kExprCallFunction: { | 1651 case kExprCallFunction: { |
1615 CallFunctionOperand operand(&i, i.pc()); | 1652 CallFunctionOperand operand(&i, i.pc()); |
1616 if (decoder.Complete(i.pc(), operand)) { | 1653 if (decoder.Complete(i.pc(), operand)) { |
1617 os << " // function #" << operand.index << ": " << *operand.sig; | 1654 os << " // function #" << operand.index << ": " << *operand.sig; |
1618 } else { | 1655 } else { |
1619 os << " // arity=" << operand.arity << " function #" << operand.index; | 1656 os << " // arity=" << operand.arity << " function #" << operand.index; |
1620 } | 1657 } |
1621 break; | 1658 break; |
1622 } | 1659 } |
1660 case kExprJITSingleFunction: { | |
1661 JITSingleFunctionOperand operand(&i, i.pc()); | |
1662 if (decoder.Complete(i.pc(), operand)) { | |
1663 os << " // sig #" << operand.sig_index << ": " << *operand.sig; | |
1664 } | |
1665 break; | |
1666 } | |
1623 case kExprReturn: { | 1667 case kExprReturn: { |
1624 ReturnArityOperand operand(&i, i.pc()); | 1668 ReturnArityOperand operand(&i, i.pc()); |
1625 os << " // arity=" << operand.arity; | 1669 os << " // arity=" << operand.arity; |
1626 break; | 1670 break; |
1627 } | 1671 } |
1628 default: | 1672 default: |
1629 break; | 1673 break; |
1630 } | 1674 } |
1631 os << std::endl; | 1675 os << std::endl; |
1632 ++line_nr; | 1676 ++line_nr; |
1633 } | 1677 } |
1634 | 1678 |
1635 return decoder.ok(); | 1679 return decoder.ok(); |
1636 } | 1680 } |
1637 | 1681 |
1638 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 1682 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
1639 const byte* start, const byte* end) { | 1683 const byte* start, const byte* end) { |
1640 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 1684 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
1641 WasmFullDecoder decoder(zone, nullptr, body); | 1685 WasmFullDecoder decoder(zone, nullptr, body); |
1642 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); | 1686 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); |
1643 } | 1687 } |
1644 | 1688 |
1645 } // namespace wasm | 1689 } // namespace wasm |
1646 } // namespace internal | 1690 } // namespace internal |
1647 } // namespace v8 | 1691 } // namespace v8 |
OLD | NEW |