Chromium Code Reviews| 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 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1435 } | 1435 } |
| 1436 | 1436 |
| 1437 | 1437 |
| 1438 void BytecodeGenerator::VisitProperty(Property* expr) { | 1438 void BytecodeGenerator::VisitProperty(Property* expr) { |
| 1439 Register obj = VisitForRegisterValue(expr->obj()); | 1439 Register obj = VisitForRegisterValue(expr->obj()); |
| 1440 VisitPropertyLoad(obj, expr); | 1440 VisitPropertyLoad(obj, expr); |
| 1441 } | 1441 } |
| 1442 | 1442 |
| 1443 | 1443 |
| 1444 Register BytecodeGenerator::VisitArguments(ZoneList<Expression*>* args) { | 1444 Register BytecodeGenerator::VisitArguments(ZoneList<Expression*>* args) { |
| 1445 if (args->length() == 0) { | |
| 1446 return Register(); | |
| 1447 } | |
| 1448 | |
| 1445 // Visit arguments and place in a contiguous block of temporary | 1449 // Visit arguments and place in a contiguous block of temporary |
| 1446 // registers. Return the first temporary register corresponding to | 1450 // registers. Return the first temporary register corresponding to |
| 1447 // the first argument. | 1451 // the first argument. |
| 1448 // | 1452 // |
| 1449 // NB the caller may have already called | 1453 // NB the caller may have already called |
| 1450 // PrepareForConsecutiveAllocations() with args->length() + N. The | 1454 // PrepareForConsecutiveAllocations() with args->length() + N. The |
| 1451 // second call here will be a no-op provided there have been N or | 1455 // second call here will be a no-op provided there have been N or |
| 1452 // less calls to NextConsecutiveRegister(). Otherwise, the arguments | 1456 // less calls to NextConsecutiveRegister(). Otherwise, the arguments |
| 1453 // here will be consecutive, but they will not be consecutive with | 1457 // here will be consecutive, but they will not be consecutive with |
| 1454 // earlier consecutive allocations made by the caller. | 1458 // earlier consecutive allocations made by the caller. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1514 case Call::NAMED_SUPER_PROPERTY_CALL: | 1518 case Call::NAMED_SUPER_PROPERTY_CALL: |
| 1515 case Call::KEYED_SUPER_PROPERTY_CALL: | 1519 case Call::KEYED_SUPER_PROPERTY_CALL: |
| 1516 case Call::LOOKUP_SLOT_CALL: | 1520 case Call::LOOKUP_SLOT_CALL: |
| 1517 case Call::SUPER_CALL: | 1521 case Call::SUPER_CALL: |
| 1518 case Call::POSSIBLY_EVAL_CALL: | 1522 case Call::POSSIBLY_EVAL_CALL: |
| 1519 UNIMPLEMENTED(); | 1523 UNIMPLEMENTED(); |
| 1520 } | 1524 } |
| 1521 | 1525 |
| 1522 // Evaluate all arguments to the function call and store in sequential | 1526 // Evaluate all arguments to the function call and store in sequential |
| 1523 // registers. | 1527 // registers. |
| 1524 if (args->length() > 0) { | 1528 Register arg = VisitArguments(args); |
| 1525 Register arg = VisitArguments(args); | 1529 CHECK(args->length() == 0 || arg.index() == receiver.index() + 1); |
| 1526 CHECK(arg.index() == receiver.index() + 1); | |
| 1527 } | |
| 1528 | 1530 |
| 1529 // TODO(rmcilroy): Deal with possible direct eval here? | 1531 // TODO(rmcilroy): Deal with possible direct eval here? |
| 1530 // TODO(rmcilroy): Use CallIC to allow call type feedback. | 1532 // TODO(rmcilroy): Use CallIC to allow call type feedback. |
| 1531 builder()->Call(callee, receiver, args->length()); | 1533 builder()->Call(callee, receiver, args->length()); |
| 1532 execution_result()->SetResultInAccumulator(); | 1534 execution_result()->SetResultInAccumulator(); |
| 1533 } | 1535 } |
| 1534 | 1536 |
| 1535 | 1537 |
| 1536 void BytecodeGenerator::VisitCallNew(CallNew* expr) { | 1538 void BytecodeGenerator::VisitCallNew(CallNew* expr) { |
| 1537 Register constructor = execution_result()->NewRegister(); | 1539 Register constructor = execution_result()->NewRegister(); |
| 1538 VisitForAccumulatorValue(expr->expression()); | 1540 VisitForAccumulatorValue(expr->expression()); |
| 1539 builder()->StoreAccumulatorInRegister(constructor); | 1541 builder()->StoreAccumulatorInRegister(constructor); |
| 1540 | 1542 |
| 1541 ZoneList<Expression*>* args = expr->arguments(); | 1543 ZoneList<Expression*>* args = expr->arguments(); |
| 1542 if (args->length() > 0) { | 1544 Register first_arg = VisitArguments(args); |
| 1543 Register first_arg = VisitArguments(args); | 1545 builder()->New(constructor, first_arg, args->length()); |
| 1544 builder()->New(constructor, first_arg, args->length()); | |
| 1545 } else { | |
| 1546 // The second argument here will be ignored as there are zero | |
| 1547 // arguments. Using the constructor register avoids avoid | |
| 1548 // allocating a temporary just to fill the operands. | |
| 1549 builder()->New(constructor, constructor, 0); | |
| 1550 } | |
| 1551 execution_result()->SetResultInAccumulator(); | 1546 execution_result()->SetResultInAccumulator(); |
| 1552 } | 1547 } |
| 1553 | 1548 |
| 1554 | 1549 |
| 1555 void BytecodeGenerator::VisitCallRuntime(CallRuntime* expr) { | 1550 void BytecodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
| 1551 ZoneList<Expression*>* args = expr->arguments(); | |
| 1552 Register receiver; | |
| 1556 if (expr->is_jsruntime()) { | 1553 if (expr->is_jsruntime()) { |
| 1557 UNIMPLEMENTED(); | 1554 // Allocate a register for the receiver and load it with undefined. |
| 1555 execution_result()->PrepareForConsecutiveAllocations(args->length() + 1); | |
| 1556 receiver = execution_result()->NextConsecutiveRegister(); | |
| 1557 builder()->LoadUndefined().StoreAccumulatorInRegister(receiver); | |
| 1558 } | 1558 } |
| 1559 // Evaluate all arguments to the runtime call. | |
| 1560 Register first_arg = VisitArguments(args); | |
| 1559 | 1561 |
| 1560 // TODO(rmcilroy): support multiple return values. | 1562 if (expr->is_jsruntime()) { |
| 1561 DCHECK_LE(expr->function()->result_size, 1); | 1563 DCHECK(args->length() == 0 || first_arg.index() == receiver.index() + 1); |
| 1562 Runtime::FunctionId function_id = expr->function()->function_id; | 1564 builder()->CallJSRuntime(expr->context_index(), receiver, args->length()); |
| 1563 | |
| 1564 // Evaluate all arguments to the runtime call. | |
| 1565 ZoneList<Expression*>* args = expr->arguments(); | |
| 1566 Register first_arg; | |
| 1567 if (args->length() > 0) { | |
| 1568 first_arg = VisitArguments(args); | |
| 1569 } else { | 1565 } else { |
| 1570 // Allocation here is just to fullfil the requirement that there | 1566 // TODO(rmcilroy): support multiple return values. |
| 1571 // is a register operand for the start of the arguments though | 1567 DCHECK_LE(expr->function()->result_size, 1); |
| 1572 // there are zero when this is generated. | 1568 Runtime::FunctionId function_id = expr->function()->function_id; |
| 1573 first_arg = execution_result()->NewRegister(); | 1569 builder()->CallRuntime(function_id, first_arg, args->length()); |
|
oth
2015/11/02 10:49:58
This may be the only spot that requires an uncheck
rmcilroy
2015/11/03 17:10:47
There are two spots which need this - CallRuntime
| |
| 1574 } | 1570 } |
| 1575 builder()->CallRuntime(function_id, first_arg, args->length()); | |
| 1576 execution_result()->SetResultInAccumulator(); | 1571 execution_result()->SetResultInAccumulator(); |
| 1577 } | 1572 } |
| 1578 | 1573 |
| 1579 | 1574 |
| 1580 void BytecodeGenerator::VisitVoid(UnaryOperation* expr) { | 1575 void BytecodeGenerator::VisitVoid(UnaryOperation* expr) { |
| 1581 VisitForEffect(expr->expression()); | 1576 VisitForEffect(expr->expression()); |
| 1582 builder()->LoadUndefined(); | 1577 builder()->LoadUndefined(); |
| 1583 execution_result()->SetResultInAccumulator(); | 1578 execution_result()->SetResultInAccumulator(); |
| 1584 } | 1579 } |
| 1585 | 1580 |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2129 } | 2124 } |
| 2130 | 2125 |
| 2131 | 2126 |
| 2132 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 2127 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
| 2133 return info()->feedback_vector()->GetIndex(slot); | 2128 return info()->feedback_vector()->GetIndex(slot); |
| 2134 } | 2129 } |
| 2135 | 2130 |
| 2136 } // namespace interpreter | 2131 } // namespace interpreter |
| 2137 } // namespace internal | 2132 } // namespace internal |
| 2138 } // namespace v8 | 2133 } // namespace v8 |
| OLD | NEW |