Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: runtime/vm/flow_graph_builder.cc

Issue 10080015: Implement checked mode in new compiler. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/code_generator_ia32.cc ('k') | runtime/vm/flow_graph_compiler_x64.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/code_descriptors.h" 8 #include "vm/code_descriptors.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flags.h" 10 #include "vm/flags.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 Value* return_value = for_value.value(); 199 Value* return_value = for_value.value();
200 if (FLAG_enable_type_checks) { 200 if (FLAG_enable_type_checks) {
201 const RawFunction::Kind kind = owner()->parsed_function().function().kind(); 201 const RawFunction::Kind kind = owner()->parsed_function().function().kind();
202 const bool is_implicit_getter = 202 const bool is_implicit_getter =
203 (kind == RawFunction::kImplicitGetter) || 203 (kind == RawFunction::kImplicitGetter) ||
204 (kind == RawFunction::kConstImplicitGetter); 204 (kind == RawFunction::kConstImplicitGetter);
205 const bool is_static = owner()->parsed_function().function().is_static(); 205 const bool is_static = owner()->parsed_function().function().is_static();
206 // Implicit getters do not need a type check at return, unless they compute 206 // Implicit getters do not need a type check at return, unless they compute
207 // the initial value of a static field. 207 // the initial value of a static field.
208 if (is_static || !is_implicit_getter) { 208 if (is_static || !is_implicit_getter) {
209 const AbstractType& type = 209 const AbstractType& dst_type =
210 AbstractType::ZoneHandle( 210 AbstractType::ZoneHandle(
211 owner()->parsed_function().function().result_type()); 211 owner()->parsed_function().function().result_type());
212 const String& dst_name =
213 String::ZoneHandle(String::NewSymbol("function result"));
214 Value* type_arguments = NULL;
215 if (!dst_type.IsInstantiated()) {
216 type_arguments = BuildInstantiatorTypeArguments(
217 node->token_index(), for_value.temp_index());
218 }
212 AssertAssignableComp* assert = 219 AssertAssignableComp* assert =
213 new AssertAssignableComp(return_value, type); 220 new AssertAssignableComp(node->id(),
221 node->value()->token_index(),
222 owner()->try_index(),
223 return_value,
224 type_arguments,
225 dst_type,
226 dst_name);
214 AddInstruction(new BindInstr(temp_index(), assert)); 227 AddInstruction(new BindInstr(temp_index(), assert));
215 return_value = new TempVal(temp_index()); 228 return_value = new TempVal(temp_index());
216 } 229 }
217 } 230 }
218 231
219 intptr_t current_context_level = owner()->context_level(); 232 intptr_t current_context_level = owner()->context_level();
220 ASSERT(current_context_level >= 0); 233 ASSERT(current_context_level >= 0);
221 if (owner()->parsed_function().saved_context_var() != NULL) { 234 if (owner()->parsed_function().saved_context_var() != NULL) {
222 // CTX on entry was saved, but not linked as context parent. 235 // CTX on entry was saved, but not linked as context parent.
223 BuildLoadContext(*owner()->parsed_function().saved_context_var(), 0); 236 BuildLoadContext(*owner()->parsed_function().saved_context_var(), 0);
(...skipping 29 matching lines...) Expand all
253 void EffectGraphVisitor::VisitTypeNode(TypeNode* node) { UNREACHABLE(); } 266 void EffectGraphVisitor::VisitTypeNode(TypeNode* node) { UNREACHABLE(); }
254 267
255 268
256 // <Expression> :: Assignable { expr: <Expression> 269 // <Expression> :: Assignable { expr: <Expression>
257 // type: AbstractType 270 // type: AbstractType
258 // dst_name: String } 271 // dst_name: String }
259 void EffectGraphVisitor::VisitAssignableNode(AssignableNode* node) { 272 void EffectGraphVisitor::VisitAssignableNode(AssignableNode* node) {
260 ValueGraphVisitor for_value(owner(), temp_index()); 273 ValueGraphVisitor for_value(owner(), temp_index());
261 node->expr()->Visit(&for_value); 274 node->expr()->Visit(&for_value);
262 Append(for_value); 275 Append(for_value);
263 AssertAssignableComp* assert = 276 Value* type_arguments = NULL;
264 new AssertAssignableComp(for_value.value(), node->type()); 277 if (!node->type().IsInstantiated()) {
265 ReturnComputation(assert); 278 type_arguments = BuildInstantiatorTypeArguments(
279 node->token_index(), for_value.temp_index());
280 }
281 AssertAssignableComp* assert_assignable =
282 new AssertAssignableComp(node->id(),
283 node->token_index(),
284 owner()->try_index(),
285 for_value.value(),
286 type_arguments,
287 node->type(),
288 node->dst_name());
289 ReturnComputation(assert_assignable);
266 } 290 }
267 291
268 292
269 // <Expression> :: BinaryOp { kind: Token::Kind 293 // <Expression> :: BinaryOp { kind: Token::Kind
270 // left: <Expression> 294 // left: <Expression>
271 // right: <Expression> } 295 // right: <Expression> }
272 void EffectGraphVisitor::VisitBinaryOpNode(BinaryOpNode* node) { 296 void EffectGraphVisitor::VisitBinaryOpNode(BinaryOpNode* node) {
273 // Operators "&&" and "||" cannot be overloaded therefore do not call 297 // Operators "&&" and "||" cannot be overloaded therefore do not call
274 // operator. 298 // operator.
275 if ((node->kind() == Token::kAND) || (node->kind() == Token::kOR)) { 299 if ((node->kind() == Token::kAND) || (node->kind() == Token::kOR)) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 333
310 // Special handling for AND/OR. 334 // Special handling for AND/OR.
311 void ValueGraphVisitor::VisitBinaryOpNode(BinaryOpNode* node) { 335 void ValueGraphVisitor::VisitBinaryOpNode(BinaryOpNode* node) {
312 // Operators "&&" and "||" cannot be overloaded therefore do not call 336 // Operators "&&" and "||" cannot be overloaded therefore do not call
313 // operator. 337 // operator.
314 if ((node->kind() == Token::kAND) || (node->kind() == Token::kOR)) { 338 if ((node->kind() == Token::kAND) || (node->kind() == Token::kOR)) {
315 // Implement short-circuit logic: do not evaluate right if evaluation 339 // Implement short-circuit logic: do not evaluate right if evaluation
316 // of left is sufficient. 340 // of left is sufficient.
317 // AND: left ? right === true : false; 341 // AND: left ? right === true : false;
318 // OR: left ? true : right === true; 342 // OR: left ? true : right === true;
319 if (FLAG_enable_type_checks) {
320 Bailout("GenerateConditionTypeCheck in kAND/kOR");
321 }
322 const Bool& bool_true = Bool::ZoneHandle(Bool::True()); 343 const Bool& bool_true = Bool::ZoneHandle(Bool::True());
323 const Bool& bool_false = Bool::ZoneHandle(Bool::False()); 344 const Bool& bool_false = Bool::ZoneHandle(Bool::False());
324 345
325 TestGraphVisitor for_test(owner(), temp_index()); 346 TestGraphVisitor for_test(owner(), temp_index());
326 node->left()->Visit(&for_test); 347 node->left()->Visit(&for_test);
348 if (FLAG_enable_type_checks) {
349 Bailout("GenerateConditionTypeCheck in kAND/kOR");
350 }
327 351
328 ValueGraphVisitor for_right(owner(), temp_index()); 352 ValueGraphVisitor for_right(owner(), temp_index());
329 node->right()->Visit(&for_right); 353 node->right()->Visit(&for_right);
354 if (FLAG_enable_type_checks) {
355 Bailout("GenerateConditionTypeCheck in kAND/kOR");
356 }
330 StrictCompareComp* comp = new StrictCompareComp(Token::kEQ_STRICT, 357 StrictCompareComp* comp = new StrictCompareComp(Token::kEQ_STRICT,
331 for_right.value(), new ConstantVal(bool_true)); 358 for_right.value(), new ConstantVal(bool_true));
332 for_right.AddInstruction(new BindInstr(temp_index(), comp)); 359 for_right.AddInstruction(new BindInstr(temp_index(), comp));
333 360
334 if (node->kind() == Token::kAND) { 361 if (node->kind() == Token::kAND) {
335 ValueGraphVisitor for_false(owner(), temp_index()); 362 ValueGraphVisitor for_false(owner(), temp_index());
336 for_false.AddInstruction( 363 for_false.AddInstruction(
337 new BindInstr(temp_index(), new ConstantVal(bool_false))); 364 new BindInstr(temp_index(), new ConstantVal(bool_false)));
338 Join(for_test, for_right, for_false); 365 Join(for_test, for_right, for_false);
339 } else { 366 } else {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 512 }
486 513
487 ArgumentGraphVisitor for_left_value(owner(), temp_index()); 514 ArgumentGraphVisitor for_left_value(owner(), temp_index());
488 node->left()->Visit(&for_left_value); 515 node->left()->Visit(&for_left_value);
489 Append(for_left_value); 516 Append(for_left_value);
490 Value* type_arguments = NULL; 517 Value* type_arguments = NULL;
491 if (!type.IsInstantiated()) { 518 if (!type.IsInstantiated()) {
492 type_arguments = BuildInstantiatorTypeArguments( 519 type_arguments = BuildInstantiatorTypeArguments(
493 node->token_index(), for_left_value.temp_index()); 520 node->token_index(), for_left_value.temp_index());
494 } 521 }
495 InstanceOfComp* instance_of = new InstanceOfComp( 522 InstanceOfComp* instance_of =
496 node->id(), 523 new InstanceOfComp(node->id(),
497 node->token_index(), 524 node->token_index(),
498 owner()->try_index(), 525 owner()->try_index(),
499 for_left_value.value(), 526 for_left_value.value(),
500 type_arguments, 527 type_arguments,
501 node->right()->AsTypeNode()->type(), 528 node->right()->AsTypeNode()->type(),
502 (node->kind() == Token::kISNOT)); 529 (node->kind() == Token::kISNOT));
503 ReturnComputation(instance_of); 530 ReturnComputation(instance_of);
504 } 531 }
505 532
506 533
507 // <Expression> :: Comparison { kind: Token::Kind 534 // <Expression> :: Comparison { kind: Token::Kind
508 // left: <Expression> 535 // left: <Expression>
509 // right: <Expression> } 536 // right: <Expression> }
510 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) { 537 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) {
511 if (Token::IsInstanceofOperator(node->kind())) { 538 if (Token::IsInstanceofOperator(node->kind())) {
512 BuildInstanceOf(node); 539 BuildInstanceOf(node);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 node->store_id(), node->token_index(), owner()->try_index(), 854 node->store_id(), node->token_index(), owner()->try_index(),
828 store_name, arguments, Array::ZoneHandle(), 1); 855 store_name, arguments, Array::ZoneHandle(), 1);
829 AddInstruction(new DoInstr(store)); 856 AddInstruction(new DoInstr(store));
830 ReturnValue(new TempVal(AllocateTempIndex())); 857 ReturnValue(new TempVal(AllocateTempIndex()));
831 } 858 }
832 859
833 860
834 void EffectGraphVisitor::VisitConditionalExprNode(ConditionalExprNode* node) { 861 void EffectGraphVisitor::VisitConditionalExprNode(ConditionalExprNode* node) {
835 TestGraphVisitor for_test(owner(), temp_index()); 862 TestGraphVisitor for_test(owner(), temp_index());
836 node->condition()->Visit(&for_test); 863 node->condition()->Visit(&for_test);
864 if (FLAG_enable_type_checks) {
865 Bailout("GenerateConditionTypeCheck in conditional expr");
866 }
837 867
838 // Translate the subexpressions for their effects. 868 // Translate the subexpressions for their effects.
839 EffectGraphVisitor for_true(owner(), temp_index()); 869 EffectGraphVisitor for_true(owner(), temp_index());
840 node->true_expr()->Visit(&for_true); 870 node->true_expr()->Visit(&for_true);
841 EffectGraphVisitor for_false(owner(), temp_index()); 871 EffectGraphVisitor for_false(owner(), temp_index());
842 node->false_expr()->Visit(&for_false); 872 node->false_expr()->Visit(&for_false);
843 873
844 Join(for_test, for_true, for_false); 874 Join(for_test, for_true, for_false);
845 } 875 }
846 876
847 877
848 void ValueGraphVisitor::VisitConditionalExprNode(ConditionalExprNode* node) { 878 void ValueGraphVisitor::VisitConditionalExprNode(ConditionalExprNode* node) {
849 TestGraphVisitor for_test(owner(), temp_index()); 879 TestGraphVisitor for_test(owner(), temp_index());
850 node->condition()->Visit(&for_test); 880 node->condition()->Visit(&for_test);
881 if (FLAG_enable_type_checks) {
882 Bailout("GenerateConditionTypeCheck in conditional expr");
883 }
851 884
852 // Ensure that the value of the true/false subexpressions are named with 885 // Ensure that the value of the true/false subexpressions are named with
853 // the same temporary name. 886 // the same temporary name.
854 ValueGraphVisitor for_true(owner(), temp_index()); 887 ValueGraphVisitor for_true(owner(), temp_index());
855 node->true_expr()->Visit(&for_true); 888 node->true_expr()->Visit(&for_true);
856 ASSERT(for_true.is_open()); 889 ASSERT(for_true.is_open());
857 if (for_true.value()->IsTemp()) { 890 if (for_true.value()->IsTemp()) {
858 ASSERT(for_true.value()->AsTemp()->index() == temp_index()); 891 ASSERT(for_true.value()->AsTemp()->index() == temp_index());
859 } else { 892 } else {
860 for_true.AddInstruction(new BindInstr(temp_index(), for_true.value())); 893 for_true.AddInstruction(new BindInstr(temp_index(), for_true.value()));
(...skipping 12 matching lines...) Expand all
873 ReturnValue(new TempVal(AllocateTempIndex())); 906 ReturnValue(new TempVal(AllocateTempIndex()));
874 } 907 }
875 908
876 909
877 // <Statement> ::= If { condition: <Expression> 910 // <Statement> ::= If { condition: <Expression>
878 // true_branch: <Sequence> 911 // true_branch: <Sequence>
879 // false_branch: <Sequence> } 912 // false_branch: <Sequence> }
880 void EffectGraphVisitor::VisitIfNode(IfNode* node) { 913 void EffectGraphVisitor::VisitIfNode(IfNode* node) {
881 TestGraphVisitor for_test(owner(), temp_index()); 914 TestGraphVisitor for_test(owner(), temp_index());
882 node->condition()->Visit(&for_test); 915 node->condition()->Visit(&for_test);
916 if (FLAG_enable_type_checks) {
917 Bailout("GenerateConditionTypeCheck in if");
918 }
883 919
884 EffectGraphVisitor for_true(owner(), temp_index()); 920 EffectGraphVisitor for_true(owner(), temp_index());
885 EffectGraphVisitor for_false(owner(), temp_index()); 921 EffectGraphVisitor for_false(owner(), temp_index());
886 922
887 node->true_branch()->Visit(&for_true); 923 node->true_branch()->Visit(&for_true);
888 // The for_false graph fragment will be empty (default graph fragment) if 924 // The for_false graph fragment will be empty (default graph fragment) if
889 // we do not call Visit. 925 // we do not call Visit.
890 if (node->false_branch() != NULL) node->false_branch()->Visit(&for_false); 926 if (node->false_branch() != NULL) node->false_branch()->Visit(&for_false);
891 Join(for_test, for_true, for_false); 927 Join(for_test, for_true, for_false);
892 } 928 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 // c) [ test ] -> (body-entry-target, loop-exit-target) 1079 // c) [ test ] -> (body-entry-target, loop-exit-target)
1044 // d) body-entry-target 1080 // d) body-entry-target
1045 // e) [ body ] -> (loop-join) 1081 // e) [ body ] -> (loop-join)
1046 // f) loop-exit-target 1082 // f) loop-exit-target
1047 // g) break-join (optional) 1083 // g) break-join (optional)
1048 void EffectGraphVisitor::VisitWhileNode(WhileNode* node) { 1084 void EffectGraphVisitor::VisitWhileNode(WhileNode* node) {
1049 TestGraphVisitor for_test(owner(), temp_index()); 1085 TestGraphVisitor for_test(owner(), temp_index());
1050 node->condition()->Visit(&for_test); 1086 node->condition()->Visit(&for_test);
1051 ASSERT(!for_test.is_empty()); // Language spec. 1087 ASSERT(!for_test.is_empty()); // Language spec.
1052 1088
1089 if (FLAG_enable_type_checks) {
1090 Bailout("GenerateConditionTypeCheck in while");
1091 }
1092
1053 EffectGraphVisitor for_body(owner(), temp_index()); 1093 EffectGraphVisitor for_body(owner(), temp_index());
1054 node->body()->Visit(&for_body); 1094 node->body()->Visit(&for_body);
1055 1095
1056 // Labels are set after body traversal. 1096 // Labels are set after body traversal.
1057 SourceLabel* lbl = node->label(); 1097 SourceLabel* lbl = node->label();
1058 ASSERT(lbl != NULL); 1098 ASSERT(lbl != NULL);
1059 if (lbl->join_for_continue() != NULL) { 1099 if (lbl->join_for_continue() != NULL) {
1060 AddInstruction(lbl->join_for_continue()); 1100 AddInstruction(lbl->join_for_continue());
1061 } 1101 }
1062 TieLoop(for_test, for_body); 1102 TieLoop(for_test, for_body);
(...skipping 13 matching lines...) Expand all
1076 // g) break-join 1116 // g) break-join
1077 void EffectGraphVisitor::VisitDoWhileNode(DoWhileNode* node) { 1117 void EffectGraphVisitor::VisitDoWhileNode(DoWhileNode* node) {
1078 // Traverse body first in order to generate continue and break labels. 1118 // Traverse body first in order to generate continue and break labels.
1079 EffectGraphVisitor for_body(owner(), temp_index()); 1119 EffectGraphVisitor for_body(owner(), temp_index());
1080 node->body()->Visit(&for_body); 1120 node->body()->Visit(&for_body);
1081 1121
1082 TestGraphVisitor for_test(owner(), temp_index()); 1122 TestGraphVisitor for_test(owner(), temp_index());
1083 node->condition()->Visit(&for_test); 1123 node->condition()->Visit(&for_test);
1084 ASSERT(is_open()); 1124 ASSERT(is_open());
1085 1125
1126 if (FLAG_enable_type_checks) {
1127 Bailout("GenerateConditionTypeCheck in do while");
1128 }
1129
1086 // Tie do-while loop (test is after the body). 1130 // Tie do-while loop (test is after the body).
1087 JoinEntryInstr* body_entry_join = new JoinEntryInstr(); 1131 JoinEntryInstr* body_entry_join = new JoinEntryInstr();
1088 AddInstruction(body_entry_join); 1132 AddInstruction(body_entry_join);
1089 body_entry_join->SetSuccessor(for_body.entry()); 1133 body_entry_join->SetSuccessor(for_body.entry());
1090 Instruction* body_exit = 1134 Instruction* body_exit =
1091 for_body.is_empty() ? body_entry_join : for_body.exit(); 1135 for_body.is_empty() ? body_entry_join : for_body.exit();
1092 1136
1093 if (for_body.is_open() || (node->label()->join_for_continue() != NULL)) { 1137 if (for_body.is_open() || (node->label()->join_for_continue() != NULL)) {
1094 BlockEntryInstr* test_entry = NULL; 1138 BlockEntryInstr* test_entry = NULL;
1095 if (node->label()->join_for_continue() == NULL) { 1139 if (node->label()->join_for_continue() == NULL) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 CloseFragment(); 1225 CloseFragment();
1182 } else { 1226 } else {
1183 // Control flow of ForLoop continues into join_for_break. 1227 // Control flow of ForLoop continues into join_for_break.
1184 exit_ = node->label()->join_for_break(); 1228 exit_ = node->label()->join_for_break();
1185 } 1229 }
1186 } else { 1230 } else {
1187 TargetEntryInstr* loop_exit = new TargetEntryInstr(); 1231 TargetEntryInstr* loop_exit = new TargetEntryInstr();
1188 TestGraphVisitor for_test(owner(), temp_index()); 1232 TestGraphVisitor for_test(owner(), temp_index());
1189 node->condition()->Visit(&for_test); 1233 node->condition()->Visit(&for_test);
1190 Append(for_test); 1234 Append(for_test);
1235 if (FLAG_enable_type_checks) {
1236 Bailout("GenerateConditionTypeCheck in for");
1237 }
1191 *for_test.true_successor_address() = body_entry; 1238 *for_test.true_successor_address() = body_entry;
1192 *for_test.false_successor_address() = loop_exit; 1239 *for_test.false_successor_address() = loop_exit;
1193 if (node->label()->join_for_break() == NULL) { 1240 if (node->label()->join_for_break() == NULL) {
1194 exit_ = loop_exit; 1241 exit_ = loop_exit;
1195 } else { 1242 } else {
1196 loop_exit->SetSuccessor(node->label()->join_for_break()); 1243 loop_exit->SetSuccessor(node->label()->join_for_break());
1197 exit_ = node->label()->join_for_break(); 1244 exit_ = node->label()->join_for_break();
1198 } 1245 }
1199 } 1246 }
1200 } 1247 }
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 1751
1705 // <Expression> ::= StoreLocal { local: LocalVariable 1752 // <Expression> ::= StoreLocal { local: LocalVariable
1706 // value: <Expression> } 1753 // value: <Expression> }
1707 void EffectGraphVisitor::VisitStoreLocalNode(StoreLocalNode* node) { 1754 void EffectGraphVisitor::VisitStoreLocalNode(StoreLocalNode* node) {
1708 ValueGraphVisitor for_value(owner(), temp_index()); 1755 ValueGraphVisitor for_value(owner(), temp_index());
1709 node->value()->Visit(&for_value); 1756 node->value()->Visit(&for_value);
1710 Append(for_value); 1757 Append(for_value);
1711 1758
1712 Value* value = for_value.value(); 1759 Value* value = for_value.value();
1713 if (FLAG_enable_type_checks) { 1760 if (FLAG_enable_type_checks) {
1714 AssertAssignableComp* assert = 1761 Value* type_arguments = NULL;
1715 new AssertAssignableComp(value, node->local().type()); 1762 if (!node->local().type().IsInstantiated()) {
1716 AddInstruction(new BindInstr(temp_index(), assert)); 1763 type_arguments = BuildInstantiatorTypeArguments(
1764 node->token_index(), for_value.temp_index());
1765 }
1766 AssertAssignableComp* assert_assignable =
1767 new AssertAssignableComp(node->id(),
1768 node->local().token_index(),
1769 owner()->try_index(),
1770 value,
1771 type_arguments,
1772 node->local().type(),
1773 node->local().name());
1774 AddInstruction(new BindInstr(temp_index(), assert_assignable));
1717 value = new TempVal(temp_index()); 1775 value = new TempVal(temp_index());
1718 } 1776 }
1719 1777
1720 StoreLocalComp* store = 1778 StoreLocalComp* store =
1721 new StoreLocalComp(node->local(), value, owner()->context_level()); 1779 new StoreLocalComp(node->local(), value, owner()->context_level());
1722 ReturnComputation(store); 1780 ReturnComputation(store);
1723 } 1781 }
1724 1782
1725 1783
1726 void EffectGraphVisitor::VisitLoadInstanceFieldNode( 1784 void EffectGraphVisitor::VisitLoadInstanceFieldNode(
(...skipping 11 matching lines...) Expand all
1738 StoreInstanceFieldNode* node) { 1796 StoreInstanceFieldNode* node) {
1739 ValueGraphVisitor for_instance(owner(), temp_index()); 1797 ValueGraphVisitor for_instance(owner(), temp_index());
1740 node->instance()->Visit(&for_instance); 1798 node->instance()->Visit(&for_instance);
1741 Append(for_instance); 1799 Append(for_instance);
1742 ValueGraphVisitor for_value(owner(), for_instance.temp_index()); 1800 ValueGraphVisitor for_value(owner(), for_instance.temp_index());
1743 node->value()->Visit(&for_value); 1801 node->value()->Visit(&for_value);
1744 Append(for_value); 1802 Append(for_value);
1745 Value* store_value = for_value.value(); 1803 Value* store_value = for_value.value();
1746 if (FLAG_enable_type_checks) { 1804 if (FLAG_enable_type_checks) {
1747 const AbstractType& type = AbstractType::ZoneHandle(node->field().type()); 1805 const AbstractType& type = AbstractType::ZoneHandle(node->field().type());
1748 AssertAssignableComp* assert = new AssertAssignableComp(store_value, type); 1806 Value* type_arguments = NULL;
1749 AddInstruction(new BindInstr(temp_index(), assert)); 1807 if (!type.IsInstantiated()) {
1750 store_value = new TempVal(temp_index()); 1808 type_arguments = BuildInstantiatorTypeArguments(
1809 node->token_index(), for_value.temp_index());
1810 }
1811 AssertAssignableComp* assert_assignable =
1812 new AssertAssignableComp(node->id(),
1813 node->value()->token_index(),
1814 owner()->try_index(),
1815 store_value,
1816 type_arguments,
1817 type,
1818 String::ZoneHandle(node->field().name()));
1819 AddInstruction(new BindInstr(temp_index() + 1, assert_assignable));
1820 store_value = new TempVal(temp_index() + 1);
1751 } 1821 }
1752 StoreInstanceFieldComp* store = 1822 StoreInstanceFieldComp* store =
1753 new StoreInstanceFieldComp(node, for_instance.value(), store_value); 1823 new StoreInstanceFieldComp(node, for_instance.value(), store_value);
1754 ReturnComputation(store); 1824 ReturnComputation(store);
1755 } 1825 }
1756 1826
1757 1827
1758 void EffectGraphVisitor::VisitLoadStaticFieldNode(LoadStaticFieldNode* node) { 1828 void EffectGraphVisitor::VisitLoadStaticFieldNode(LoadStaticFieldNode* node) {
1759 LoadStaticFieldComp* load = new LoadStaticFieldComp(node->field()); 1829 LoadStaticFieldComp* load = new LoadStaticFieldComp(node->field());
1760 ReturnComputation(load); 1830 ReturnComputation(load);
1761 } 1831 }
1762 1832
1763 1833
1764 void EffectGraphVisitor::VisitStoreStaticFieldNode(StoreStaticFieldNode* node) { 1834 void EffectGraphVisitor::VisitStoreStaticFieldNode(StoreStaticFieldNode* node) {
1765 ValueGraphVisitor for_value(owner(), temp_index()); 1835 ValueGraphVisitor for_value(owner(), temp_index());
1766 node->value()->Visit(&for_value); 1836 node->value()->Visit(&for_value);
1767 Append(for_value); 1837 Append(for_value);
1768 Value* store_value = for_value.value(); 1838 Value* store_value = for_value.value();
1769 if (FLAG_enable_type_checks) { 1839 if (FLAG_enable_type_checks) {
1770 const AbstractType& type = AbstractType::ZoneHandle(node->field().type()); 1840 const AbstractType& type = AbstractType::ZoneHandle(node->field().type());
1771 AssertAssignableComp* assert = new AssertAssignableComp(store_value, type); 1841 Value* type_arguments = NULL;
1772 AddInstruction(new BindInstr(temp_index(), assert)); 1842 if (!type.IsInstantiated()) {
1843 type_arguments = BuildInstantiatorTypeArguments(
1844 node->token_index(), for_value.temp_index());
1845 }
1846 AssertAssignableComp* assert_assignable =
1847 new AssertAssignableComp(node->id(),
1848 node->field().token_index(),
1849 owner()->try_index(),
1850 store_value,
1851 type_arguments,
1852 type,
1853 String::ZoneHandle(node->field().name()));
1854 AddInstruction(new BindInstr(temp_index(), assert_assignable));
1773 store_value = new TempVal(temp_index()); 1855 store_value = new TempVal(temp_index());
1774 } 1856 }
1775 StoreStaticFieldComp* store = 1857 StoreStaticFieldComp* store =
1776 new StoreStaticFieldComp(node->field(), store_value); 1858 new StoreStaticFieldComp(node->field(), store_value);
1777 ReturnComputation(store); 1859 ReturnComputation(store);
1778 } 1860 }
1779 1861
1780 1862
1781 void EffectGraphVisitor::VisitLoadIndexedNode(LoadIndexedNode* node) { 1863 void EffectGraphVisitor::VisitLoadIndexedNode(LoadIndexedNode* node) {
1782 ArgumentGraphVisitor for_array(owner(), temp_index()); 1864 ArgumentGraphVisitor for_array(owner(), temp_index());
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 new ConstantVal(Object::ZoneHandle()), 1996 new ConstantVal(Object::ZoneHandle()),
1915 owner()->context_level()); 1997 owner()->context_level());
1916 AddInstruction(new DoInstr(clear_local)); 1998 AddInstruction(new DoInstr(clear_local));
1917 } 1999 }
1918 } 2000 }
1919 } 2001 }
1920 } 2002 }
1921 2003
1922 if (FLAG_enable_type_checks && 2004 if (FLAG_enable_type_checks &&
1923 (node == owner()->parsed_function().node_sequence())) { 2005 (node == owner()->parsed_function().node_sequence())) {
1924 Bailout("VisitSequenceNode GenerateArgumentTypeChecks()"); 2006 const int num_params =
2007 owner()->parsed_function().function().NumberOfParameters();
2008 for (int pos = 0; pos < num_params; pos++) {
2009 const LocalVariable& parameter = *scope->VariableAt(pos);
2010 ASSERT(parameter.owner() == scope);
2011 LoadLocalComp* load = new LoadLocalComp(parameter,
2012 owner()->context_level());
2013 AddInstruction(new BindInstr(temp_index(), load));
2014 TempVal* argument_value = new TempVal(temp_index());
2015 Value* type_arguments = NULL;
2016 if (!parameter.type().IsInstantiated()) {
2017 type_arguments = BuildInstantiatorTypeArguments(
2018 node->token_index(), temp_index() + 1);
2019 }
2020 AssertAssignableComp* assert_assignable =
2021 new AssertAssignableComp(node->id(),
2022 parameter.token_index(),
2023 owner()->try_index(),
2024 argument_value,
2025 type_arguments,
2026 parameter.type(),
2027 parameter.name());
2028 AddInstruction(new DoInstr(assert_assignable));
2029 }
1925 } 2030 }
1926 2031
1927 intptr_t i = 0; 2032 intptr_t i = 0;
1928 while (is_open() && (i < node->length())) { 2033 while (is_open() && (i < node->length())) {
1929 EffectGraphVisitor for_effect(owner(), temp_index()); 2034 EffectGraphVisitor for_effect(owner(), temp_index());
1930 node->NodeAt(i++)->Visit(&for_effect); 2035 node->NodeAt(i++)->Visit(&for_effect);
1931 Append(for_effect); 2036 Append(for_effect);
1932 if (!is_open()) { 2037 if (!is_open()) {
1933 // E.g., because of a JumpNode. 2038 // E.g., because of a JumpNode.
1934 break; 2039 break;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 2254
2150 2255
2151 void FlowGraphPrinter::VisitConstant(ConstantVal* val) { 2256 void FlowGraphPrinter::VisitConstant(ConstantVal* val) {
2152 OS::Print("#%s", val->value().ToCString()); 2257 OS::Print("#%s", val->value().ToCString());
2153 } 2258 }
2154 2259
2155 2260
2156 void FlowGraphPrinter::VisitAssertAssignable(AssertAssignableComp* comp) { 2261 void FlowGraphPrinter::VisitAssertAssignable(AssertAssignableComp* comp) {
2157 OS::Print("AssertAssignable("); 2262 OS::Print("AssertAssignable(");
2158 comp->value()->Accept(this); 2263 comp->value()->Accept(this);
2159 OS::Print(", %s)", comp->type().ToCString()); 2264 OS::Print(", %s, '%s'",
2265 comp->dst_type().ToCString(),
2266 comp->dst_name().ToCString());
2267 if (comp->type_arguments() != NULL) {
2268 OS::Print(" (type-arg:");
2269 comp->type_arguments()->Accept(this);
2270 }
2271 OS::Print(")");
2272 }
2273
2274
2275 void FlowGraphPrinter::VisitAssertBoolean(AssertBooleanComp* comp) {
2276 OS::Print("AssertBoolean(");
2277 comp->value()->Accept(this);
2278 OS::Print(")");
2160 } 2279 }
2161 2280
2162 2281
2163 void FlowGraphPrinter::VisitCurrentContext(CurrentContextComp* comp) { 2282 void FlowGraphPrinter::VisitCurrentContext(CurrentContextComp* comp) {
2164 OS::Print("CurrentContext"); 2283 OS::Print("CurrentContext");
2165 } 2284 }
2166 2285
2167 2286
2168 void FlowGraphPrinter::VisitClosureCall(ClosureCallComp* comp) { 2287 void FlowGraphPrinter::VisitClosureCall(ClosureCallComp* comp) {
2169 OS::Print("ClosureCall("); 2288 OS::Print("ClosureCall(");
(...skipping 18 matching lines...) Expand all
2188 2307
2189 void FlowGraphPrinter::VisitStrictCompare(StrictCompareComp* comp) { 2308 void FlowGraphPrinter::VisitStrictCompare(StrictCompareComp* comp) {
2190 OS::Print("StrictCompare(%s, ", Token::Str(comp->kind())); 2309 OS::Print("StrictCompare(%s, ", Token::Str(comp->kind()));
2191 comp->left()->Accept(this); 2310 comp->left()->Accept(this);
2192 OS::Print(", "); 2311 OS::Print(", ");
2193 comp->right()->Accept(this); 2312 comp->right()->Accept(this);
2194 OS::Print(")"); 2313 OS::Print(")");
2195 } 2314 }
2196 2315
2197 2316
2198
2199 void FlowGraphPrinter::VisitStaticCall(StaticCallComp* comp) { 2317 void FlowGraphPrinter::VisitStaticCall(StaticCallComp* comp) {
2200 OS::Print("StaticCall(%s", 2318 OS::Print("StaticCall(%s",
2201 String::Handle(comp->function().name()).ToCString()); 2319 String::Handle(comp->function().name()).ToCString());
2202 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) { 2320 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) {
2203 OS::Print(", "); 2321 OS::Print(", ");
2204 comp->ArgumentAt(i)->Accept(this); 2322 comp->ArgumentAt(i)->Accept(this);
2205 } 2323 }
2206 OS::Print(")"); 2324 OS::Print(")");
2207 } 2325 }
2208 2326
(...skipping 19 matching lines...) Expand all
2228 void FlowGraphPrinter::VisitLoadInstanceField(LoadInstanceFieldComp* comp) { 2346 void FlowGraphPrinter::VisitLoadInstanceField(LoadInstanceFieldComp* comp) {
2229 OS::Print("LoadInstanceField(%s, ", 2347 OS::Print("LoadInstanceField(%s, ",
2230 String::Handle(comp->field().name()).ToCString()); 2348 String::Handle(comp->field().name()).ToCString());
2231 comp->instance()->Accept(this); 2349 comp->instance()->Accept(this);
2232 OS::Print(")"); 2350 OS::Print(")");
2233 } 2351 }
2234 2352
2235 2353
2236 void FlowGraphPrinter::VisitStoreInstanceField(StoreInstanceFieldComp* comp) { 2354 void FlowGraphPrinter::VisitStoreInstanceField(StoreInstanceFieldComp* comp) {
2237 OS::Print("StoreInstanceField(%s, ", 2355 OS::Print("StoreInstanceField(%s, ",
2238 String::Handle(comp->field().name()).ToCString()); 2356 String::Handle(comp->field().name()).ToCString());
2239 comp->instance()->Accept(this); 2357 comp->instance()->Accept(this);
2240 OS::Print(", "); 2358 OS::Print(", ");
2241 comp->value()->Accept(this); 2359 comp->value()->Accept(this);
2242 OS::Print(")"); 2360 OS::Print(")");
2243 } 2361 }
2244 2362
2245 2363
2246 void FlowGraphPrinter::VisitLoadStaticField(LoadStaticFieldComp* comp) { 2364 void FlowGraphPrinter::VisitLoadStaticField(LoadStaticFieldComp* comp) {
2247 OS::Print("LoadStaticField(%s)", 2365 OS::Print("LoadStaticField(%s)",
2248 String::Handle(comp->field().name()).ToCString()); 2366 String::Handle(comp->field().name()).ToCString());
2249 } 2367 }
2250 2368
2251 2369
2252 void FlowGraphPrinter::VisitStoreStaticField(StoreStaticFieldComp* comp) { 2370 void FlowGraphPrinter::VisitStoreStaticField(StoreStaticFieldComp* comp) {
2253 OS::Print("StoreStaticField(%s, ", 2371 OS::Print("StoreStaticField(%s, ",
2254 String::Handle(comp->field().name()).ToCString()); 2372 String::Handle(comp->field().name()).ToCString());
2255 comp->value()->Accept(this); 2373 comp->value()->Accept(this);
2256 OS::Print(")"); 2374 OS::Print(")");
2257 } 2375 }
2258 2376
2259 2377
2260 void FlowGraphPrinter::VisitStoreIndexed(StoreIndexedComp* comp) { 2378 void FlowGraphPrinter::VisitStoreIndexed(StoreIndexedComp* comp) {
2261 OS::Print("StoreIndexed("); 2379 OS::Print("StoreIndexed(");
2262 comp->array()->Accept(this); 2380 comp->array()->Accept(this);
2263 OS::Print(", "); 2381 OS::Print(", ");
2264 comp->index()->Accept(this); 2382 comp->index()->Accept(this);
(...skipping 21 matching lines...) Expand all
2286 2404
2287 void FlowGraphPrinter::VisitBooleanNegate(BooleanNegateComp* comp) { 2405 void FlowGraphPrinter::VisitBooleanNegate(BooleanNegateComp* comp) {
2288 OS::Print("! "); 2406 OS::Print("! ");
2289 comp->value()->Accept(this); 2407 comp->value()->Accept(this);
2290 } 2408 }
2291 2409
2292 2410
2293 void FlowGraphPrinter::VisitInstanceOf(InstanceOfComp* comp) { 2411 void FlowGraphPrinter::VisitInstanceOf(InstanceOfComp* comp) {
2294 comp->value()->Accept(this); 2412 comp->value()->Accept(this);
2295 OS::Print(" %s %s", 2413 OS::Print(" %s %s",
2296 comp->negate_result() ? "ISNOT" : "IS", 2414 comp->negate_result() ? "ISNOT" : "IS",
2297 String::Handle(comp->type().Name()).ToCString()); 2415 String::Handle(comp->type().Name()).ToCString());
2298 if (comp->type_arguments() != NULL) { 2416 if (comp->type_arguments() != NULL) {
2299 OS::Print(" (type-arg:"); 2417 OS::Print(" (type-arg:");
2300 comp->type_arguments()->Accept(this); 2418 comp->type_arguments()->Accept(this);
2301 OS::Print(")");
2302 } 2419 }
2420 OS::Print(")");
2303 } 2421 }
2304 2422
2305 2423
2306 void FlowGraphPrinter::VisitAllocateObject(AllocateObjectComp* comp) { 2424 void FlowGraphPrinter::VisitAllocateObject(AllocateObjectComp* comp) {
2307 OS::Print("AllocateObject(%s", 2425 OS::Print("AllocateObject(%s",
2308 Class::Handle(comp->constructor().owner()).ToCString()); 2426 Class::Handle(comp->constructor().owner()).ToCString());
2309 for (intptr_t i = 0; i < comp->arguments().length(); i++) { 2427 for (intptr_t i = 0; i < comp->arguments().length(); i++) {
2310 OS::Print(", "); 2428 OS::Print(", ");
2311 comp->arguments()[i]->Accept(this); 2429 comp->arguments()[i]->Accept(this);
2312 } 2430 }
2313 OS::Print(")"); 2431 OS::Print(")");
2314 } 2432 }
2315 2433
2316 2434
2317 void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) { 2435 void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) {
2318 OS::Print("CreateArray("); 2436 OS::Print("CreateArray(");
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 2498
2381 2499
2382 void FlowGraphPrinter::VisitCloneContext(CloneContextComp* comp) { 2500 void FlowGraphPrinter::VisitCloneContext(CloneContextComp* comp) {
2383 OS::Print("CloneContext("); 2501 OS::Print("CloneContext(");
2384 comp->context_value()->Accept(this); 2502 comp->context_value()->Accept(this);
2385 OS::Print(")"); 2503 OS::Print(")");
2386 } 2504 }
2387 2505
2388 2506
2389 void FlowGraphPrinter::VisitCatchEntry(CatchEntryComp* comp) { 2507 void FlowGraphPrinter::VisitCatchEntry(CatchEntryComp* comp) {
2390 OS::Print("CatchEntry(%s, %s)", comp->exception_var().name().ToCString(), 2508 OS::Print("CatchEntry(%s, %s)",
2391 comp->stacktrace_var().name().ToCString()); 2509 comp->exception_var().name().ToCString(),
2510 comp->stacktrace_var().name().ToCString());
2392 } 2511 }
2393 2512
2394 2513
2395 void FlowGraphPrinter::VisitStoreContext(StoreContextComp* comp) { 2514 void FlowGraphPrinter::VisitStoreContext(StoreContextComp* comp) {
2396 OS::Print("StoreContext("); 2515 OS::Print("StoreContext(");
2397 comp->value()->Accept(this); 2516 comp->value()->Accept(this);
2398 OS::Print(")"); 2517 OS::Print(")");
2399 } 2518 }
2400 2519
2401 2520
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 char* chars = reinterpret_cast<char*>( 2721 char* chars = reinterpret_cast<char*>(
2603 Isolate::Current()->current_zone()->Allocate(len)); 2722 Isolate::Current()->current_zone()->Allocate(len));
2604 OS::SNPrint(chars, len, kFormat, function_name, reason); 2723 OS::SNPrint(chars, len, kFormat, function_name, reason);
2605 const Error& error = Error::Handle( 2724 const Error& error = Error::Handle(
2606 LanguageError::New(String::Handle(String::New(chars)))); 2725 LanguageError::New(String::Handle(String::New(chars))));
2607 Isolate::Current()->long_jump_base()->Jump(1, error); 2726 Isolate::Current()->long_jump_base()->Jump(1, error);
2608 } 2727 }
2609 2728
2610 2729
2611 } // namespace dart 2730 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/code_generator_ia32.cc ('k') | runtime/vm/flow_graph_compiler_x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698