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/ast/compile-time-value.h" | 7 #include "src/ast/compile-time-value.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-info.h" | 10 #include "src/compilation-info.h" |
(...skipping 2468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2479 RegisterAllocationScope register_scope(this); | 2479 RegisterAllocationScope register_scope(this); |
2480 SuperCallReference* super = expr->expression()->AsSuperCallReference(); | 2480 SuperCallReference* super = expr->expression()->AsSuperCallReference(); |
2481 | 2481 |
2482 // Prepare the constructor to the super call. | 2482 // Prepare the constructor to the super call. |
2483 Register this_function = VisitForRegisterValue(super->this_function_var()); | 2483 Register this_function = VisitForRegisterValue(super->this_function_var()); |
2484 builder()->CallRuntime(Runtime::kInlineGetSuperConstructor, this_function); | 2484 builder()->CallRuntime(Runtime::kInlineGetSuperConstructor, this_function); |
2485 | 2485 |
2486 Register constructor = this_function; // Re-use dead this_function register. | 2486 Register constructor = this_function; // Re-use dead this_function register. |
2487 builder()->StoreAccumulatorInRegister(constructor); | 2487 builder()->StoreAccumulatorInRegister(constructor); |
2488 | 2488 |
2489 RegisterList args = | 2489 ZoneList<Expression*>* args = expr->arguments(); |
2490 register_allocator()->NewRegisterList(expr->arguments()->length()); | |
2491 VisitArguments(expr->arguments(), args); | |
2492 | 2490 |
2493 // The new target is loaded into the accumulator from the | 2491 bool has_spread = false; |
2494 // {new.target} variable. | 2492 for (int i = 0; i < args->length(); i++) { |
2495 VisitForAccumulatorValue(super->new_target_var()); | 2493 if (args->at(i)->IsSpread()) has_spread = true; |
2494 } | |
2496 | 2495 |
2497 // Call construct. | 2496 if (has_spread) { |
2498 builder()->SetExpressionPosition(expr); | 2497 // Deal with the spread arg. |
rmcilroy
2016/11/30 14:35:32
nit - Prepare the spread arguments. ?
petermarshall
2016/11/30 15:24:48
Done
| |
2499 // TODO(turbofan): For now we do gather feedback on super constructor | 2498 RegisterList spread_prepare_args = |
2500 // calls, utilizing the existing machinery to inline the actual call | 2499 register_allocator()->NewRegisterList(args->length()); |
2501 // target and the JSCreate for the implicit receiver allocation. This | 2500 VisitArguments(args, spread_prepare_args); |
2502 // is not an ideal solution for super constructor calls, but it gets | 2501 |
2503 // the job done for now. In the long run we might want to revisit this | 2502 Runtime::FunctionId function_id = Runtime::kSpreadIterablePrepareVarargs; |
rmcilroy
2016/11/30 14:35:32
nit - no need for the function_id variable now
petermarshall
2016/11/30 15:24:48
Done
| |
2504 // and come up with a better way. | 2503 builder()->CallRuntime(function_id, spread_prepare_args); |
2505 int const feedback_slot_index = feedback_index(expr->CallFeedbackICSlot()); | 2504 |
2506 builder()->New(constructor, args, feedback_slot_index); | 2505 // Do ReflectConstruct. |
rmcilroy
2016/11/30 14:35:32
nit - Call ReflectConstruct to do the actual super
petermarshall
2016/11/30 15:24:48
Done.
| |
2506 RegisterList reflect_construct_args = | |
2507 register_allocator()->NewRegisterList(4); | |
2508 builder()->StoreAccumulatorInRegister(reflect_construct_args[2]); | |
2509 Register receiver = reflect_construct_args[0]; | |
rmcilroy
2016/11/30 14:35:32
nit - I'd prefer that the code just consistently u
petermarshall
2016/11/30 15:24:48
Done
| |
2510 builder()->LoadUndefined().StoreAccumulatorInRegister(receiver); | |
2511 builder()->MoveRegister(constructor, reflect_construct_args[1]); | |
2512 VisitForRegisterValue(super->new_target_var(), reflect_construct_args[3]); | |
2513 builder()->CallJSRuntime(Context::REFLECT_CONSTRUCT_INDEX, | |
2514 reflect_construct_args); | |
2515 } else { | |
2516 RegisterList args_regs = | |
2517 register_allocator()->NewRegisterList(args->length()); | |
2518 VisitArguments(args, args_regs); | |
2519 // The new target is loaded into the accumulator from the | |
2520 // {new.target} variable. | |
2521 VisitForAccumulatorValue(super->new_target_var()); | |
2522 | |
2523 // Call construct. | |
2524 builder()->SetExpressionPosition(expr); | |
2525 // TODO(turbofan): For now we do gather feedback on super constructor | |
2526 // calls, utilizing the existing machinery to inline the actual call | |
2527 // target and the JSCreate for the implicit receiver allocation. This | |
2528 // is not an ideal solution for super constructor calls, but it gets | |
2529 // the job done for now. In the long run we might want to revisit this | |
2530 // and come up with a better way. | |
2531 int const feedback_slot_index = feedback_index(expr->CallFeedbackICSlot()); | |
2532 builder()->New(constructor, args_regs, feedback_slot_index); | |
2533 } | |
2507 } | 2534 } |
2508 | 2535 |
2509 void BytecodeGenerator::VisitCallNew(CallNew* expr) { | 2536 void BytecodeGenerator::VisitCallNew(CallNew* expr) { |
2510 Register constructor = VisitForRegisterValue(expr->expression()); | 2537 Register constructor = VisitForRegisterValue(expr->expression()); |
2511 RegisterList args = | 2538 RegisterList args = |
2512 register_allocator()->NewRegisterList(expr->arguments()->length()); | 2539 register_allocator()->NewRegisterList(expr->arguments()->length()); |
2513 VisitArguments(expr->arguments(), args); | 2540 VisitArguments(expr->arguments(), args); |
2514 | 2541 |
2515 builder()->SetExpressionPosition(expr); | 2542 builder()->SetExpressionPosition(expr); |
2516 // The accumulator holds new target which is the same as the | 2543 // The accumulator holds new target which is the same as the |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2804 | 2831 |
2805 void BytecodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) { | 2832 void BytecodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) { |
2806 // TODO(rmcilroy): Special case "x * 1.0" and "x * -1" which are generated for | 2833 // TODO(rmcilroy): Special case "x * 1.0" and "x * -1" which are generated for |
2807 // +x and -x by the parser. | 2834 // +x and -x by the parser. |
2808 Register lhs = VisitForRegisterValue(expr->left()); | 2835 Register lhs = VisitForRegisterValue(expr->left()); |
2809 VisitForAccumulatorValue(expr->right()); | 2836 VisitForAccumulatorValue(expr->right()); |
2810 FeedbackVectorSlot slot = expr->BinaryOperationFeedbackSlot(); | 2837 FeedbackVectorSlot slot = expr->BinaryOperationFeedbackSlot(); |
2811 builder()->BinaryOperation(expr->op(), lhs, feedback_index(slot)); | 2838 builder()->BinaryOperation(expr->op(), lhs, feedback_index(slot)); |
2812 } | 2839 } |
2813 | 2840 |
2814 void BytecodeGenerator::VisitSpread(Spread* expr) { UNREACHABLE(); } | 2841 void BytecodeGenerator::VisitSpread(Spread* expr) { Visit(expr->expression()); } |
2815 | 2842 |
2816 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { | 2843 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { |
2817 UNREACHABLE(); | 2844 UNREACHABLE(); |
2818 } | 2845 } |
2819 | 2846 |
2820 void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) { | 2847 void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) { |
2821 builder()->LoadAccumulatorWithRegister(Register::function_closure()); | 2848 builder()->LoadAccumulatorWithRegister(Register::function_closure()); |
2822 } | 2849 } |
2823 | 2850 |
2824 void BytecodeGenerator::VisitSuperCallReference(SuperCallReference* expr) { | 2851 void BytecodeGenerator::VisitSuperCallReference(SuperCallReference* expr) { |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3196 } | 3223 } |
3197 | 3224 |
3198 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { | 3225 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { |
3199 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | 3226 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict |
3200 : Runtime::kStoreKeyedToSuper_Sloppy; | 3227 : Runtime::kStoreKeyedToSuper_Sloppy; |
3201 } | 3228 } |
3202 | 3229 |
3203 } // namespace interpreter | 3230 } // namespace interpreter |
3204 } // namespace internal | 3231 } // namespace internal |
3205 } // namespace v8 | 3232 } // namespace v8 |
OLD | NEW |