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/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/control-flow-builders.h" | 8 #include "src/interpreter/control-flow-builders.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 #include "src/parser.h" | 10 #include "src/parser.h" |
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 } | 1468 } |
1469 | 1469 |
1470 | 1470 |
1471 void BytecodeGenerator::VisitProperty(Property* expr) { | 1471 void BytecodeGenerator::VisitProperty(Property* expr) { |
1472 Register obj = VisitForRegisterValue(expr->obj()); | 1472 Register obj = VisitForRegisterValue(expr->obj()); |
1473 VisitPropertyLoad(obj, expr); | 1473 VisitPropertyLoad(obj, expr); |
1474 } | 1474 } |
1475 | 1475 |
1476 | 1476 |
1477 Register BytecodeGenerator::VisitArguments(ZoneList<Expression*>* args) { | 1477 Register BytecodeGenerator::VisitArguments(ZoneList<Expression*>* args) { |
| 1478 if (args->length() == 0) { |
| 1479 return Register(); |
| 1480 } |
| 1481 |
1478 // Visit arguments and place in a contiguous block of temporary | 1482 // Visit arguments and place in a contiguous block of temporary |
1479 // registers. Return the first temporary register corresponding to | 1483 // registers. Return the first temporary register corresponding to |
1480 // the first argument. | 1484 // the first argument. |
1481 // | 1485 // |
1482 // NB the caller may have already called | 1486 // NB the caller may have already called |
1483 // PrepareForConsecutiveAllocations() with args->length() + N. The | 1487 // PrepareForConsecutiveAllocations() with args->length() + N. The |
1484 // second call here will be a no-op provided there have been N or | 1488 // second call here will be a no-op provided there have been N or |
1485 // less calls to NextConsecutiveRegister(). Otherwise, the arguments | 1489 // less calls to NextConsecutiveRegister(). Otherwise, the arguments |
1486 // here will be consecutive, but they will not be consecutive with | 1490 // here will be consecutive, but they will not be consecutive with |
1487 // earlier consecutive allocations made by the caller. | 1491 // earlier consecutive allocations made by the caller. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 case Call::NAMED_SUPER_PROPERTY_CALL: | 1551 case Call::NAMED_SUPER_PROPERTY_CALL: |
1548 case Call::KEYED_SUPER_PROPERTY_CALL: | 1552 case Call::KEYED_SUPER_PROPERTY_CALL: |
1549 case Call::LOOKUP_SLOT_CALL: | 1553 case Call::LOOKUP_SLOT_CALL: |
1550 case Call::SUPER_CALL: | 1554 case Call::SUPER_CALL: |
1551 case Call::POSSIBLY_EVAL_CALL: | 1555 case Call::POSSIBLY_EVAL_CALL: |
1552 UNIMPLEMENTED(); | 1556 UNIMPLEMENTED(); |
1553 } | 1557 } |
1554 | 1558 |
1555 // Evaluate all arguments to the function call and store in sequential | 1559 // Evaluate all arguments to the function call and store in sequential |
1556 // registers. | 1560 // registers. |
1557 if (args->length() > 0) { | 1561 Register arg = VisitArguments(args); |
1558 Register arg = VisitArguments(args); | 1562 CHECK(args->length() == 0 || arg.index() == receiver.index() + 1); |
1559 CHECK(arg.index() == receiver.index() + 1); | |
1560 } | |
1561 | 1563 |
1562 // TODO(rmcilroy): Deal with possible direct eval here? | 1564 // TODO(rmcilroy): Deal with possible direct eval here? |
1563 // TODO(rmcilroy): Use CallIC to allow call type feedback. | 1565 // TODO(rmcilroy): Use CallIC to allow call type feedback. |
1564 builder()->Call(callee, receiver, args->length()); | 1566 builder()->Call(callee, receiver, args->length()); |
1565 execution_result()->SetResultInAccumulator(); | 1567 execution_result()->SetResultInAccumulator(); |
1566 } | 1568 } |
1567 | 1569 |
1568 | 1570 |
1569 void BytecodeGenerator::VisitCallNew(CallNew* expr) { | 1571 void BytecodeGenerator::VisitCallNew(CallNew* expr) { |
1570 Register constructor = execution_result()->NewRegister(); | 1572 Register constructor = execution_result()->NewRegister(); |
1571 VisitForAccumulatorValue(expr->expression()); | 1573 VisitForAccumulatorValue(expr->expression()); |
1572 builder()->StoreAccumulatorInRegister(constructor); | 1574 builder()->StoreAccumulatorInRegister(constructor); |
1573 | 1575 |
1574 ZoneList<Expression*>* args = expr->arguments(); | 1576 ZoneList<Expression*>* args = expr->arguments(); |
1575 if (args->length() > 0) { | 1577 Register first_arg = VisitArguments(args); |
1576 Register first_arg = VisitArguments(args); | 1578 builder()->New(constructor, first_arg, args->length()); |
1577 builder()->New(constructor, first_arg, args->length()); | |
1578 } else { | |
1579 // The second argument here will be ignored as there are zero | |
1580 // arguments. Using the constructor register avoids avoid | |
1581 // allocating a temporary just to fill the operands. | |
1582 builder()->New(constructor, constructor, 0); | |
1583 } | |
1584 execution_result()->SetResultInAccumulator(); | 1579 execution_result()->SetResultInAccumulator(); |
1585 } | 1580 } |
1586 | 1581 |
1587 | 1582 |
1588 void BytecodeGenerator::VisitCallRuntime(CallRuntime* expr) { | 1583 void BytecodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
| 1584 ZoneList<Expression*>* args = expr->arguments(); |
| 1585 Register receiver; |
1589 if (expr->is_jsruntime()) { | 1586 if (expr->is_jsruntime()) { |
1590 UNIMPLEMENTED(); | 1587 // Allocate a register for the receiver and load it with undefined. |
| 1588 execution_result()->PrepareForConsecutiveAllocations(args->length() + 1); |
| 1589 receiver = execution_result()->NextConsecutiveRegister(); |
| 1590 builder()->LoadUndefined().StoreAccumulatorInRegister(receiver); |
1591 } | 1591 } |
| 1592 // Evaluate all arguments to the runtime call. |
| 1593 Register first_arg = VisitArguments(args); |
1592 | 1594 |
1593 // TODO(rmcilroy): support multiple return values. | 1595 if (expr->is_jsruntime()) { |
1594 DCHECK_LE(expr->function()->result_size, 1); | 1596 DCHECK(args->length() == 0 || first_arg.index() == receiver.index() + 1); |
1595 Runtime::FunctionId function_id = expr->function()->function_id; | 1597 builder()->CallJSRuntime(expr->context_index(), receiver, args->length()); |
1596 | |
1597 // Evaluate all arguments to the runtime call. | |
1598 ZoneList<Expression*>* args = expr->arguments(); | |
1599 Register first_arg; | |
1600 if (args->length() > 0) { | |
1601 first_arg = VisitArguments(args); | |
1602 } else { | 1598 } else { |
1603 // Allocation here is just to fullfil the requirement that there | 1599 // TODO(rmcilroy): support multiple return values. |
1604 // is a register operand for the start of the arguments though | 1600 DCHECK_LE(expr->function()->result_size, 1); |
1605 // there are zero when this is generated. | 1601 Runtime::FunctionId function_id = expr->function()->function_id; |
1606 first_arg = execution_result()->NewRegister(); | 1602 builder()->CallRuntime(function_id, first_arg, args->length()); |
1607 } | 1603 } |
1608 builder()->CallRuntime(function_id, first_arg, args->length()); | |
1609 execution_result()->SetResultInAccumulator(); | 1604 execution_result()->SetResultInAccumulator(); |
1610 } | 1605 } |
1611 | 1606 |
1612 | 1607 |
1613 void BytecodeGenerator::VisitVoid(UnaryOperation* expr) { | 1608 void BytecodeGenerator::VisitVoid(UnaryOperation* expr) { |
1614 VisitForEffect(expr->expression()); | 1609 VisitForEffect(expr->expression()); |
1615 builder()->LoadUndefined(); | 1610 builder()->LoadUndefined(); |
1616 execution_result()->SetResultInAccumulator(); | 1611 execution_result()->SetResultInAccumulator(); |
1617 } | 1612 } |
1618 | 1613 |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2168 } | 2163 } |
2169 | 2164 |
2170 | 2165 |
2171 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 2166 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
2172 return info()->feedback_vector()->GetIndex(slot); | 2167 return info()->feedback_vector()->GetIndex(slot); |
2173 } | 2168 } |
2174 | 2169 |
2175 } // namespace interpreter | 2170 } // namespace interpreter |
2176 } // namespace internal | 2171 } // namespace internal |
2177 } // namespace v8 | 2172 } // namespace v8 |
OLD | NEW |