Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" |
| 8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
| 9 #include "vm/code_descriptors.h" | 9 #include "vm/code_descriptors.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1066 // f) loop-exit-target | 1066 // f) loop-exit-target |
| 1067 // g) break-join (optional) | 1067 // g) break-join (optional) |
| 1068 void EffectGraphVisitor::VisitWhileNode(WhileNode* node) { | 1068 void EffectGraphVisitor::VisitWhileNode(WhileNode* node) { |
| 1069 TestGraphVisitor for_test(owner(), | 1069 TestGraphVisitor for_test(owner(), |
| 1070 temp_index(), | 1070 temp_index(), |
| 1071 node->condition()->token_index()); | 1071 node->condition()->token_index()); |
| 1072 node->condition()->Visit(&for_test); | 1072 node->condition()->Visit(&for_test); |
| 1073 ASSERT(!for_test.is_empty()); // Language spec. | 1073 ASSERT(!for_test.is_empty()); // Language spec. |
| 1074 | 1074 |
| 1075 EffectGraphVisitor for_body(owner(), temp_index()); | 1075 EffectGraphVisitor for_body(owner(), temp_index()); |
| 1076 if (for_body.is_open()) { | |
|
Vyacheslav Egorov (Google)
2012/06/15 18:02:51
if is not required now. it is always open right af
srdjan
2012/06/15 18:05:06
Done.
| |
| 1077 CheckStackOverflowComp* comp = | |
| 1078 new CheckStackOverflowComp(node->token_index(), owner()->try_index()); | |
| 1079 for_body.AddInstruction(new DoInstr(comp)); | |
| 1080 } | |
| 1076 node->body()->Visit(&for_body); | 1081 node->body()->Visit(&for_body); |
| 1077 | 1082 |
| 1078 // Labels are set after body traversal. | 1083 // Labels are set after body traversal. |
| 1079 SourceLabel* lbl = node->label(); | 1084 SourceLabel* lbl = node->label(); |
| 1080 ASSERT(lbl != NULL); | 1085 ASSERT(lbl != NULL); |
| 1081 if (lbl->join_for_continue() != NULL) { | 1086 if (lbl->join_for_continue() != NULL) { |
| 1082 AddInstruction(lbl->join_for_continue()); | 1087 AddInstruction(lbl->join_for_continue()); |
| 1083 } | 1088 } |
| 1084 TieLoop(for_test, for_body); | 1089 TieLoop(for_test, for_body); |
| 1085 if (lbl->join_for_break() != NULL) { | 1090 if (lbl->join_for_break() != NULL) { |
| 1086 AddInstruction(lbl->join_for_break()); | 1091 AddInstruction(lbl->join_for_break()); |
| 1087 } | 1092 } |
| 1088 } | 1093 } |
| 1089 | 1094 |
| 1090 | 1095 |
| 1091 // The fragment is composed as follows: | 1096 // The fragment is composed as follows: |
| 1092 // a) body-entry-join | 1097 // a) body-entry-join |
| 1093 // b) [ body ] | 1098 // b) [ body ] |
| 1094 // c) test-entry (continue-join or body-exit-target) | 1099 // c) test-entry (continue-join or body-exit-target) |
| 1095 // d) [ test-entry ] -> (back-target, loop-exit-target) | 1100 // d) [ test-entry ] -> (back-target, loop-exit-target) |
| 1096 // e) back-target -> (body-entry-join) | 1101 // e) back-target -> (body-entry-join) |
| 1097 // f) loop-exit-target | 1102 // f) loop-exit-target |
| 1098 // g) break-join | 1103 // g) break-join |
| 1099 void EffectGraphVisitor::VisitDoWhileNode(DoWhileNode* node) { | 1104 void EffectGraphVisitor::VisitDoWhileNode(DoWhileNode* node) { |
| 1100 // Traverse body first in order to generate continue and break labels. | 1105 // Traverse body first in order to generate continue and break labels. |
| 1101 EffectGraphVisitor for_body(owner(), temp_index()); | 1106 EffectGraphVisitor for_body(owner(), temp_index()); |
| 1107 if (for_body.is_open()) { | |
|
Vyacheslav Egorov (Google)
2012/06/15 18:02:51
ditto
srdjan
2012/06/15 18:05:06
Done.
| |
| 1108 CheckStackOverflowComp* comp = | |
| 1109 new CheckStackOverflowComp(node->token_index(), owner()->try_index()); | |
| 1110 for_body.AddInstruction(new DoInstr(comp)); | |
| 1111 } | |
| 1102 node->body()->Visit(&for_body); | 1112 node->body()->Visit(&for_body); |
| 1103 | 1113 |
| 1104 TestGraphVisitor for_test(owner(), | 1114 TestGraphVisitor for_test(owner(), |
| 1105 temp_index(), | 1115 temp_index(), |
| 1106 node->condition()->token_index()); | 1116 node->condition()->token_index()); |
| 1107 node->condition()->Visit(&for_test); | 1117 node->condition()->Visit(&for_test); |
| 1108 ASSERT(is_open()); | 1118 ASSERT(is_open()); |
| 1109 | 1119 |
| 1110 // Tie do-while loop (test is after the body). | 1120 // Tie do-while loop (test is after the body). |
| 1111 JoinEntryInstr* body_entry_join = new JoinEntryInstr(); | 1121 JoinEntryInstr* body_entry_join = new JoinEntryInstr(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1156 void EffectGraphVisitor::VisitForNode(ForNode* node) { | 1166 void EffectGraphVisitor::VisitForNode(ForNode* node) { |
| 1157 EffectGraphVisitor for_initializer(owner(), temp_index()); | 1167 EffectGraphVisitor for_initializer(owner(), temp_index()); |
| 1158 node->initializer()->Visit(&for_initializer); | 1168 node->initializer()->Visit(&for_initializer); |
| 1159 Append(for_initializer); | 1169 Append(for_initializer); |
| 1160 ASSERT(is_open()); | 1170 ASSERT(is_open()); |
| 1161 | 1171 |
| 1162 // Compose body to set any jump labels. | 1172 // Compose body to set any jump labels. |
| 1163 EffectGraphVisitor for_body(owner(), temp_index()); | 1173 EffectGraphVisitor for_body(owner(), temp_index()); |
| 1164 TargetEntryInstr* body_entry = new TargetEntryInstr(); | 1174 TargetEntryInstr* body_entry = new TargetEntryInstr(); |
| 1165 for_body.AddInstruction(body_entry); | 1175 for_body.AddInstruction(body_entry); |
| 1166 node->body()->Visit(&for_body); | |
| 1167 if (for_body.is_open()) { | 1176 if (for_body.is_open()) { |
|
Vyacheslav Egorov (Google)
2012/06/15 18:02:51
ditto
srdjan
2012/06/15 18:05:06
Done.
| |
| 1168 CheckStackOverflowComp* comp = | 1177 CheckStackOverflowComp* comp = |
| 1169 new CheckStackOverflowComp(node->token_index(), owner()->try_index()); | 1178 new CheckStackOverflowComp(node->token_index(), owner()->try_index()); |
| 1170 for_body.AddInstruction(new DoInstr(comp)); | 1179 for_body.AddInstruction(new DoInstr(comp)); |
| 1171 } | 1180 } |
| 1181 node->body()->Visit(&for_body); | |
| 1172 | 1182 |
| 1173 // Join loop body, increment and compute their end instruction. | 1183 // Join loop body, increment and compute their end instruction. |
| 1174 ASSERT(!for_body.is_empty()); | 1184 ASSERT(!for_body.is_empty()); |
| 1175 Instruction* loop_increment_end = NULL; | 1185 Instruction* loop_increment_end = NULL; |
| 1176 EffectGraphVisitor for_increment(owner(), temp_index()); | 1186 EffectGraphVisitor for_increment(owner(), temp_index()); |
| 1177 if ((node->label()->join_for_continue() == NULL) && for_body.is_open()) { | 1187 if ((node->label()->join_for_continue() == NULL) && for_body.is_open()) { |
| 1178 // Do not insert an extra basic block. | 1188 // Do not insert an extra basic block. |
| 1179 node->increment()->Visit(&for_increment); | 1189 node->increment()->Visit(&for_increment); |
| 1180 for_body.Append(for_increment); | 1190 for_body.Append(for_increment); |
| 1181 loop_increment_end = for_body.exit(); | 1191 loop_increment_end = for_body.exit(); |
| (...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2552 char* chars = reinterpret_cast<char*>( | 2562 char* chars = reinterpret_cast<char*>( |
| 2553 Isolate::Current()->current_zone()->Allocate(len)); | 2563 Isolate::Current()->current_zone()->Allocate(len)); |
| 2554 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2564 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2555 const Error& error = Error::Handle( | 2565 const Error& error = Error::Handle( |
| 2556 LanguageError::New(String::Handle(String::New(chars)))); | 2566 LanguageError::New(String::Handle(String::New(chars)))); |
| 2557 Isolate::Current()->long_jump_base()->Jump(1, error); | 2567 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2558 } | 2568 } |
| 2559 | 2569 |
| 2560 | 2570 |
| 2561 } // namespace dart | 2571 } // namespace dart |
| OLD | NEW |