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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
639 info_(info), | 639 info_(info), |
640 ast_string_constants_(info->isolate()->ast_string_constants()), | 640 ast_string_constants_(info->isolate()->ast_string_constants()), |
641 closure_scope_(info->scope()), | 641 closure_scope_(info->scope()), |
642 current_scope_(info->scope()), | 642 current_scope_(info->scope()), |
643 globals_builder_(new (zone()) GlobalDeclarationsBuilder(info->zone())), | 643 globals_builder_(new (zone()) GlobalDeclarationsBuilder(info->zone())), |
644 global_declarations_(0, info->zone()), | 644 global_declarations_(0, info->zone()), |
645 function_literals_(0, info->zone()), | 645 function_literals_(0, info->zone()), |
646 native_function_literals_(0, info->zone()), | 646 native_function_literals_(0, info->zone()), |
647 object_literals_(0, info->zone()), | 647 object_literals_(0, info->zone()), |
648 array_literals_(0, info->zone()), | 648 array_literals_(0, info->zone()), |
649 block_coverage_slots_(0, info->zone()), | |
649 execution_control_(nullptr), | 650 execution_control_(nullptr), |
650 execution_context_(nullptr), | 651 execution_context_(nullptr), |
651 execution_result_(nullptr), | 652 execution_result_(nullptr), |
652 generator_jump_table_(nullptr), | 653 generator_jump_table_(nullptr), |
653 generator_state_(), | 654 generator_state_(), |
654 loop_depth_(0) { | 655 loop_depth_(0) { |
655 DCHECK_EQ(closure_scope(), closure_scope()->GetClosureScope()); | 656 DCHECK_EQ(closure_scope(), closure_scope()->GetClosureScope()); |
656 } | 657 } |
657 | 658 |
658 Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) { | 659 Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) { |
659 AllocateDeferredConstants(isolate); | 660 AllocateDeferredConstants(isolate); |
661 | |
662 if (is_block_coverage()) { | |
663 Handle<CoverageInfo> coverage_info = | |
664 isolate->factory()->NewCoverageInfo(block_coverage_slots_); | |
665 info()->shared_info()->set_coverage_info(*coverage_info); | |
rmcilroy
2017/05/18 14:17:59
We don't set things in the shared_info in the byte
jgruber
2017/05/22 09:43:32
I changed this to store the CoverageInfo on Compil
| |
666 } | |
667 | |
660 if (HasStackOverflow()) return Handle<BytecodeArray>(); | 668 if (HasStackOverflow()) return Handle<BytecodeArray>(); |
661 return builder()->ToBytecodeArray(isolate); | 669 return builder()->ToBytecodeArray(isolate); |
662 } | 670 } |
663 | 671 |
664 void BytecodeGenerator::AllocateDeferredConstants(Isolate* isolate) { | 672 void BytecodeGenerator::AllocateDeferredConstants(Isolate* isolate) { |
665 // Build global declaration pair arrays. | 673 // Build global declaration pair arrays. |
666 for (GlobalDeclarationsBuilder* globals_builder : global_declarations_) { | 674 for (GlobalDeclarationsBuilder* globals_builder : global_declarations_) { |
667 Handle<FixedArray> declarations = | 675 Handle<FixedArray> declarations = |
668 globals_builder->AllocateDeclarations(info()); | 676 globals_builder->AllocateDeclarations(info()); |
669 if (declarations.is_null()) return SetStackOverflow(); | 677 if (declarations.is_null()) return SetStackOverflow(); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1049 void BytecodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { | 1057 void BytecodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
1050 builder()->SetStatementPosition(stmt); | 1058 builder()->SetStatementPosition(stmt); |
1051 VisitForEffect(stmt->expression()); | 1059 VisitForEffect(stmt->expression()); |
1052 } | 1060 } |
1053 | 1061 |
1054 void BytecodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { | 1062 void BytecodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { |
1055 } | 1063 } |
1056 | 1064 |
1057 void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { | 1065 void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { |
1058 builder()->SetStatementPosition(stmt); | 1066 builder()->SetStatementPosition(stmt); |
1067 | |
1059 if (stmt->condition()->ToBooleanIsTrue()) { | 1068 if (stmt->condition()->ToBooleanIsTrue()) { |
1060 // Generate then block unconditionally as always true. | 1069 // Generate then block unconditionally as always true. |
1070 IncBlockCounter(stmt->then_range()); | |
1061 Visit(stmt->then_statement()); | 1071 Visit(stmt->then_statement()); |
1062 } else if (stmt->condition()->ToBooleanIsFalse()) { | 1072 } else if (stmt->condition()->ToBooleanIsFalse()) { |
1063 // Generate else block unconditionally if it exists. | 1073 // Generate else block unconditionally if it exists. |
1064 if (stmt->HasElseStatement()) { | 1074 if (stmt->HasElseStatement()) { |
1075 IncBlockCounter(stmt->else_range()); | |
1065 Visit(stmt->else_statement()); | 1076 Visit(stmt->else_statement()); |
1066 } | 1077 } |
1067 } else { | 1078 } else { |
1068 // TODO(oth): If then statement is BreakStatement or | 1079 // TODO(oth): If then statement is BreakStatement or |
1069 // ContinueStatement we can reduce number of generated | 1080 // ContinueStatement we can reduce number of generated |
1070 // jump/jump_ifs here. See BasicLoops test. | 1081 // jump/jump_ifs here. See BasicLoops test. |
1071 BytecodeLabel end_label; | 1082 BytecodeLabel end_label; |
1072 BytecodeLabels then_labels(zone()), else_labels(zone()); | 1083 BytecodeLabels then_labels(zone()), else_labels(zone()); |
1073 VisitForTest(stmt->condition(), &then_labels, &else_labels, | 1084 VisitForTest(stmt->condition(), &then_labels, &else_labels, |
1074 TestFallthrough::kThen); | 1085 TestFallthrough::kThen); |
1075 | 1086 |
1076 then_labels.Bind(builder()); | 1087 then_labels.Bind(builder()); |
1088 IncBlockCounter(stmt->then_range()); | |
1077 Visit(stmt->then_statement()); | 1089 Visit(stmt->then_statement()); |
1078 | 1090 |
1079 if (stmt->HasElseStatement()) { | 1091 if (stmt->HasElseStatement()) { |
1080 builder()->Jump(&end_label); | 1092 builder()->Jump(&end_label); |
1081 else_labels.Bind(builder()); | 1093 else_labels.Bind(builder()); |
1094 IncBlockCounter(stmt->else_range()); | |
1082 Visit(stmt->else_statement()); | 1095 Visit(stmt->else_statement()); |
1083 } else { | 1096 } else { |
1084 else_labels.Bind(builder()); | 1097 else_labels.Bind(builder()); |
1085 } | 1098 } |
1086 builder()->Bind(&end_label); | 1099 builder()->Bind(&end_label); |
1087 } | 1100 } |
1088 } | 1101 } |
1089 | 1102 |
1090 void BytecodeGenerator::VisitSloppyBlockFunctionStatement( | 1103 void BytecodeGenerator::VisitSloppyBlockFunctionStatement( |
1091 SloppyBlockFunctionStatement* stmt) { | 1104 SloppyBlockFunctionStatement* stmt) { |
(...skipping 2582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3674 } | 3687 } |
3675 | 3688 |
3676 LanguageMode BytecodeGenerator::language_mode() const { | 3689 LanguageMode BytecodeGenerator::language_mode() const { |
3677 return current_scope()->language_mode(); | 3690 return current_scope()->language_mode(); |
3678 } | 3691 } |
3679 | 3692 |
3680 int BytecodeGenerator::feedback_index(FeedbackSlot slot) const { | 3693 int BytecodeGenerator::feedback_index(FeedbackSlot slot) const { |
3681 return FeedbackVector::GetIndex(slot); | 3694 return FeedbackVector::GetIndex(slot); |
3682 } | 3695 } |
3683 | 3696 |
3697 bool BytecodeGenerator::is_block_coverage() const { | |
3698 return FLAG_block_coverage && | |
3699 info()->parse_info()->script()->IsUserJavaScript(); | |
3700 } | |
3701 | |
3684 Runtime::FunctionId BytecodeGenerator::StoreToSuperRuntimeId() { | 3702 Runtime::FunctionId BytecodeGenerator::StoreToSuperRuntimeId() { |
3685 return is_strict(language_mode()) ? Runtime::kStoreToSuper_Strict | 3703 return is_strict(language_mode()) ? Runtime::kStoreToSuper_Strict |
3686 : Runtime::kStoreToSuper_Sloppy; | 3704 : Runtime::kStoreToSuper_Sloppy; |
3687 } | 3705 } |
3688 | 3706 |
3689 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { | 3707 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { |
3690 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | 3708 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict |
3691 : Runtime::kStoreKeyedToSuper_Sloppy; | 3709 : Runtime::kStoreKeyedToSuper_Sloppy; |
3692 } | 3710 } |
3693 | 3711 |
3694 } // namespace interpreter | 3712 } // namespace interpreter |
3695 } // namespace internal | 3713 } // namespace internal |
3696 } // namespace v8 | 3714 } // namespace v8 |
OLD | NEW |