| 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/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 2259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2270 type_arguments = BuildInstantiatorTypeArguments(node->token_pos(), | 2270 type_arguments = BuildInstantiatorTypeArguments(node->token_pos(), |
| 2271 instantiator_class, | 2271 instantiator_class, |
| 2272 NULL); | 2272 NULL); |
| 2273 arguments->Add(PushArgument(type_arguments)); | 2273 arguments->Add(PushArgument(type_arguments)); |
| 2274 } | 2274 } |
| 2275 AllocateObjectInstr* alloc = new AllocateObjectInstr(node->token_pos(), | 2275 AllocateObjectInstr* alloc = new AllocateObjectInstr(node->token_pos(), |
| 2276 cls, | 2276 cls, |
| 2277 arguments); | 2277 arguments); |
| 2278 alloc->set_closure_function(function); | 2278 alloc->set_closure_function(function); |
| 2279 | 2279 |
| 2280 // Create fake fields for function and context. Only the context field is | |
| 2281 // stored at the allocation to be used later when inlining a closure call. | |
| 2282 const Field& function_field = | |
| 2283 Field::ZoneHandle( | |
| 2284 Field::New(Symbols::ClosureFunctionField(), | |
| 2285 false, // !static | |
| 2286 true, // final | |
| 2287 false, // !const | |
| 2288 alloc->cls(), | |
| 2289 0)); // No token position. | |
| 2290 function_field.SetOffset(Closure::function_offset()); | |
| 2291 const Field& context_field = | |
| 2292 Field::ZoneHandle(Field::New( | |
| 2293 Symbols::ClosureContextField(), | |
| 2294 false, // !static | |
| 2295 true, // final | |
| 2296 false, // !const | |
| 2297 alloc->cls(), | |
| 2298 0)); // No token position. | |
| 2299 context_field.SetOffset(Closure::context_offset()); | |
| 2300 alloc->set_context_field(context_field); | |
| 2301 | |
| 2302 Value* closure_val = Bind(alloc); | 2280 Value* closure_val = Bind(alloc); |
| 2303 { LocalVariable* closure_tmp_var = EnterTempLocalScope(closure_val); | 2281 { LocalVariable* closure_tmp_var = EnterTempLocalScope(closure_val); |
| 2304 // Store function. | 2282 // Store function. |
| 2305 Value* closure_tmp_val = Bind(new LoadLocalInstr(*closure_tmp_var)); | 2283 Value* closure_tmp_val = Bind(new LoadLocalInstr(*closure_tmp_var)); |
| 2306 Value* func_val = | 2284 Value* func_val = |
| 2307 Bind(new ConstantInstr(Function::ZoneHandle(function.raw()))); | 2285 Bind(new ConstantInstr(Function::ZoneHandle(function.raw()))); |
| 2308 Do(new StoreInstanceFieldInstr(function_field, | 2286 Do(new StoreInstanceFieldInstr(Closure::function_offset(), |
| 2309 closure_tmp_val, | 2287 closure_tmp_val, |
| 2310 func_val, | 2288 func_val, |
| 2311 kEmitStoreBarrier)); | 2289 kEmitStoreBarrier)); |
| 2312 if (is_implicit) { | 2290 if (is_implicit) { |
| 2313 // Create new context containing the receiver. | 2291 // Create new context containing the receiver. |
| 2314 const intptr_t kNumContextVariables = 1; // The receiver. | 2292 const intptr_t kNumContextVariables = 1; // The receiver. |
| 2315 Value* allocated_context = | 2293 Value* allocated_context = |
| 2316 Bind(new AllocateContextInstr(node->token_pos(), | 2294 Bind(new AllocateContextInstr(node->token_pos(), |
| 2317 kNumContextVariables)); | 2295 kNumContextVariables)); |
| 2318 { LocalVariable* context_tmp_var = EnterTempLocalScope(allocated_context); | 2296 { LocalVariable* context_tmp_var = EnterTempLocalScope(allocated_context); |
| 2319 // Store receiver in context. | 2297 // Store receiver in context. |
| 2320 Value* context_tmp_val = Bind(new LoadLocalInstr(*context_tmp_var)); | 2298 Value* context_tmp_val = Bind(new LoadLocalInstr(*context_tmp_var)); |
| 2321 ValueGraphVisitor for_receiver(owner()); | 2299 ValueGraphVisitor for_receiver(owner()); |
| 2322 node->receiver()->Visit(&for_receiver); | 2300 node->receiver()->Visit(&for_receiver); |
| 2323 Append(for_receiver); | 2301 Append(for_receiver); |
| 2324 Value* receiver = for_receiver.value(); | 2302 Value* receiver = for_receiver.value(); |
| 2325 Do(new StoreInstanceFieldInstr(Context::variable_offset(0), | 2303 Do(new StoreInstanceFieldInstr(Context::variable_offset(0), |
| 2326 context_tmp_val, | 2304 context_tmp_val, |
| 2327 receiver, | 2305 receiver, |
| 2328 kEmitStoreBarrier)); | 2306 kEmitStoreBarrier)); |
| 2329 // Store new context in closure. | 2307 // Store new context in closure. |
| 2330 closure_tmp_val = Bind(new LoadLocalInstr(*closure_tmp_var)); | 2308 closure_tmp_val = Bind(new LoadLocalInstr(*closure_tmp_var)); |
| 2331 context_tmp_val = Bind(new LoadLocalInstr(*context_tmp_var)); | 2309 context_tmp_val = Bind(new LoadLocalInstr(*context_tmp_var)); |
| 2332 Do(new StoreInstanceFieldInstr(context_field, | 2310 Do(new StoreInstanceFieldInstr(Closure::context_offset(), |
| 2333 closure_tmp_val, | 2311 closure_tmp_val, |
| 2334 context_tmp_val, | 2312 context_tmp_val, |
| 2335 kEmitStoreBarrier)); | 2313 kEmitStoreBarrier)); |
| 2336 Do(ExitTempLocalScope(context_tmp_var)); | 2314 Do(ExitTempLocalScope(context_tmp_var)); |
| 2337 } | 2315 } |
| 2338 } else { | 2316 } else { |
| 2339 // Store current context in closure. | 2317 // Store current context in closure. |
| 2340 closure_tmp_val = Bind(new LoadLocalInstr(*closure_tmp_var)); | 2318 closure_tmp_val = Bind(new LoadLocalInstr(*closure_tmp_var)); |
| 2341 Value* context = Bind(new CurrentContextInstr()); | 2319 Value* context = Bind(new CurrentContextInstr()); |
| 2342 Do(new StoreInstanceFieldInstr(context_field, | 2320 Do(new StoreInstanceFieldInstr(Closure::context_offset(), |
| 2343 closure_tmp_val, | 2321 closure_tmp_val, |
| 2344 context, | 2322 context, |
| 2345 kEmitStoreBarrier)); | 2323 kEmitStoreBarrier)); |
| 2346 } | 2324 } |
| 2347 ReturnDefinition(ExitTempLocalScope(closure_tmp_var)); | 2325 ReturnDefinition(ExitTempLocalScope(closure_tmp_var)); |
| 2348 } | 2326 } |
| 2349 } | 2327 } |
| 2350 | 2328 |
| 2351 | 2329 |
| 2352 void EffectGraphVisitor::BuildPushArguments( | 2330 void EffectGraphVisitor::BuildPushArguments( |
| (...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3925 LanguageError::kError, | 3903 LanguageError::kError, |
| 3926 Heap::kNew, | 3904 Heap::kNew, |
| 3927 "FlowGraphBuilder Bailout: %s %s", | 3905 "FlowGraphBuilder Bailout: %s %s", |
| 3928 String::Handle(function.name()).ToCString(), | 3906 String::Handle(function.name()).ToCString(), |
| 3929 reason)); | 3907 reason)); |
| 3930 Isolate::Current()->long_jump_base()->Jump(1, error); | 3908 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 3931 } | 3909 } |
| 3932 | 3910 |
| 3933 | 3911 |
| 3934 } // namespace dart | 3912 } // namespace dart |
| OLD | NEW |