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 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 VisitNewTargetVariable(scope()->new_target_var()); | 667 VisitNewTargetVariable(scope()->new_target_var()); |
668 | 668 |
669 // TODO(rmcilroy): Emit tracing call if requested to do so. | 669 // TODO(rmcilroy): Emit tracing call if requested to do so. |
670 if (FLAG_trace) { | 670 if (FLAG_trace) { |
671 UNIMPLEMENTED(); | 671 UNIMPLEMENTED(); |
672 } | 672 } |
673 | 673 |
674 // Visit declarations within the function scope. | 674 // Visit declarations within the function scope. |
675 VisitDeclarations(scope()->declarations()); | 675 VisitDeclarations(scope()->declarations()); |
676 | 676 |
| 677 // Emit initializing assignments for module namespace imports (if any). |
| 678 VisitModuleNamespaceImports(); |
| 679 |
677 // Perform a stack-check before the body. | 680 // Perform a stack-check before the body. |
678 builder()->StackCheck(info()->literal()->start_position()); | 681 builder()->StackCheck(info()->literal()->start_position()); |
679 | 682 |
680 // Visit statements in the function body. | 683 // Visit statements in the function body. |
681 VisitStatements(info()->literal()->body()); | 684 VisitStatements(info()->literal()->body()); |
682 } | 685 } |
683 | 686 |
684 void BytecodeGenerator::BuildIndexedJump(Register index, size_t start_index, | 687 void BytecodeGenerator::BuildIndexedJump(Register index, size_t start_index, |
685 size_t size, | 688 size_t size, |
686 ZoneVector<BytecodeLabel>& targets) { | 689 ZoneVector<BytecodeLabel>& targets) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 case VariableLocation::MODULE: | 869 case VariableLocation::MODULE: |
867 DCHECK_EQ(variable->mode(), LET); | 870 DCHECK_EQ(variable->mode(), LET); |
868 DCHECK(variable->IsExport()); | 871 DCHECK(variable->IsExport()); |
869 VisitForAccumulatorValue(decl->fun()); | 872 VisitForAccumulatorValue(decl->fun()); |
870 VisitVariableAssignment(variable, Token::INIT, | 873 VisitVariableAssignment(variable, Token::INIT, |
871 FeedbackVectorSlot::Invalid()); | 874 FeedbackVectorSlot::Invalid()); |
872 break; | 875 break; |
873 } | 876 } |
874 } | 877 } |
875 | 878 |
| 879 void BytecodeGenerator::VisitModuleNamespaceImports() { |
| 880 if (!scope()->is_module_scope()) return; |
| 881 |
| 882 RegisterAllocationScope register_scope(this); |
| 883 Register module_request = register_allocator()->NewRegister(); |
| 884 |
| 885 ModuleDescriptor* descriptor = scope()->AsModuleScope()->module(); |
| 886 for (auto entry : descriptor->namespace_imports()) { |
| 887 builder() |
| 888 ->LoadLiteral(Smi::FromInt(entry->module_request)) |
| 889 .StoreAccumulatorInRegister(module_request) |
| 890 .CallRuntime(Runtime::kGetModuleNamespace, module_request); |
| 891 Variable* var = scope()->LookupLocal(entry->local_name); |
| 892 DCHECK_NOT_NULL(var); |
| 893 VisitVariableAssignment(var, Token::INIT, FeedbackVectorSlot::Invalid()); |
| 894 } |
| 895 } |
| 896 |
876 void BytecodeGenerator::VisitDeclarations( | 897 void BytecodeGenerator::VisitDeclarations( |
877 ZoneList<Declaration*>* declarations) { | 898 ZoneList<Declaration*>* declarations) { |
878 RegisterAllocationScope register_scope(this); | 899 RegisterAllocationScope register_scope(this); |
879 DCHECK(globals_builder()->empty()); | 900 DCHECK(globals_builder()->empty()); |
880 for (int i = 0; i < declarations->length(); i++) { | 901 for (int i = 0; i < declarations->length(); i++) { |
881 RegisterAllocationScope register_scope(this); | 902 RegisterAllocationScope register_scope(this); |
882 Visit(declarations->at(i)); | 903 Visit(declarations->at(i)); |
883 } | 904 } |
884 if (globals_builder()->empty()) return; | 905 if (globals_builder()->empty()) return; |
885 | 906 |
(...skipping 2260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3146 } | 3167 } |
3147 | 3168 |
3148 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { | 3169 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { |
3149 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | 3170 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict |
3150 : Runtime::kStoreKeyedToSuper_Sloppy; | 3171 : Runtime::kStoreKeyedToSuper_Sloppy; |
3151 } | 3172 } |
3152 | 3173 |
3153 } // namespace interpreter | 3174 } // namespace interpreter |
3154 } // namespace internal | 3175 } // namespace internal |
3155 } // namespace v8 | 3176 } // namespace v8 |
OLD | NEW |