| 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 "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/code_descriptors.h" | 10 #include "vm/code_descriptors.h" |
| (...skipping 3076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3087 (scope != NULL) ? scope->num_context_variables() : 0; | 3087 (scope != NULL) ? scope->num_context_variables() : 0; |
| 3088 int previous_context_level = owner()->context_level(); | 3088 int previous_context_level = owner()->context_level(); |
| 3089 if (num_context_variables > 0) { | 3089 if (num_context_variables > 0) { |
| 3090 InlineBailout("EffectGraphVisitor::VisitSequenceNode (context)"); | 3090 InlineBailout("EffectGraphVisitor::VisitSequenceNode (context)"); |
| 3091 // The loop local scope declares variables that are captured. | 3091 // The loop local scope declares variables that are captured. |
| 3092 // Allocate and chain a new context. | 3092 // Allocate and chain a new context. |
| 3093 // Allocate context computation (uses current CTX) | 3093 // Allocate context computation (uses current CTX) |
| 3094 Value* allocated_context = | 3094 Value* allocated_context = |
| 3095 Bind(new AllocateContextInstr(node->token_pos(), | 3095 Bind(new AllocateContextInstr(node->token_pos(), |
| 3096 num_context_variables)); | 3096 num_context_variables)); |
| 3097 | 3097 { LocalVariable* tmp_var = EnterTempLocalScope(allocated_context); |
| 3098 // If this node_sequence is the body of the function being compiled, and if | 3098 // If this node_sequence is the body of the function being compiled, and |
| 3099 // this function allocates context variables, but none of its enclosing | 3099 // if this function allocates context variables, but none of its enclosing |
| 3100 // functions do, the context on entry is not linked as parent of the | 3100 // functions do, the context on entry is not linked as parent of the |
| 3101 // allocated context but saved on entry and restored on exit as to prevent | 3101 // allocated context but saved on entry and restored on exit as to prevent |
| 3102 // memory leaks. | 3102 // memory leaks. |
| 3103 // In this case, the parser pre-allocates a variable to save the context. | 3103 // In this case, the parser pre-allocates a variable to save the context. |
| 3104 if (MustSaveRestoreContext(node)) { | 3104 if (MustSaveRestoreContext(node)) { |
| 3105 Value* current_context = Bind(new CurrentContextInstr()); |
| 3106 Do(BuildStoreTemp( |
| 3107 *owner()->parsed_function()->saved_entry_context_var(), |
| 3108 current_context)); |
| 3109 Value* null_context = Bind(new ConstantInstr(Object::ZoneHandle())); |
| 3110 AddInstruction(new StoreContextInstr(null_context)); |
| 3111 } |
| 3105 Value* current_context = Bind(new CurrentContextInstr()); | 3112 Value* current_context = Bind(new CurrentContextInstr()); |
| 3106 Do(BuildStoreTemp(*owner()->parsed_function()->saved_entry_context_var(), | 3113 Value* tmp_val = Bind(new LoadLocalInstr(*tmp_var)); |
| 3107 current_context)); | 3114 Do(new StoreVMFieldInstr(tmp_val, |
| 3108 Value* null_context = Bind(new ConstantInstr(Object::ZoneHandle())); | 3115 Context::parent_offset(), |
| 3109 AddInstruction(new StoreContextInstr(null_context)); | 3116 current_context, |
| 3117 Type::ZoneHandle())); |
| 3118 AddInstruction( |
| 3119 new StoreContextInstr(Bind(ExitTempLocalScope(tmp_var)))); |
| 3110 } | 3120 } |
| 3111 | |
| 3112 AddInstruction(new ChainContextInstr(allocated_context)); | |
| 3113 owner()->set_context_level(scope->context_level()); | 3121 owner()->set_context_level(scope->context_level()); |
| 3114 | 3122 |
| 3115 // If this node_sequence is the body of the function being compiled, copy | 3123 // If this node_sequence is the body of the function being compiled, copy |
| 3116 // the captured parameters from the frame into the context. | 3124 // the captured parameters from the frame into the context. |
| 3117 if (node == owner()->parsed_function()->node_sequence()) { | 3125 if (node == owner()->parsed_function()->node_sequence()) { |
| 3118 ASSERT(scope->context_level() == 1); | 3126 ASSERT(scope->context_level() == 1); |
| 3119 const Function& function = owner()->parsed_function()->function(); | 3127 const Function& function = owner()->parsed_function()->function(); |
| 3120 const int num_params = function.NumParameters(); | 3128 const int num_params = function.NumParameters(); |
| 3121 int param_frame_index = (num_params == function.num_fixed_parameters()) ? | 3129 int param_frame_index = (num_params == function.num_fixed_parameters()) ? |
| 3122 (kParamEndSlotFromFp + num_params) : kFirstLocalSlotFromFp; | 3130 (kParamEndSlotFromFp + num_params) : kFirstLocalSlotFromFp; |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3546 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 3554 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 3547 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3555 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 3548 OS::SNPrint(chars, len, kFormat, function_name, reason); | 3556 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 3549 const Error& error = Error::Handle( | 3557 const Error& error = Error::Handle( |
| 3550 LanguageError::New(String::Handle(String::New(chars)))); | 3558 LanguageError::New(String::Handle(String::New(chars)))); |
| 3551 Isolate::Current()->long_jump_base()->Jump(1, error); | 3559 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 3552 } | 3560 } |
| 3553 | 3561 |
| 3554 | 3562 |
| 3555 } // namespace dart | 3563 } // namespace dart |
| OLD | NEW |