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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 if (count == 0) { | 711 if (count == 0) { |
712 BUILD(Return, 0, builder_->Buffer(0)); | 712 BUILD(Return, 0, builder_->Buffer(0)); |
713 ssa_env_->Kill(); | 713 ssa_env_->Kill(); |
714 Leaf(kAstEnd); | 714 Leaf(kAstEnd); |
715 } else { | 715 } else { |
716 Shift(kAstEnd, count); | 716 Shift(kAstEnd, count); |
717 } | 717 } |
718 break; | 718 break; |
719 } | 719 } |
720 case kExprUnreachable: { | 720 case kExprUnreachable: { |
| 721 // TODO(clemensh): add source position for unreachable |
721 BUILD0(Unreachable); | 722 BUILD0(Unreachable); |
722 ssa_env_->Kill(SsaEnv::kControlEnd); | 723 ssa_env_->Kill(SsaEnv::kControlEnd); |
723 Leaf(kAstEnd, nullptr); | 724 Leaf(kAstEnd, nullptr); |
724 break; | 725 break; |
725 } | 726 } |
726 case kExprI8Const: { | 727 case kExprI8Const: { |
727 ImmI8Operand operand(this, pc_); | 728 ImmI8Operand operand(this, pc_); |
728 Leaf(kAstI32, BUILD(Int32Constant, operand.value)); | 729 Leaf(kAstI32, BUILD(Int32Constant, operand.value)); |
729 len = 1 + operand.length; | 730 len = 1 + operand.length; |
730 break; | 731 break; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 TypeCheckLast(p, sig->GetParam(p->index - 1)); | 948 TypeCheckLast(p, sig->GetParam(p->index - 1)); |
948 if (p->done() && build()) { | 949 if (p->done() && build()) { |
949 if (sig->parameter_count() == 2) { | 950 if (sig->parameter_count() == 2) { |
950 p->tree->node = builder_->Binop(opcode, p->tree->children[0]->node, | 951 p->tree->node = builder_->Binop(opcode, p->tree->children[0]->node, |
951 p->tree->children[1]->node); | 952 p->tree->children[1]->node); |
952 } else if (sig->parameter_count() == 1) { | 953 } else if (sig->parameter_count() == 1) { |
953 p->tree->node = builder_->Unop(opcode, p->tree->children[0]->node); | 954 p->tree->node = builder_->Unop(opcode, p->tree->children[0]->node); |
954 } else { | 955 } else { |
955 UNREACHABLE(); | 956 UNREACHABLE(); |
956 } | 957 } |
| 958 if (IsSimpleOpTrapping(p->opcode())) AddSourcePosition(p); |
957 } | 959 } |
958 return; | 960 return; |
959 } | 961 } |
960 | 962 |
961 switch (opcode) { | 963 switch (opcode) { |
962 case kExprBlock: { | 964 case kExprBlock: { |
963 if (p->done()) { | 965 if (p->done()) { |
964 Block* last = &blocks_.back(); | 966 Block* last = &blocks_.back(); |
965 DCHECK_EQ(stack_.size() - 1, last->stack_depth); | 967 DCHECK_EQ(stack_.size() - 1, last->stack_depth); |
966 // fallthrough with the last expression. | 968 // fallthrough with the last expression. |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 TypeCheckLast(p, operand.sig->GetParam(p->index - 1)); | 1230 TypeCheckLast(p, operand.sig->GetParam(p->index - 1)); |
1229 } | 1231 } |
1230 if (p->done() && build()) { | 1232 if (p->done() && build()) { |
1231 uint32_t count = p->tree->count + 1; | 1233 uint32_t count = p->tree->count + 1; |
1232 TFNode** buffer = builder_->Buffer(count); | 1234 TFNode** buffer = builder_->Buffer(count); |
1233 buffer[0] = nullptr; // reserved for code object. | 1235 buffer[0] = nullptr; // reserved for code object. |
1234 for (uint32_t i = 1; i < count; i++) { | 1236 for (uint32_t i = 1; i < count; i++) { |
1235 buffer[i] = p->tree->children[i - 1]->node; | 1237 buffer[i] = p->tree->children[i - 1]->node; |
1236 } | 1238 } |
1237 p->tree->node = builder_->CallDirect(operand.index, buffer); | 1239 p->tree->node = builder_->CallDirect(operand.index, buffer); |
| 1240 AddSourcePosition(p); |
1238 } | 1241 } |
1239 break; | 1242 break; |
1240 } | 1243 } |
1241 case kExprCallIndirect: { | 1244 case kExprCallIndirect: { |
1242 SignatureIndexOperand operand(this, p->pc()); | 1245 SignatureIndexOperand operand(this, p->pc()); |
1243 CHECK(Validate(p->pc(), operand)); | 1246 CHECK(Validate(p->pc(), operand)); |
1244 if (p->index == 1) { | 1247 if (p->index == 1) { |
1245 TypeCheckLast(p, kAstI32); | 1248 TypeCheckLast(p, kAstI32); |
1246 } else { | 1249 } else { |
1247 TypeCheckLast(p, operand.sig->GetParam(p->index - 2)); | 1250 TypeCheckLast(p, operand.sig->GetParam(p->index - 2)); |
1248 } | 1251 } |
1249 if (p->done() && build()) { | 1252 if (p->done() && build()) { |
1250 uint32_t count = p->tree->count; | 1253 uint32_t count = p->tree->count; |
1251 TFNode** buffer = builder_->Buffer(count); | 1254 TFNode** buffer = builder_->Buffer(count); |
1252 for (uint32_t i = 0; i < count; i++) { | 1255 for (uint32_t i = 0; i < count; i++) { |
1253 buffer[i] = p->tree->children[i]->node; | 1256 buffer[i] = p->tree->children[i]->node; |
1254 } | 1257 } |
1255 p->tree->node = builder_->CallIndirect(operand.index, buffer); | 1258 p->tree->node = builder_->CallIndirect(operand.index, buffer); |
| 1259 AddSourcePosition(p); |
1256 } | 1260 } |
1257 break; | 1261 break; |
1258 } | 1262 } |
1259 case kExprCallImport: { | 1263 case kExprCallImport: { |
1260 ImportIndexOperand operand(this, p->pc()); | 1264 ImportIndexOperand operand(this, p->pc()); |
1261 CHECK(Validate(p->pc(), operand)); | 1265 CHECK(Validate(p->pc(), operand)); |
1262 if (p->index > 0) { | 1266 if (p->index > 0) { |
1263 TypeCheckLast(p, operand.sig->GetParam(p->index - 1)); | 1267 TypeCheckLast(p, operand.sig->GetParam(p->index - 1)); |
1264 } | 1268 } |
1265 if (p->done() && build()) { | 1269 if (p->done() && build()) { |
1266 uint32_t count = p->tree->count + 1; | 1270 uint32_t count = p->tree->count + 1; |
1267 TFNode** buffer = builder_->Buffer(count); | 1271 TFNode** buffer = builder_->Buffer(count); |
1268 buffer[0] = nullptr; // reserved for code object. | 1272 buffer[0] = nullptr; // reserved for code object. |
1269 for (uint32_t i = 1; i < count; i++) { | 1273 for (uint32_t i = 1; i < count; i++) { |
1270 buffer[i] = p->tree->children[i - 1]->node; | 1274 buffer[i] = p->tree->children[i - 1]->node; |
1271 } | 1275 } |
1272 p->tree->node = builder_->CallImport(operand.index, buffer); | 1276 p->tree->node = builder_->CallImport(operand.index, buffer); |
| 1277 AddSourcePosition(p); |
1273 } | 1278 } |
1274 break; | 1279 break; |
1275 } | 1280 } |
1276 default: | 1281 default: |
1277 break; | 1282 break; |
1278 } | 1283 } |
1279 } | 1284 } |
1280 | 1285 |
1281 void ReduceBreakToExprBlock(Production* p, Block* block) { | 1286 void ReduceBreakToExprBlock(Production* p, Block* block) { |
1282 ReduceBreakToExprBlock(p, block, p->tree->count > 0 ? p->last() : nullptr); | 1287 ReduceBreakToExprBlock(p, block, p->tree->count > 0 ? p->last() : nullptr); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 } | 1323 } |
1319 } | 1324 } |
1320 | 1325 |
1321 void ReduceLoadMem(Production* p, LocalType type, MachineType mem_type) { | 1326 void ReduceLoadMem(Production* p, LocalType type, MachineType mem_type) { |
1322 DCHECK_EQ(1, p->index); | 1327 DCHECK_EQ(1, p->index); |
1323 TypeCheckLast(p, kAstI32); // index | 1328 TypeCheckLast(p, kAstI32); // index |
1324 if (build()) { | 1329 if (build()) { |
1325 MemoryAccessOperand operand(this, p->pc()); | 1330 MemoryAccessOperand operand(this, p->pc()); |
1326 p->tree->node = | 1331 p->tree->node = |
1327 builder_->LoadMem(type, mem_type, p->last()->node, operand.offset); | 1332 builder_->LoadMem(type, mem_type, p->last()->node, operand.offset); |
| 1333 AddSourcePosition(p); |
1328 } | 1334 } |
1329 } | 1335 } |
1330 | 1336 |
1331 void ReduceStoreMem(Production* p, LocalType type, MachineType mem_type) { | 1337 void ReduceStoreMem(Production* p, LocalType type, MachineType mem_type) { |
1332 if (p->index == 1) { | 1338 if (p->index == 1) { |
1333 TypeCheckLast(p, kAstI32); // index | 1339 TypeCheckLast(p, kAstI32); // index |
1334 } else { | 1340 } else { |
1335 DCHECK_EQ(2, p->index); | 1341 DCHECK_EQ(2, p->index); |
1336 TypeCheckLast(p, type); | 1342 TypeCheckLast(p, type); |
1337 if (build()) { | 1343 if (build()) { |
1338 MemoryAccessOperand operand(this, p->pc()); | 1344 MemoryAccessOperand operand(this, p->pc()); |
1339 TFNode* val = p->tree->children[1]->node; | 1345 TFNode* val = p->tree->children[1]->node; |
1340 builder_->StoreMem(mem_type, p->tree->children[0]->node, operand.offset, | 1346 builder_->StoreMem(mem_type, p->tree->children[0]->node, operand.offset, |
1341 val); | 1347 val); |
1342 p->tree->node = val; | 1348 p->tree->node = val; |
| 1349 AddSourcePosition(p); |
1343 } | 1350 } |
1344 } | 1351 } |
1345 } | 1352 } |
1346 | 1353 |
1347 void TypeCheckLast(Production* p, LocalType expected) { | 1354 void TypeCheckLast(Production* p, LocalType expected) { |
1348 LocalType result = p->last()->type; | 1355 LocalType result = p->last()->type; |
1349 if (result == expected) return; | 1356 if (result == expected) return; |
1350 if (result == kAstEnd) return; | 1357 if (result == kAstEnd) return; |
1351 if (expected != kAstStmt) { | 1358 if (expected != kAstStmt) { |
1352 error(p->pc(), p->last()->pc, | 1359 error(p->pc(), p->last()->pc, |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1624 pc += length; | 1631 pc += length; |
1625 arity_stack.push_back(arity); | 1632 arity_stack.push_back(arity); |
1626 while (arity_stack.back() == 0) { | 1633 while (arity_stack.back() == 0) { |
1627 arity_stack.pop_back(); | 1634 arity_stack.pop_back(); |
1628 if (arity_stack.empty()) return assigned; // reached end of loop | 1635 if (arity_stack.empty()) return assigned; // reached end of loop |
1629 arity_stack.back()--; | 1636 arity_stack.back()--; |
1630 } | 1637 } |
1631 } | 1638 } |
1632 return assigned; | 1639 return assigned; |
1633 } | 1640 } |
| 1641 |
| 1642 void AddSourcePosition(Production* p) { |
| 1643 DCHECK_NOT_NULL(p->tree->node); |
| 1644 AddSourcePosition(p->tree->node, p->pc()); |
| 1645 } |
| 1646 |
| 1647 void AddSourcePosition(TFNode* node, const byte* pc) { |
| 1648 int offset = static_cast<int>(pc - start_); |
| 1649 DCHECK_EQ(pc - start_, offset); // overflows cannot happen |
| 1650 builder_->SetSourcePosition(node, offset); |
| 1651 } |
| 1652 |
| 1653 bool IsSimpleOpTrapping(WasmOpcode opcode) { |
| 1654 switch (opcode) { |
| 1655 #define V(name) case WasmOpcode::kExpr##name: |
| 1656 FOREACH_SIMPLE_TRAPPING_OPCODE(V) |
| 1657 #undef V |
| 1658 return true; |
| 1659 default: |
| 1660 return false; |
| 1661 } |
| 1662 } |
1634 }; | 1663 }; |
1635 | 1664 |
1636 bool DecodeLocalDecls(AstLocalDecls& decls, const byte* start, | 1665 bool DecodeLocalDecls(AstLocalDecls& decls, const byte* start, |
1637 const byte* end) { | 1666 const byte* end) { |
1638 base::AccountingAllocator allocator; | 1667 base::AccountingAllocator allocator; |
1639 Zone tmp(&allocator); | 1668 Zone tmp(&allocator); |
1640 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 1669 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
1641 SR_WasmDecoder decoder(&tmp, nullptr, body); | 1670 SR_WasmDecoder decoder(&tmp, nullptr, body); |
1642 return decoder.DecodeLocalDecls(decls); | 1671 return decoder.DecodeLocalDecls(decls); |
1643 } | 1672 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1776 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 1805 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
1777 const byte* start, const byte* end) { | 1806 const byte* start, const byte* end) { |
1778 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 1807 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
1779 SR_WasmDecoder decoder(zone, nullptr, body); | 1808 SR_WasmDecoder decoder(zone, nullptr, body); |
1780 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); | 1809 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); |
1781 } | 1810 } |
1782 | 1811 |
1783 } // namespace wasm | 1812 } // namespace wasm |
1784 } // namespace internal | 1813 } // namespace internal |
1785 } // namespace v8 | 1814 } // namespace v8 |
OLD | NEW |