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

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

Issue 888463004: Add support for sync* and yield (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 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
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 "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/ast_printer.h" 8 #include "vm/ast_printer.h"
9 #include "vm/bit_vector.h" 9 #include "vm/bit_vector.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 1068
1069 // Async functions contain two types of return statements: 1069 // Async functions contain two types of return statements:
1070 // 1) Returns that should complete the completer once all finally blocks have 1070 // 1) Returns that should complete the completer once all finally blocks have
1071 // been inlined (call: :async_completer.complete(return_value)). These 1071 // been inlined (call: :async_completer.complete(return_value)). These
1072 // returns end up returning null in the end. 1072 // returns end up returning null in the end.
1073 // 2) "Continuation" returns that should not complete the completer but return 1073 // 2) "Continuation" returns that should not complete the completer but return
1074 // the value. 1074 // the value.
1075 // 1075 //
1076 // We distinguish those kinds of nodes via is_regular_return(). 1076 // We distinguish those kinds of nodes via is_regular_return().
1077 // 1077 //
1078 if (function.is_async_closure() && 1078 if (function.IsAsyncClosure() &&
1079 (node->return_type() == ReturnNode::kRegular)) { 1079 (node->return_type() == ReturnNode::kRegular)) {
1080 // Temporary store the computed return value. 1080 // Temporary store the computed return value.
1081 Do(BuildStoreExprTemp(return_value)); 1081 Do(BuildStoreExprTemp(return_value));
1082 1082
1083 LocalVariable* rcv_var = node->scope()->LookupVariable( 1083 LocalVariable* rcv_var =
1084 Symbols::AsyncCompleter(), false); 1084 node->scope()->LookupVariable(Symbols::AsyncCompleter(), false);
1085 ASSERT(rcv_var != NULL && rcv_var->is_captured()); 1085 ASSERT(rcv_var != NULL && rcv_var->is_captured());
1086 ZoneGrowableArray<PushArgumentInstr*>* arguments = 1086 ZoneGrowableArray<PushArgumentInstr*>* arguments =
1087 new(I) ZoneGrowableArray<PushArgumentInstr*>(2); 1087 new(I) ZoneGrowableArray<PushArgumentInstr*>(2);
1088 Value* rcv_value = Bind(BuildLoadLocal(*rcv_var)); 1088 Value* rcv_value = Bind(BuildLoadLocal(*rcv_var));
1089 arguments->Add(PushArgument(rcv_value)); 1089 arguments->Add(PushArgument(rcv_value));
1090 Value* returned_value = Bind(BuildLoadExprTemp()); 1090 Value* returned_value = Bind(BuildLoadExprTemp());
1091 arguments->Add(PushArgument(returned_value)); 1091 arguments->Add(PushArgument(returned_value));
1092 InstanceCallInstr* call = new(I) InstanceCallInstr( 1092 InstanceCallInstr* call = new(I) InstanceCallInstr(
1093 Scanner::kNoSourcePos, 1093 Scanner::kNoSourcePos,
1094 Symbols::CompleterComplete(), 1094 Symbols::CompleterComplete(),
1095 Token::kILLEGAL, 1095 Token::kILLEGAL,
1096 arguments, 1096 arguments,
1097 Object::null_array(), 1097 Object::null_array(),
1098 1, 1098 1,
1099 owner()->ic_data_array()); 1099 owner()->ic_data_array());
1100 Do(call); 1100 Do(call);
1101 1101
1102 // Rebind the return value for the actual return call to be null. 1102 // Rebind the return value for the actual return call to be null.
1103 return_value = BuildNullValue(); 1103 return_value = BuildNullValue();
1104 } 1104 }
1105 1105
1106 intptr_t current_context_level = owner()->context_level(); 1106 intptr_t current_context_level = owner()->context_level();
1107 ASSERT(current_context_level >= 0); 1107 ASSERT(current_context_level >= 0);
1108 if (HasContextScope()) { 1108 if (HasContextScope()) {
1109 UnchainContexts(current_context_level); 1109 UnchainContexts(current_context_level);
1110 } 1110 }
1111 1111
1112
1113 AddReturnExit(node->token_pos(), return_value); 1112 AddReturnExit(node->token_pos(), return_value);
1114 1113
1115 if (function.is_async_closure() && 1114 if ((function.IsAsyncClosure() || function.IsSyncGenClosure()) &&
1116 (node->return_type() == ReturnNode::kContinuationTarget)) { 1115 (node->return_type() == ReturnNode::kContinuationTarget)) {
1117 JoinEntryInstr* const join = new(I) JoinEntryInstr( 1116 JoinEntryInstr* const join = new(I) JoinEntryInstr(
1118 owner()->AllocateBlockId(), owner()->try_index()); 1117 owner()->AllocateBlockId(), owner()->try_index());
1119 owner()->await_joins()->Add(join); 1118 owner()->await_joins()->Add(join);
1120 exit_ = join; 1119 exit_ = join;
1121 } 1120 }
1122 } 1121 }
1123 1122
1124 1123
1125 // <Expression> ::= Literal { literal: Instance } 1124 // <Expression> ::= Literal { literal: Instance }
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 return new(I) AssertAssignableInstr(token_pos, 1476 return new(I) AssertAssignableInstr(token_pos,
1478 value, 1477 value,
1479 instantiator, 1478 instantiator,
1480 instantiator_type_arguments, 1479 instantiator_type_arguments,
1481 dst_type, 1480 dst_type,
1482 dst_name, 1481 dst_name,
1483 deopt_id); 1482 deopt_id);
1484 } 1483 }
1485 1484
1486 1485
1486 void EffectGraphVisitor::BuildYieldJump(LocalVariable* old_context,
1487 LocalVariable* iterator_param,
1488 const intptr_t old_ctx_level,
1489 JoinEntryInstr* target) {
1490 // Building a jump consists of the following actions:
1491 // * Load the generator body's iterator parameter (:iterator)
1492 // from the current context into a temporary.
1493 // * Restore the old context from :await_cxt_var.
1494 // * Copy the iterator saved above into the restored context.
1495 // * Append a Goto to the target's join.
1496 ASSERT((iterator_param != NULL) && iterator_param->is_captured());
1497 ASSERT((old_context != NULL) && old_context->is_captured());
1498 // Before restoring the context we need to temporarily save the
1499 // iterator parameter.
1500 LocalVariable* temp_iterator_var =
1501 EnterTempLocalScope(Bind(BuildLoadLocal(*iterator_param)));
1502
1503 // Restore the saved continuation context, i.e. the context that was
1504 // saved into :await_ctx_var before the closure suspended.
1505 BuildRestoreContext(*old_context);
1506
1507 // Store the continuation result and continuation error values into
1508 // the restored context.
1509
1510 // FlowGraphBuilder is at top context level, but the continuation
1511 // target has possibly been recorded in a nested context (old_ctx_level).
1512 // We need to unroll manually here.
1513 intptr_t delta =
1514 old_ctx_level - iterator_param->owner()->context_level();
1515 ASSERT(delta >= 0);
1516 Value* context = Bind(BuildCurrentContext());
1517 while (delta-- > 0) {
1518 context = Bind(new(I) LoadFieldInstr(
1519 context, Context::parent_offset(), Type::ZoneHandle(I, Type::null()),
1520 Scanner::kNoSourcePos));
1521 }
1522 LocalVariable* temp_context_var = EnterTempLocalScope(context);
1523
1524 Value* context_val = Bind(new(I) LoadLocalInstr(*temp_context_var));
1525 Value* store_val = Bind(new(I) LoadLocalInstr(*temp_iterator_var));
1526 StoreInstanceFieldInstr* store = new(I) StoreInstanceFieldInstr(
1527 Context::variable_offset(iterator_param->index()),
1528 context_val,
1529 store_val,
1530 kEmitStoreBarrier,
1531 Scanner::kNoSourcePos);
1532 Do(store);
1533
1534 Do(ExitTempLocalScope(temp_context_var));
1535 Do(ExitTempLocalScope(temp_iterator_var));
1536
1537 // Goto saved join.
1538 Goto(target);
1539 }
1540
1541
1487 void EffectGraphVisitor::BuildAwaitJump(LocalVariable* old_context, 1542 void EffectGraphVisitor::BuildAwaitJump(LocalVariable* old_context,
1488 LocalVariable* continuation_result, 1543 LocalVariable* continuation_result,
1489 LocalVariable* continuation_error, 1544 LocalVariable* continuation_error,
1490 LocalVariable* continuation_stack_trace, 1545 LocalVariable* continuation_stack_trace,
1491 const intptr_t old_ctx_level, 1546 const intptr_t old_ctx_level,
1492 JoinEntryInstr* target) { 1547 JoinEntryInstr* target) {
1493 // Building a jump consists of the following actions: 1548 // Building a jump consists of the following actions:
1494 // * Record the current continuation result in a temporary. 1549 // * Load the current continuation result parameter (:async_result)
1495 // * Restore the old context. 1550 // and continuation error parameter (:async_error_param) from
1496 // * Overwrite the old context's continuation result with the temporary. 1551 // the current context into temporaries.
1552 // * Restore the old context from :await_cxt_var.
1553 // * Copy the result and error parameters saved above into the restored
1554 // context.
1497 // * Append a Goto to the target's join. 1555 // * Append a Goto to the target's join.
1498 ASSERT((continuation_result != NULL) && continuation_result->is_captured()); 1556 ASSERT((continuation_result != NULL) && continuation_result->is_captured());
1499 ASSERT((continuation_error != NULL) && continuation_error->is_captured()); 1557 ASSERT((continuation_error != NULL) && continuation_error->is_captured());
1500 ASSERT((old_context != NULL) && old_context->is_captured()); 1558 ASSERT((old_context != NULL) && old_context->is_captured());
1501 // Before restoring the continuation context we need to temporary save the 1559 // Before restoring the continuation context we need to temporary save the
1502 // result and error parameter. 1560 // result and error parameter.
1503 LocalVariable* temp_result_var = EnterTempLocalScope( 1561 LocalVariable* temp_result_var =
1504 Bind(BuildLoadLocal(*continuation_result))); 1562 EnterTempLocalScope(Bind(BuildLoadLocal(*continuation_result)));
1505 LocalVariable* temp_error_var = EnterTempLocalScope( 1563 LocalVariable* temp_error_var =
1506 Bind(BuildLoadLocal(*continuation_error))); 1564 EnterTempLocalScope(Bind(BuildLoadLocal(*continuation_error)));
1507 LocalVariable* temp_stack_trace_var = EnterTempLocalScope( 1565 LocalVariable* temp_stack_trace_var =
1508 Bind(BuildLoadLocal(*continuation_stack_trace))); 1566 EnterTempLocalScope(Bind(BuildLoadLocal(*continuation_stack_trace)));
1509 // Restore the saved continuation context. 1567
1568 // Restore the saved continuation context, i.e. the context that was
1569 // saved into :await_ctx_var before the closure suspended.
1510 BuildRestoreContext(*old_context); 1570 BuildRestoreContext(*old_context);
1511 1571
1512 // Pass over the continuation result. 1572 // Store the continuation result and continuation error values into
1573 // the restored context.
1513 1574
1514 // FlowGraphBuilder is at top context level, but the await target has possibly 1575 // FlowGraphBuilder is at top context level, but the await target has possibly
1515 // been recorded in a nested context (old_ctx_level). We need to unroll 1576 // been recorded in a nested context (old_ctx_level). We need to unroll
1516 // manually here. 1577 // manually here.
1517 intptr_t delta = old_ctx_level - 1578 intptr_t delta =
1518 continuation_result->owner()->context_level(); 1579 old_ctx_level - continuation_result->owner()->context_level();
1519 ASSERT(delta >= 0); 1580 ASSERT(delta >= 0);
1520 Value* context = Bind(BuildCurrentContext()); 1581 Value* context = Bind(BuildCurrentContext());
1521 while (delta-- > 0) { 1582 while (delta-- > 0) {
1522 context = Bind(new(I) LoadFieldInstr( 1583 context = Bind(new(I) LoadFieldInstr(
1523 context, Context::parent_offset(), Type::ZoneHandle(I, Type::null()), 1584 context, Context::parent_offset(), Type::ZoneHandle(I, Type::null()),
1524 Scanner::kNoSourcePos)); 1585 Scanner::kNoSourcePos));
1525 } 1586 }
1526 LocalVariable* temp_context_var = EnterTempLocalScope(context); 1587 LocalVariable* temp_context_var = EnterTempLocalScope(context);
1527 1588
1528 Value* context_val = Bind(new(I) LoadLocalInstr(*temp_context_var)); 1589 Value* context_val = Bind(new(I) LoadLocalInstr(*temp_context_var));
(...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after
3746 Do(BuildStoreContext(context)); 3807 Do(BuildStoreContext(context));
3747 } 3808 }
3748 } 3809 }
3749 3810
3750 3811
3751 // <Statement> ::= Sequence { scope: LocalScope 3812 // <Statement> ::= Sequence { scope: LocalScope
3752 // nodes: <Statement>* 3813 // nodes: <Statement>*
3753 // label: SourceLabel } 3814 // label: SourceLabel }
3754 void EffectGraphVisitor::VisitSequenceNode(SequenceNode* node) { 3815 void EffectGraphVisitor::VisitSequenceNode(SequenceNode* node) {
3755 LocalScope* scope = node->scope(); 3816 LocalScope* scope = node->scope();
3817 const Function& function = owner()->function();
3756 const intptr_t num_context_variables = 3818 const intptr_t num_context_variables =
3757 (scope != NULL) ? scope->num_context_variables() : 0; 3819 (scope != NULL) ? scope->num_context_variables() : 0;
3758 const bool is_top_level_sequence = 3820 const bool is_top_level_sequence =
3759 node == owner()->parsed_function().node_sequence(); 3821 node == owner()->parsed_function().node_sequence();
3760 // The outermost function sequence cannot contain a label. 3822 // The outermost function sequence cannot contain a label.
3761 ASSERT((node->label() == NULL) || !is_top_level_sequence); 3823 ASSERT((node->label() == NULL) || !is_top_level_sequence);
3762 NestedBlock nested_block(owner(), node); 3824 NestedBlock nested_block(owner(), node);
3763 3825
3764 if (num_context_variables > 0) { 3826 if (num_context_variables > 0) {
3765 // The local scope declares variables that are captured. 3827 // The local scope declares variables that are captured.
(...skipping 12 matching lines...) Expand all
3778 kEmitStoreBarrier, 3840 kEmitStoreBarrier,
3779 Scanner::kNoSourcePos)); 3841 Scanner::kNoSourcePos));
3780 } 3842 }
3781 Do(BuildStoreContext(Bind(ExitTempLocalScope(tmp_var)))); 3843 Do(BuildStoreContext(Bind(ExitTempLocalScope(tmp_var))));
3782 } 3844 }
3783 3845
3784 // If this node_sequence is the body of the function being compiled, copy 3846 // If this node_sequence is the body of the function being compiled, copy
3785 // the captured parameters from the frame into the context. 3847 // the captured parameters from the frame into the context.
3786 if (is_top_level_sequence) { 3848 if (is_top_level_sequence) {
3787 ASSERT(scope->context_level() == 1); 3849 ASSERT(scope->context_level() == 1);
3788 const Function& function = owner()->function();
3789 const int num_params = function.NumParameters(); 3850 const int num_params = function.NumParameters();
3790 int param_frame_index = (num_params == function.num_fixed_parameters()) ? 3851 int param_frame_index = (num_params == function.num_fixed_parameters()) ?
3791 (kParamEndSlotFromFp + num_params) : kFirstLocalSlotFromFp; 3852 (kParamEndSlotFromFp + num_params) : kFirstLocalSlotFromFp;
3792 for (int pos = 0; pos < num_params; param_frame_index--, pos++) { 3853 for (int pos = 0; pos < num_params; param_frame_index--, pos++) {
3793 const LocalVariable& parameter = *scope->VariableAt(pos); 3854 const LocalVariable& parameter = *scope->VariableAt(pos);
3794 ASSERT(parameter.owner() == scope); 3855 ASSERT(parameter.owner() == scope);
3795 if (parameter.is_captured()) { 3856 if (parameter.is_captured()) {
3796 // Create a temporary local describing the original position. 3857 // Create a temporary local describing the original position.
3797 const String& temp_name = Symbols::TempParam(); 3858 const String& temp_name = Symbols::TempParam();
3798 LocalVariable* temp_local = new(I) LocalVariable( 3859 LocalVariable* temp_local = new(I) LocalVariable(
(...skipping 17 matching lines...) Expand all
3816 Value* null_constant = Bind(new(I) ConstantInstr( 3877 Value* null_constant = Bind(new(I) ConstantInstr(
3817 Object::ZoneHandle(I, Object::null()))); 3878 Object::ZoneHandle(I, Object::null())));
3818 Do(BuildStoreLocal(*temp_local, null_constant)); 3879 Do(BuildStoreLocal(*temp_local, null_constant));
3819 } 3880 }
3820 } 3881 }
3821 } 3882 }
3822 } 3883 }
3823 3884
3824 // This check may be deleted if the generated code is leaf. 3885 // This check may be deleted if the generated code is leaf.
3825 // Native functions don't need a stack check at entry. 3886 // Native functions don't need a stack check at entry.
3826 const Function& function = owner()->function();
3827 if (is_top_level_sequence && !function.is_native()) { 3887 if (is_top_level_sequence && !function.is_native()) {
3828 // Always allocate CheckOverflowInstr so that deopt-ids match regardless 3888 // Always allocate CheckOverflowInstr so that deopt-ids match regardless
3829 // if we inline or not. 3889 // if we inline or not.
3830 if (!function.IsImplicitGetterFunction() && 3890 if (!function.IsImplicitGetterFunction() &&
3831 !function.IsImplicitSetterFunction()) { 3891 !function.IsImplicitSetterFunction()) {
3832 CheckStackOverflowInstr* check = 3892 CheckStackOverflowInstr* check =
3833 new(I) CheckStackOverflowInstr(function.token_pos(), 0); 3893 new(I) CheckStackOverflowInstr(function.token_pos(), 0);
3834 // If we are inlining don't actually attach the stack check. We must still 3894 // If we are inlining don't actually attach the stack check. We must still
3835 // create the stack check in order to allocate a deopt id. 3895 // create the stack check in order to allocate a deopt id.
3836 if (!owner()->IsInlining()) { 3896 if (!owner()->IsInlining()) {
3837 AddInstruction(check); 3897 AddInstruction(check);
3838 } 3898 }
3839 } 3899 }
3840 } 3900 }
3841 3901
3842 if (Isolate::Current()->TypeChecksEnabled() && is_top_level_sequence) { 3902 if (Isolate::Current()->TypeChecksEnabled() && is_top_level_sequence) {
3843 const Function& function = owner()->function();
3844 const int num_params = function.NumParameters(); 3903 const int num_params = function.NumParameters();
3845 int pos = 0; 3904 int pos = 0;
3846 if (function.IsConstructor()) { 3905 if (function.IsConstructor()) {
3847 // Skip type checking of receiver and phase for constructor functions. 3906 // Skip type checking of receiver and phase for constructor functions.
3848 pos = 2; 3907 pos = 2;
3849 } else if (function.IsFactory() || function.IsDynamicFunction()) { 3908 } else if (function.IsFactory() || function.IsDynamicFunction()) {
3850 // Skip type checking of type arguments for factory functions. 3909 // Skip type checking of type arguments for factory functions.
3851 // Skip type checking of receiver for instance functions. 3910 // Skip type checking of receiver for instance functions.
3852 pos = 1; 3911 pos = 1;
3853 } 3912 }
3854 while (pos < num_params) { 3913 while (pos < num_params) {
3855 const LocalVariable& parameter = *scope->VariableAt(pos); 3914 const LocalVariable& parameter = *scope->VariableAt(pos);
3856 ASSERT(parameter.owner() == scope); 3915 ASSERT(parameter.owner() == scope);
3857 if (!CanSkipTypeCheck(parameter.token_pos(), 3916 if (!CanSkipTypeCheck(parameter.token_pos(),
3858 NULL, 3917 NULL,
3859 parameter.type(), 3918 parameter.type(),
3860 parameter.name())) { 3919 parameter.name())) {
3861 Value* parameter_value = Bind(BuildLoadLocal(parameter)); 3920 Value* parameter_value = Bind(BuildLoadLocal(parameter));
3862 Do(BuildAssertAssignable(parameter.token_pos(), 3921 Do(BuildAssertAssignable(parameter.token_pos(),
3863 parameter_value, 3922 parameter_value,
3864 parameter.type(), 3923 parameter.type(),
3865 parameter.name())); 3924 parameter.name()));
3866 } 3925 }
3867 pos++; 3926 pos++;
3868 } 3927 }
3869 } 3928 }
3870 3929
3871 // Continuation part: 3930 // Continuation part:
3872 // If this node sequence is the body of an async closure leave room for a 3931 // If this node sequence is the body of a function with continuations,
3873 // preamble. The preamble is generated after visiting the body. 3932 // leave room for a preamble.
3933 // The preamble is generated after visiting the body.
3874 GotoInstr* preamble_start = NULL; 3934 GotoInstr* preamble_start = NULL;
3875 if (is_top_level_sequence && (owner()->function().is_async_closure())) { 3935 if (is_top_level_sequence &&
3936 (function.IsAsyncClosure() || function.IsSyncGenClosure())) {
3876 JoinEntryInstr* preamble_end = new(I) JoinEntryInstr( 3937 JoinEntryInstr* preamble_end = new(I) JoinEntryInstr(
3877 owner()->AllocateBlockId(), owner()->try_index()); 3938 owner()->AllocateBlockId(), owner()->try_index());
3878 ASSERT(exit() != NULL); 3939 ASSERT(exit() != NULL);
3879 exit()->Goto(preamble_end); 3940 exit()->Goto(preamble_end);
3880 ASSERT(exit()->next()->IsGoto()); 3941 ASSERT(exit()->next()->IsGoto());
3881 preamble_start = exit()->next()->AsGoto(); 3942 preamble_start = exit()->next()->AsGoto();
3882 ASSERT(preamble_start->IsGoto()); 3943 ASSERT(preamble_start->IsGoto());
3883 exit_ = preamble_end; 3944 exit_ = preamble_end;
3884 } 3945 }
3885 3946
3886 intptr_t i = 0; 3947 intptr_t i = 0;
3887 while (is_open() && (i < node->length())) { 3948 while (is_open() && (i < node->length())) {
3888 EffectGraphVisitor for_effect(owner()); 3949 EffectGraphVisitor for_effect(owner());
3889 node->NodeAt(i++)->Visit(&for_effect); 3950 node->NodeAt(i++)->Visit(&for_effect);
3890 Append(for_effect); 3951 Append(for_effect);
3891 if (!is_open()) { 3952 if (!is_open()) {
3892 // E.g., because of a JumpNode. 3953 // E.g., because of a JumpNode.
3893 break; 3954 break;
3894 } 3955 }
3895 } 3956 }
3896 3957
3897 // Continuation part: 3958 // Continuation part:
3898 // After generating the CFG for the body we can create the preamble because we 3959 // After generating the CFG for the body we can create the preamble
3899 // know exactly how many continuation states we need. 3960 // because we know exactly how many continuation states we need.
3900 if (is_top_level_sequence && (owner()->function().is_async_closure())) { 3961 if (is_top_level_sequence &&
3962 (function.IsAsyncClosure() || function.IsSyncGenClosure())) {
3901 ASSERT(preamble_start != NULL); 3963 ASSERT(preamble_start != NULL);
3902 // We are at the top level. Fetch the corresponding scope. 3964 // We are at the top level. Fetch the corresponding scope.
3903 LocalScope* top_scope = node->scope(); 3965 LocalScope* top_scope = node->scope();
3904 LocalVariable* jump_var = top_scope->LookupVariable( 3966 LocalVariable* jump_var = top_scope->LookupVariable(
3905 Symbols::AwaitJumpVar(), false); 3967 Symbols::AwaitJumpVar(), false);
3906 ASSERT(jump_var != NULL && jump_var->is_captured()); 3968 ASSERT(jump_var != NULL && jump_var->is_captured());
3907
3908 Instruction* saved_entry = entry_; 3969 Instruction* saved_entry = entry_;
3909 Instruction* saved_exit = exit_; 3970 Instruction* saved_exit = exit_;
3910 entry_ = NULL; 3971 entry_ = NULL;
3911 exit_ = NULL; 3972 exit_ = NULL;
3912 3973
3913 LoadLocalNode* load_jump_count = new(I) LoadLocalNode( 3974 LoadLocalNode* load_jump_count =
3914 Scanner::kNoSourcePos, jump_var); 3975 new(I) LoadLocalNode(Scanner::kNoSourcePos, jump_var);
3915 ComparisonNode* check_jump_count; 3976 ComparisonNode* check_jump_count;
3916 const intptr_t num_await_states = owner()->await_joins()->length(); 3977 const intptr_t num_await_states = owner()->await_joins()->length();
3978
3917 LocalVariable* old_context = top_scope->LookupVariable( 3979 LocalVariable* old_context = top_scope->LookupVariable(
3918 Symbols::AwaitContextVar(), false); 3980 Symbols::AwaitContextVar(), false);
3919 LocalVariable* continuation_result = top_scope->LookupVariable(
3920 Symbols::AsyncOperationParam(), false);
3921 LocalVariable* continuation_error = top_scope->LookupVariable(
3922 Symbols::AsyncOperationErrorParam(), false);
3923 LocalVariable* continuation_stack_trace = top_scope->LookupVariable(
3924 Symbols::AsyncOperationStackTraceParam(), false);
3925 for (intptr_t i = 0; i < num_await_states; i++) { 3981 for (intptr_t i = 0; i < num_await_states; i++) {
3926 check_jump_count = new(I) ComparisonNode( 3982 check_jump_count = new(I) ComparisonNode(
3927 Scanner::kNoSourcePos, 3983 Scanner::kNoSourcePos,
3928 Token::kEQ, 3984 Token::kEQ,
3929 load_jump_count, 3985 load_jump_count,
3930 new(I) LiteralNode( 3986 new(I) LiteralNode(
3931 Scanner::kNoSourcePos, Smi::ZoneHandle(I, Smi::New(i)))); 3987 Scanner::kNoSourcePos, Smi::ZoneHandle(I, Smi::New(i))));
3932 TestGraphVisitor for_test(owner(), Scanner::kNoSourcePos); 3988 TestGraphVisitor for_test(owner(), Scanner::kNoSourcePos);
3933 check_jump_count->Visit(&for_test); 3989 check_jump_count->Visit(&for_test);
3934 EffectGraphVisitor for_true(owner()); 3990 EffectGraphVisitor for_true(owner());
3935 EffectGraphVisitor for_false(owner()); 3991 EffectGraphVisitor for_false(owner());
3936 3992
3937 for_true.BuildAwaitJump(old_context, 3993 if (function.IsAsyncClosure()) {
3938 continuation_result, 3994 LocalVariable* result_param =
3939 continuation_error, 3995 top_scope->LookupVariable(Symbols::AsyncOperationParam(), false);
3940 continuation_stack_trace, 3996 LocalVariable* error_param =
3941 (*owner()->await_levels())[i], 3997 top_scope->LookupVariable(Symbols::AsyncOperationErrorParam(),
3942 (*owner()->await_joins())[i]); 3998 false);
3999 LocalVariable* stack_trace_param =
4000 top_scope->LookupVariable(Symbols::AsyncOperationStackTraceParam(),
4001 false);
4002 for_true.BuildAwaitJump(old_context,
4003 result_param,
4004 error_param,
4005 stack_trace_param,
4006 (*owner()->await_levels())[i],
4007 (*owner()->await_joins())[i]);
4008 } else {
4009 ASSERT(function.IsSyncGenClosure());
4010 LocalVariable* iterator_param =
4011 top_scope->LookupVariable(Symbols::IteratorParameter(), false);
4012 for_true.BuildYieldJump(old_context,
4013 iterator_param,
4014 (*owner()->await_levels())[i],
4015 (*owner()->await_joins())[i]);
4016 }
4017
3943 Join(for_test, for_true, for_false); 4018 Join(for_test, for_true, for_false);
3944
3945 if (i == 0) { 4019 if (i == 0) {
3946 // Manually link up the preamble start. 4020 // Manually link up the preamble start.
3947 preamble_start->previous()->set_next(for_test.entry()); 4021 preamble_start->previous()->set_next(for_test.entry());
3948 for_test.entry()->set_previous(preamble_start->previous()); 4022 for_test.entry()->set_previous(preamble_start->previous());
3949 } 4023 }
3950 if (i == (num_await_states - 1)) { 4024 if (i == (num_await_states - 1)) {
3951 // Link up preamble end. 4025 // Link up preamble end.
3952 if (exit_ == NULL) { 4026 if (exit_ == NULL) {
3953 exit_ = preamble_start; 4027 exit_ = preamble_start;
3954 } else { 4028 } else {
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
4333 Report::MessageF(Report::kBailout, 4407 Report::MessageF(Report::kBailout,
4334 Script::Handle(function.script()), 4408 Script::Handle(function.script()),
4335 function.token_pos(), 4409 function.token_pos(),
4336 "FlowGraphBuilder Bailout: %s %s", 4410 "FlowGraphBuilder Bailout: %s %s",
4337 String::Handle(function.name()).ToCString(), 4411 String::Handle(function.name()).ToCString(),
4338 reason); 4412 reason);
4339 UNREACHABLE(); 4413 UNREACHABLE();
4340 } 4414 }
4341 4415
4342 } // namespace dart 4416 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698