Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/kernel_binary_flowgraph.h" | 5 #include "vm/kernel_binary_flowgraph.h" |
| 6 | 6 |
| 7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
| 8 #include "vm/longjump.h" | 8 #include "vm/longjump.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 | 10 |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 753 } | 753 } |
| 754 case kLabeledStatement: | 754 case kLabeledStatement: |
| 755 VisitStatement(); // read body. | 755 VisitStatement(); // read body. |
| 756 return; | 756 return; |
| 757 case kBreakStatement: | 757 case kBreakStatement: |
| 758 builder_->ReadPosition(); // read position. | 758 builder_->ReadPosition(); // read position. |
| 759 builder_->ReadUInt(); // read target_index. | 759 builder_->ReadUInt(); // read target_index. |
| 760 return; | 760 return; |
| 761 case kWhileStatement: | 761 case kWhileStatement: |
| 762 ++depth_.loop_; | 762 ++depth_.loop_; |
| 763 builder_->ReadPosition(); // read position. | |
| 763 VisitExpression(); // read condition. | 764 VisitExpression(); // read condition. |
| 764 VisitStatement(); // read body. | 765 VisitStatement(); // read body. |
| 765 --depth_.loop_; | 766 --depth_.loop_; |
| 766 return; | 767 return; |
| 767 case kDoStatement: | 768 case kDoStatement: |
| 768 ++depth_.loop_; | 769 ++depth_.loop_; |
| 770 builder_->ReadPosition(); // read position. | |
| 769 VisitStatement(); // read body. | 771 VisitStatement(); // read body. |
| 770 VisitExpression(); // read condition. | 772 VisitExpression(); // read condition. |
| 771 --depth_.loop_; | 773 --depth_.loop_; |
| 772 return; | 774 return; |
| 773 case kForStatement: { | 775 case kForStatement: { |
| 774 PositionScope scope(builder_->reader_); | 776 PositionScope scope(builder_->reader_); |
| 775 | 777 |
| 776 intptr_t offset = | 778 intptr_t offset = |
| 777 builder_->ReaderOffset() - 1; // -1 to include tag byte. | 779 builder_->ReaderOffset() - 1; // -1 to include tag byte. |
| 778 | 780 |
| 779 EnterScope(offset); | 781 EnterScope(offset); |
| 780 | 782 |
| 783 TokenPosition position = builder_->ReadPosition(); // read position. | |
| 781 intptr_t list_length = | 784 intptr_t list_length = |
| 782 builder_->ReadListLength(); // read number of variables. | 785 builder_->ReadListLength(); // read number of variables. |
| 783 for (intptr_t i = 0; i < list_length; ++i) { | 786 for (intptr_t i = 0; i < list_length; ++i) { |
| 784 VisitVariableDeclaration(); // read ith variable. | 787 VisitVariableDeclaration(); // read ith variable. |
| 785 } | 788 } |
| 786 | 789 |
| 787 ++depth_.loop_; | 790 ++depth_.loop_; |
| 788 | 791 |
| 789 Tag tag = builder_->ReadTag(); // Read first part of condition. | 792 Tag tag = builder_->ReadTag(); // Read first part of condition. |
| 790 if (tag == kSomething) { | 793 if (tag == kSomething) { |
| 791 VisitExpression(); // read rest of condition. | 794 VisitExpression(); // read rest of condition. |
| 792 } | 795 } |
| 793 list_length = builder_->ReadListLength(); // read number of updates. | 796 list_length = builder_->ReadListLength(); // read number of updates. |
| 794 for (intptr_t i = 0; i < list_length; ++i) { | 797 for (intptr_t i = 0; i < list_length; ++i) { |
| 795 VisitExpression(); // read ith update. | 798 VisitExpression(); // read ith update. |
| 796 } | 799 } |
| 797 VisitStatement(); // read body. | 800 VisitStatement(); // read body. |
| 798 | 801 |
| 799 --depth_.loop_; | 802 --depth_.loop_; |
| 800 | 803 |
| 801 ExitScope(builder_->reader_->min_position(), | 804 ExitScope(position, builder_->reader_->max_position()); |
| 802 builder_->reader_->max_position()); | |
| 803 return; | 805 return; |
| 804 } | 806 } |
| 805 case kForInStatement: | 807 case kForInStatement: |
| 806 case kAsyncForInStatement: { | 808 case kAsyncForInStatement: { |
| 807 PositionScope scope(builder_->reader_); | 809 PositionScope scope(builder_->reader_); |
| 808 | 810 |
| 809 intptr_t start_offset = | 811 intptr_t start_offset = |
| 810 builder_->ReaderOffset() - 1; // -1 to include tag byte. | 812 builder_->ReaderOffset() - 1; // -1 to include tag byte. |
| 811 | 813 |
| 812 TokenPosition position = builder_->ReadPosition(); // read position. | 814 builder_->ReadPosition(); // read position. |
| 815 TokenPosition body_position = | |
| 816 builder_->ReadPosition(); // read body position. | |
| 813 | 817 |
| 814 // Notice the ordering: We skip the variable, read the iterable, go back, | 818 // Notice the ordering: We skip the variable, read the iterable, go back, |
| 815 // re-read the variable, go forward to after having read the iterable. | 819 // re-read the variable, go forward to after having read the iterable. |
| 816 intptr_t offset = builder_->ReaderOffset(); | 820 intptr_t offset = builder_->ReaderOffset(); |
| 817 builder_->SkipVariableDeclaration(); // read variable. | 821 builder_->SkipVariableDeclaration(); // read variable. |
| 818 VisitExpression(); // read iterable. | 822 VisitExpression(); // read iterable. |
| 819 | 823 |
| 820 ++depth_.for_in_; | 824 ++depth_.for_in_; |
| 821 AddIteratorVariable(); | 825 AddIteratorVariable(); |
| 822 ++depth_.loop_; | 826 ++depth_.loop_; |
| 823 EnterScope(start_offset); | 827 EnterScope(start_offset); |
| 824 | 828 |
| 825 { | 829 { |
| 826 AlternativeReadingScope alt(builder_->reader_, offset); | 830 AlternativeReadingScope alt(builder_->reader_, offset); |
| 827 VisitVariableDeclaration(); // read variable. | 831 VisitVariableDeclaration(); // read variable. |
| 828 } | 832 } |
| 829 VisitStatement(); // read body. | 833 VisitStatement(); // read body. |
| 830 | 834 |
| 831 if (!position.IsReal()) { | 835 if (!body_position.IsReal()) { |
| 832 position = builder_->reader_->min_position(); | 836 body_position = builder_->reader_->min_position(); |
| 833 } | 837 } |
| 834 // TODO(jensj): From kernel_binary.cc | 838 // TODO(jensj): From kernel_binary.cc |
| 835 // forinstmt->variable_->set_end_position(forinstmt->position_); | 839 // forinstmt->variable_->set_end_position(forinstmt->position_); |
| 836 ExitScope(position, builder_->reader_->max_position()); | 840 ExitScope(body_position, builder_->reader_->max_position()); |
| 837 --depth_.loop_; | 841 --depth_.loop_; |
| 838 --depth_.for_in_; | 842 --depth_.for_in_; |
| 839 return; | 843 return; |
| 840 } | 844 } |
| 841 case kSwitchStatement: { | 845 case kSwitchStatement: { |
| 842 AddSwitchVariable(); | 846 AddSwitchVariable(); |
| 843 VisitExpression(); // read condition. | 847 VisitExpression(); // read condition. |
| 844 int case_count = builder_->ReadListLength(); // read number of cases. | 848 int case_count = builder_->ReadListLength(); // read number of cases. |
| 845 for (intptr_t i = 0; i < case_count; ++i) { | 849 for (intptr_t i = 0; i < case_count; ++i) { |
| 846 int expression_count = | 850 int expression_count = |
| (...skipping 3250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4097 return; | 4101 return; |
| 4098 } | 4102 } |
| 4099 case kLabeledStatement: | 4103 case kLabeledStatement: |
| 4100 SkipStatement(); // read body. | 4104 SkipStatement(); // read body. |
| 4101 return; | 4105 return; |
| 4102 case kBreakStatement: | 4106 case kBreakStatement: |
| 4103 ReadPosition(); // read position. | 4107 ReadPosition(); // read position. |
| 4104 ReadUInt(); // read target_index. | 4108 ReadUInt(); // read target_index. |
| 4105 return; | 4109 return; |
| 4106 case kWhileStatement: | 4110 case kWhileStatement: |
| 4111 ReadPosition(); // read position. | |
|
ahe
2017/08/08 11:38:51
print("Hello, World!"); // Prints "Hello, World!"
| |
| 4107 SkipExpression(); // read condition. | 4112 SkipExpression(); // read condition. |
|
ahe
2017/08/08 11:38:51
Similarly, adding a comment that contradicts with
| |
| 4108 SkipStatement(); // read body. | 4113 SkipStatement(); // read body. |
| 4109 return; | 4114 return; |
| 4110 case kDoStatement: | 4115 case kDoStatement: |
| 4116 ReadPosition(); // read position. | |
| 4111 SkipStatement(); // read body. | 4117 SkipStatement(); // read body. |
| 4112 SkipExpression(); // read condition. | 4118 SkipExpression(); // read condition. |
| 4113 return; | 4119 return; |
| 4114 case kForStatement: { | 4120 case kForStatement: { |
| 4121 ReadPosition(); // read position. | |
| 4115 SkipListOfVariableDeclarations(); // read variables. | 4122 SkipListOfVariableDeclarations(); // read variables. |
| 4116 Tag tag = ReadTag(); // Read first part of condition. | 4123 Tag tag = ReadTag(); // Read first part of condition. |
|
ahe
2017/08/08 11:38:51
Generally, comments should start with an uppercase
| |
| 4117 if (tag == kSomething) { | 4124 if (tag == kSomething) { |
| 4118 SkipExpression(); // read rest of condition. | 4125 SkipExpression(); // read rest of condition. |
| 4119 } | 4126 } |
| 4120 SkipListOfExpressions(); // read updates. | 4127 SkipListOfExpressions(); // read updates. |
| 4121 SkipStatement(); // read body. | 4128 SkipStatement(); // read body. |
| 4122 return; | 4129 return; |
| 4123 } | 4130 } |
| 4124 case kForInStatement: | 4131 case kForInStatement: |
| 4125 case kAsyncForInStatement: | 4132 case kAsyncForInStatement: |
| 4126 ReadPosition(); // read position. | 4133 ReadPosition(); // read position. |
|
ahe
2017/08/08 11:38:51
Read position of what?
| |
| 4134 ReadPosition(); // read body position. | |
|
ahe
2017/08/08 11:38:51
This comment adds value as it adds additional info
| |
| 4127 SkipVariableDeclaration(); // read variable. | 4135 SkipVariableDeclaration(); // read variable. |
| 4128 SkipExpression(); // read iterable. | 4136 SkipExpression(); // read iterable. |
| 4129 SkipStatement(); // read body. | 4137 SkipStatement(); // read body. |
| 4130 return; | 4138 return; |
| 4131 case kSwitchStatement: { | 4139 case kSwitchStatement: { |
| 4132 SkipExpression(); // read condition. | 4140 SkipExpression(); // read condition. |
| 4133 int case_count = ReadListLength(); // read number of cases. | 4141 int case_count = ReadListLength(); // read number of cases. |
| 4134 for (intptr_t i = 0; i < case_count; ++i) { | 4142 for (intptr_t i = 0; i < case_count; ++i) { |
| 4135 int expression_count = ReadListLength(); // read number of expressions. | 4143 int expression_count = ReadListLength(); // read number of expressions. |
| 4136 for (intptr_t j = 0; j < expression_count; ++j) { | 4144 for (intptr_t j = 0; j < expression_count; ++j) { |
| (...skipping 1945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6082 if (NeedsDebugStepCheck(parsed_function()->function(), position)) { | 6090 if (NeedsDebugStepCheck(parsed_function()->function(), position)) { |
| 6083 instructions += DebugStepCheck(position); | 6091 instructions += DebugStepCheck(position); |
| 6084 } | 6092 } |
| 6085 instructions += Goto(destination); | 6093 instructions += Goto(destination); |
| 6086 } | 6094 } |
| 6087 return instructions; | 6095 return instructions; |
| 6088 } | 6096 } |
| 6089 | 6097 |
| 6090 Fragment StreamingFlowGraphBuilder::BuildWhileStatement() { | 6098 Fragment StreamingFlowGraphBuilder::BuildWhileStatement() { |
| 6091 loop_depth_inc(); | 6099 loop_depth_inc(); |
| 6100 ReadPosition(); // read position. | |
| 6101 | |
| 6092 bool negate; | 6102 bool negate; |
| 6093 Fragment condition = TranslateCondition(&negate); // read condition. | 6103 Fragment condition = TranslateCondition(&negate); // read condition. |
| 6094 TargetEntryInstr* body_entry; | 6104 TargetEntryInstr* body_entry; |
| 6095 TargetEntryInstr* loop_exit; | 6105 TargetEntryInstr* loop_exit; |
| 6096 condition += BranchIfTrue(&body_entry, &loop_exit, negate); | 6106 condition += BranchIfTrue(&body_entry, &loop_exit, negate); |
| 6097 | 6107 |
| 6098 Fragment body(body_entry); | 6108 Fragment body(body_entry); |
| 6099 body += BuildStatement(); // read body. | 6109 body += BuildStatement(); // read body. |
| 6100 | 6110 |
| 6101 Instruction* entry; | 6111 Instruction* entry; |
| 6102 if (body.is_open()) { | 6112 if (body.is_open()) { |
| 6103 JoinEntryInstr* join = BuildJoinEntry(); | 6113 JoinEntryInstr* join = BuildJoinEntry(); |
| 6104 body += Goto(join); | 6114 body += Goto(join); |
| 6105 | 6115 |
| 6106 Fragment loop(join); | 6116 Fragment loop(join); |
| 6107 loop += CheckStackOverflow(); | 6117 loop += CheckStackOverflow(); |
| 6108 loop += condition; | 6118 loop += condition; |
| 6109 entry = new (Z) GotoInstr(join, Thread::Current()->GetNextDeoptId()); | 6119 entry = new (Z) GotoInstr(join, Thread::Current()->GetNextDeoptId()); |
| 6110 } else { | 6120 } else { |
| 6111 entry = condition.entry; | 6121 entry = condition.entry; |
| 6112 } | 6122 } |
| 6113 | 6123 |
| 6114 loop_depth_dec(); | 6124 loop_depth_dec(); |
| 6115 return Fragment(entry, loop_exit); | 6125 return Fragment(entry, loop_exit); |
| 6116 } | 6126 } |
| 6117 | 6127 |
| 6118 Fragment StreamingFlowGraphBuilder::BuildDoStatement() { | 6128 Fragment StreamingFlowGraphBuilder::BuildDoStatement() { |
| 6119 loop_depth_inc(); | 6129 loop_depth_inc(); |
| 6130 ReadPosition(); // read position. | |
| 6120 Fragment body = BuildStatement(); // read body. | 6131 Fragment body = BuildStatement(); // read body. |
| 6121 | 6132 |
| 6122 if (body.is_closed()) { | 6133 if (body.is_closed()) { |
| 6123 SkipExpression(); // read condition. | 6134 SkipExpression(); // read condition. |
| 6124 loop_depth_dec(); | 6135 loop_depth_dec(); |
| 6125 return body; | 6136 return body; |
| 6126 } | 6137 } |
| 6127 | 6138 |
| 6128 bool negate; | 6139 bool negate; |
| 6129 JoinEntryInstr* join = BuildJoinEntry(); | 6140 JoinEntryInstr* join = BuildJoinEntry(); |
| 6130 Fragment loop(join); | 6141 Fragment loop(join); |
| 6131 loop += CheckStackOverflow(); | 6142 loop += CheckStackOverflow(); |
| 6132 loop += body; | 6143 loop += body; |
| 6133 loop += TranslateCondition(&negate); // read condition. | 6144 loop += TranslateCondition(&negate); // read condition. |
| 6134 TargetEntryInstr* loop_repeat; | 6145 TargetEntryInstr* loop_repeat; |
| 6135 TargetEntryInstr* loop_exit; | 6146 TargetEntryInstr* loop_exit; |
| 6136 loop += BranchIfTrue(&loop_repeat, &loop_exit, negate); | 6147 loop += BranchIfTrue(&loop_repeat, &loop_exit, negate); |
| 6137 | 6148 |
| 6138 Fragment repeat(loop_repeat); | 6149 Fragment repeat(loop_repeat); |
| 6139 repeat += Goto(join); | 6150 repeat += Goto(join); |
| 6140 | 6151 |
| 6141 loop_depth_dec(); | 6152 loop_depth_dec(); |
| 6142 return Fragment(new (Z) GotoInstr(join, Thread::Current()->GetNextDeoptId()), | 6153 return Fragment(new (Z) GotoInstr(join, Thread::Current()->GetNextDeoptId()), |
| 6143 loop_exit); | 6154 loop_exit); |
| 6144 } | 6155 } |
| 6145 | 6156 |
| 6146 Fragment StreamingFlowGraphBuilder::BuildForStatement() { | 6157 Fragment StreamingFlowGraphBuilder::BuildForStatement() { |
| 6147 intptr_t offset = ReaderOffset() - 1; // Include the tag. | 6158 intptr_t offset = ReaderOffset() - 1; // Include the tag. |
| 6148 | 6159 |
| 6160 ReadPosition(); // read position. | |
| 6161 | |
| 6149 Fragment declarations; | 6162 Fragment declarations; |
| 6150 | 6163 |
| 6151 bool new_context = false; | 6164 bool new_context = false; |
| 6152 declarations += EnterScope(offset, &new_context); | 6165 declarations += EnterScope(offset, &new_context); |
| 6153 | 6166 |
| 6154 intptr_t list_length = ReadListLength(); // read number of variables. | 6167 intptr_t list_length = ReadListLength(); // read number of variables. |
| 6155 for (intptr_t i = 0; i < list_length; ++i) { | 6168 for (intptr_t i = 0; i < list_length; ++i) { |
| 6156 declarations += BuildVariableDeclaration(); // read ith variable. | 6169 declarations += BuildVariableDeclaration(); // read ith variable. |
| 6157 } | 6170 } |
| 6158 | 6171 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6200 loop_depth_dec(); | 6213 loop_depth_dec(); |
| 6201 | 6214 |
| 6202 loop += ExitScope(offset); | 6215 loop += ExitScope(offset); |
| 6203 | 6216 |
| 6204 return loop; | 6217 return loop; |
| 6205 } | 6218 } |
| 6206 | 6219 |
| 6207 Fragment StreamingFlowGraphBuilder::BuildForInStatement(bool async) { | 6220 Fragment StreamingFlowGraphBuilder::BuildForInStatement(bool async) { |
| 6208 intptr_t offset = ReaderOffset() - 1; // Include the tag. | 6221 intptr_t offset = ReaderOffset() - 1; // Include the tag. |
| 6209 | 6222 |
| 6210 TokenPosition position = ReadPosition(); // read position. | 6223 ReadPosition(); // read position. |
|
ahe
2017/08/08 11:38:51
Of what?
| |
| 6224 TokenPosition body_position = ReadPosition(); // read body position. | |
| 6211 intptr_t variable_kernel_position = ReaderOffset(); | 6225 intptr_t variable_kernel_position = ReaderOffset(); |
| 6212 SkipVariableDeclaration(); // read variable. | 6226 SkipVariableDeclaration(); // read variable. |
| 6213 | 6227 |
| 6214 TokenPosition iterable_position = TokenPosition::kNoSource; | 6228 TokenPosition iterable_position = TokenPosition::kNoSource; |
| 6215 Fragment instructions = | 6229 Fragment instructions = |
| 6216 BuildExpression(&iterable_position); // read iterable. | 6230 BuildExpression(&iterable_position); // read iterable. |
| 6217 instructions += PushArgument(); | 6231 instructions += PushArgument(); |
| 6218 | 6232 |
| 6219 const dart::String& iterator_getter = dart::String::ZoneHandle( | 6233 const dart::String& iterator_getter = dart::String::ZoneHandle( |
| 6220 Z, dart::Field::GetterSymbol(Symbols::Iterator())); | 6234 Z, dart::Field::GetterSymbol(Symbols::Iterator())); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 6233 TargetEntryInstr* body_entry; | 6247 TargetEntryInstr* body_entry; |
| 6234 TargetEntryInstr* loop_exit; | 6248 TargetEntryInstr* loop_exit; |
| 6235 condition += BranchIfTrue(&body_entry, &loop_exit, false); | 6249 condition += BranchIfTrue(&body_entry, &loop_exit, false); |
| 6236 | 6250 |
| 6237 Fragment body(body_entry); | 6251 Fragment body(body_entry); |
| 6238 body += EnterScope(offset); | 6252 body += EnterScope(offset); |
| 6239 body += LoadLocal(iterator); | 6253 body += LoadLocal(iterator); |
| 6240 body += PushArgument(); | 6254 body += PushArgument(); |
| 6241 const dart::String& current_getter = dart::String::ZoneHandle( | 6255 const dart::String& current_getter = dart::String::ZoneHandle( |
| 6242 Z, dart::Field::GetterSymbol(Symbols::Current())); | 6256 Z, dart::Field::GetterSymbol(Symbols::Current())); |
| 6243 body += InstanceCall(position, current_getter, Token::kGET, 1); | 6257 body += InstanceCall(body_position, current_getter, Token::kGET, 1); |
| 6244 body += StoreLocal(TokenPosition::kNoSource, | 6258 body += StoreLocal(TokenPosition::kNoSource, |
| 6245 LookupVariable(variable_kernel_position)); | 6259 LookupVariable(variable_kernel_position)); |
| 6246 body += Drop(); | 6260 body += Drop(); |
| 6247 body += BuildStatement(); // read body. | 6261 body += BuildStatement(); // read body. |
| 6248 body += ExitScope(offset); | 6262 body += ExitScope(offset); |
| 6249 | 6263 |
| 6250 if (body.is_open()) { | 6264 if (body.is_open()) { |
| 6251 JoinEntryInstr* join = BuildJoinEntry(); | 6265 JoinEntryInstr* join = BuildJoinEntry(); |
| 6252 instructions += Goto(join); | 6266 instructions += Goto(join); |
| 6253 body += Goto(join); | 6267 body += Goto(join); |
| (...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7314 } | 7328 } |
| 7315 } | 7329 } |
| 7316 | 7330 |
| 7317 return Array::Handle(Array::null()); | 7331 return Array::Handle(Array::null()); |
| 7318 } | 7332 } |
| 7319 | 7333 |
| 7320 } // namespace kernel | 7334 } // namespace kernel |
| 7321 } // namespace dart | 7335 } // namespace dart |
| 7322 | 7336 |
| 7323 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 7337 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |