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/builtins/builtins-constructor.h" | 9 #include "src/builtins/builtins-constructor.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 global_declarations_(0, info->zone()), | 628 global_declarations_(0, info->zone()), |
629 function_literals_(0, info->zone()), | 629 function_literals_(0, info->zone()), |
630 native_function_literals_(0, info->zone()), | 630 native_function_literals_(0, info->zone()), |
631 object_literals_(0, info->zone()), | 631 object_literals_(0, info->zone()), |
632 array_literals_(0, info->zone()), | 632 array_literals_(0, info->zone()), |
633 execution_control_(nullptr), | 633 execution_control_(nullptr), |
634 execution_context_(nullptr), | 634 execution_context_(nullptr), |
635 execution_result_(nullptr), | 635 execution_result_(nullptr), |
636 generator_resume_points_(info->literal()->yield_count(), info->zone()), | 636 generator_resume_points_(info->literal()->yield_count(), info->zone()), |
637 generator_state_(), | 637 generator_state_(), |
638 loop_depth_(0) { | 638 loop_depth_(0), |
| 639 source_url_entry_(0), |
| 640 has_source_url_entry_(false) { |
639 DCHECK_EQ(closure_scope(), closure_scope()->GetClosureScope()); | 641 DCHECK_EQ(closure_scope(), closure_scope()->GetClosureScope()); |
640 } | 642 } |
641 | 643 |
642 Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) { | 644 Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) { |
643 AllocateDeferredConstants(isolate); | 645 AllocateDeferredConstants(isolate); |
644 if (HasStackOverflow()) return Handle<BytecodeArray>(); | 646 if (HasStackOverflow()) return Handle<BytecodeArray>(); |
645 return builder()->ToBytecodeArray(isolate); | 647 return builder()->ToBytecodeArray(isolate); |
646 } | 648 } |
647 | 649 |
648 void BytecodeGenerator::AllocateDeferredConstants(Isolate* isolate) { | 650 void BytecodeGenerator::AllocateDeferredConstants(Isolate* isolate) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 } | 691 } |
690 } | 692 } |
691 | 693 |
692 // Build array literal constant elements | 694 // Build array literal constant elements |
693 for (std::pair<ArrayLiteral*, size_t> literal : array_literals_) { | 695 for (std::pair<ArrayLiteral*, size_t> literal : array_literals_) { |
694 ArrayLiteral* array_literal = literal.first; | 696 ArrayLiteral* array_literal = literal.first; |
695 Handle<ConstantElementsPair> constant_elements = | 697 Handle<ConstantElementsPair> constant_elements = |
696 array_literal->GetOrBuildConstantElements(isolate); | 698 array_literal->GetOrBuildConstantElements(isolate); |
697 builder()->SetDeferredConstantPoolEntry(literal.second, constant_elements); | 699 builder()->SetDeferredConstantPoolEntry(literal.second, constant_elements); |
698 } | 700 } |
| 701 |
| 702 if (has_source_url_entry()) { |
| 703 Handle<String> url(String::cast(info()->script()->name())); |
| 704 builder()->SetDeferredConstantPoolEntry(source_url_entry(), url); |
| 705 } |
699 } | 706 } |
700 | 707 |
701 void BytecodeGenerator::GenerateBytecode(uintptr_t stack_limit) { | 708 void BytecodeGenerator::GenerateBytecode(uintptr_t stack_limit) { |
702 DisallowHeapAllocation no_allocation; | 709 DisallowHeapAllocation no_allocation; |
703 DisallowHandleAllocation no_handles; | 710 DisallowHandleAllocation no_handles; |
704 DisallowHandleDereference no_deref; | 711 DisallowHandleDereference no_deref; |
705 | 712 |
706 InitializeAstVisitor(stack_limit); | 713 InitializeAstVisitor(stack_limit); |
707 | 714 |
708 // Initialize the incoming context. | 715 // Initialize the incoming context. |
(...skipping 2287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2996 builder()->SetExpressionPosition(expr); | 3003 builder()->SetExpressionPosition(expr); |
2997 builder()->BinaryOperation(expr->op(), lhs, feedback_index(slot)); | 3004 builder()->BinaryOperation(expr->op(), lhs, feedback_index(slot)); |
2998 } | 3005 } |
2999 | 3006 |
3000 void BytecodeGenerator::VisitSpread(Spread* expr) { Visit(expr->expression()); } | 3007 void BytecodeGenerator::VisitSpread(Spread* expr) { Visit(expr->expression()); } |
3001 | 3008 |
3002 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { | 3009 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { |
3003 UNREACHABLE(); | 3010 UNREACHABLE(); |
3004 } | 3011 } |
3005 | 3012 |
| 3013 void BytecodeGenerator::VisitImportCallExpression(ImportCallExpression* expr) { |
| 3014 size_t entry = builder()->AllocateDeferredConstantPoolEntry(); |
| 3015 set_source_url_entry(entry); |
| 3016 RegisterList args = register_allocator()->NewRegisterList(2); |
| 3017 VisitForRegisterValue(expr->arg(), args[1]); |
| 3018 builder() |
| 3019 ->LoadConstantPoolEntry(entry) |
| 3020 .StoreAccumulatorInRegister(args[0]) |
| 3021 .CallRuntime(Runtime::kDynamicImportCall, args); |
| 3022 } |
| 3023 |
3006 void BytecodeGenerator::VisitGetIterator(GetIterator* expr) { | 3024 void BytecodeGenerator::VisitGetIterator(GetIterator* expr) { |
3007 FeedbackSlot load_slot = expr->IteratorPropertyFeedbackSlot(); | 3025 FeedbackSlot load_slot = expr->IteratorPropertyFeedbackSlot(); |
3008 FeedbackSlot call_slot = expr->IteratorCallFeedbackSlot(); | 3026 FeedbackSlot call_slot = expr->IteratorCallFeedbackSlot(); |
3009 | 3027 |
3010 RegisterList args = register_allocator()->NewRegisterList(1); | 3028 RegisterList args = register_allocator()->NewRegisterList(1); |
3011 Register method = register_allocator()->NewRegister(); | 3029 Register method = register_allocator()->NewRegister(); |
3012 Register obj = args[0]; | 3030 Register obj = args[0]; |
3013 | 3031 |
3014 VisitForAccumulatorValue(expr->iterable()); | 3032 VisitForAccumulatorValue(expr->iterable()); |
3015 | 3033 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3488 } | 3506 } |
3489 | 3507 |
3490 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { | 3508 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { |
3491 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | 3509 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict |
3492 : Runtime::kStoreKeyedToSuper_Sloppy; | 3510 : Runtime::kStoreKeyedToSuper_Sloppy; |
3493 } | 3511 } |
3494 | 3512 |
3495 } // namespace interpreter | 3513 } // namespace interpreter |
3496 } // namespace internal | 3514 } // namespace internal |
3497 } // namespace v8 | 3515 } // namespace v8 |
OLD | NEW |