| 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 CheckStackOverflowComp* comp = |
| 1077 new CheckStackOverflowComp(node->token_index(), owner()->try_index()); |
| 1078 for_body.AddInstruction(new DoInstr(comp)); |
| 1076 node->body()->Visit(&for_body); | 1079 node->body()->Visit(&for_body); |
| 1077 | 1080 |
| 1078 // Labels are set after body traversal. | 1081 // Labels are set after body traversal. |
| 1079 SourceLabel* lbl = node->label(); | 1082 SourceLabel* lbl = node->label(); |
| 1080 ASSERT(lbl != NULL); | 1083 ASSERT(lbl != NULL); |
| 1081 if (lbl->join_for_continue() != NULL) { | 1084 if (lbl->join_for_continue() != NULL) { |
| 1082 AddInstruction(lbl->join_for_continue()); | 1085 AddInstruction(lbl->join_for_continue()); |
| 1083 } | 1086 } |
| 1084 TieLoop(for_test, for_body); | 1087 TieLoop(for_test, for_body); |
| 1085 if (lbl->join_for_break() != NULL) { | 1088 if (lbl->join_for_break() != NULL) { |
| 1086 AddInstruction(lbl->join_for_break()); | 1089 AddInstruction(lbl->join_for_break()); |
| 1087 } | 1090 } |
| 1088 } | 1091 } |
| 1089 | 1092 |
| 1090 | 1093 |
| 1091 // The fragment is composed as follows: | 1094 // The fragment is composed as follows: |
| 1092 // a) body-entry-join | 1095 // a) body-entry-join |
| 1093 // b) [ body ] | 1096 // b) [ body ] |
| 1094 // c) test-entry (continue-join or body-exit-target) | 1097 // c) test-entry (continue-join or body-exit-target) |
| 1095 // d) [ test-entry ] -> (back-target, loop-exit-target) | 1098 // d) [ test-entry ] -> (back-target, loop-exit-target) |
| 1096 // e) back-target -> (body-entry-join) | 1099 // e) back-target -> (body-entry-join) |
| 1097 // f) loop-exit-target | 1100 // f) loop-exit-target |
| 1098 // g) break-join | 1101 // g) break-join |
| 1099 void EffectGraphVisitor::VisitDoWhileNode(DoWhileNode* node) { | 1102 void EffectGraphVisitor::VisitDoWhileNode(DoWhileNode* node) { |
| 1100 // Traverse body first in order to generate continue and break labels. | 1103 // Traverse body first in order to generate continue and break labels. |
| 1101 EffectGraphVisitor for_body(owner(), temp_index()); | 1104 EffectGraphVisitor for_body(owner(), temp_index()); |
| 1105 CheckStackOverflowComp* comp = |
| 1106 new CheckStackOverflowComp(node->token_index(), owner()->try_index()); |
| 1107 for_body.AddInstruction(new DoInstr(comp)); |
| 1102 node->body()->Visit(&for_body); | 1108 node->body()->Visit(&for_body); |
| 1103 | 1109 |
| 1104 TestGraphVisitor for_test(owner(), | 1110 TestGraphVisitor for_test(owner(), |
| 1105 temp_index(), | 1111 temp_index(), |
| 1106 node->condition()->token_index()); | 1112 node->condition()->token_index()); |
| 1107 node->condition()->Visit(&for_test); | 1113 node->condition()->Visit(&for_test); |
| 1108 ASSERT(is_open()); | 1114 ASSERT(is_open()); |
| 1109 | 1115 |
| 1110 // Tie do-while loop (test is after the body). | 1116 // Tie do-while loop (test is after the body). |
| 1111 JoinEntryInstr* body_entry_join = new JoinEntryInstr(); | 1117 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) { | 1162 void EffectGraphVisitor::VisitForNode(ForNode* node) { |
| 1157 EffectGraphVisitor for_initializer(owner(), temp_index()); | 1163 EffectGraphVisitor for_initializer(owner(), temp_index()); |
| 1158 node->initializer()->Visit(&for_initializer); | 1164 node->initializer()->Visit(&for_initializer); |
| 1159 Append(for_initializer); | 1165 Append(for_initializer); |
| 1160 ASSERT(is_open()); | 1166 ASSERT(is_open()); |
| 1161 | 1167 |
| 1162 // Compose body to set any jump labels. | 1168 // Compose body to set any jump labels. |
| 1163 EffectGraphVisitor for_body(owner(), temp_index()); | 1169 EffectGraphVisitor for_body(owner(), temp_index()); |
| 1164 TargetEntryInstr* body_entry = new TargetEntryInstr(); | 1170 TargetEntryInstr* body_entry = new TargetEntryInstr(); |
| 1165 for_body.AddInstruction(body_entry); | 1171 for_body.AddInstruction(body_entry); |
| 1172 CheckStackOverflowComp* comp = |
| 1173 new CheckStackOverflowComp(node->token_index(), owner()->try_index()); |
| 1174 for_body.AddInstruction(new DoInstr(comp)); |
| 1166 node->body()->Visit(&for_body); | 1175 node->body()->Visit(&for_body); |
| 1167 if (for_body.is_open()) { | |
| 1168 CheckStackOverflowComp* comp = | |
| 1169 new CheckStackOverflowComp(node->token_index(), owner()->try_index()); | |
| 1170 for_body.AddInstruction(new DoInstr(comp)); | |
| 1171 } | |
| 1172 | 1176 |
| 1173 // Join loop body, increment and compute their end instruction. | 1177 // Join loop body, increment and compute their end instruction. |
| 1174 ASSERT(!for_body.is_empty()); | 1178 ASSERT(!for_body.is_empty()); |
| 1175 Instruction* loop_increment_end = NULL; | 1179 Instruction* loop_increment_end = NULL; |
| 1176 EffectGraphVisitor for_increment(owner(), temp_index()); | 1180 EffectGraphVisitor for_increment(owner(), temp_index()); |
| 1177 if ((node->label()->join_for_continue() == NULL) && for_body.is_open()) { | 1181 if ((node->label()->join_for_continue() == NULL) && for_body.is_open()) { |
| 1178 // Do not insert an extra basic block. | 1182 // Do not insert an extra basic block. |
| 1179 node->increment()->Visit(&for_increment); | 1183 node->increment()->Visit(&for_increment); |
| 1180 for_body.Append(for_increment); | 1184 for_body.Append(for_increment); |
| 1181 loop_increment_end = for_body.exit(); | 1185 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*>( | 2556 char* chars = reinterpret_cast<char*>( |
| 2553 Isolate::Current()->current_zone()->Allocate(len)); | 2557 Isolate::Current()->current_zone()->Allocate(len)); |
| 2554 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2558 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2555 const Error& error = Error::Handle( | 2559 const Error& error = Error::Handle( |
| 2556 LanguageError::New(String::Handle(String::New(chars)))); | 2560 LanguageError::New(String::Handle(String::New(chars)))); |
| 2557 Isolate::Current()->long_jump_base()->Jump(1, error); | 2561 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2558 } | 2562 } |
| 2559 | 2563 |
| 2560 | 2564 |
| 2561 } // namespace dart | 2565 } // namespace dart |
| OLD | NEW |