| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "vm/kernel_to_il.h" | 7 #include "vm/kernel_to_il.h" |
| 8 | 8 |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/intermediate_language.h" | 10 #include "vm/intermediate_language.h" |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 313 |
| 314 LocalScope* enclosing_scope = NULL; | 314 LocalScope* enclosing_scope = NULL; |
| 315 if (function.IsLocalFunction()) { | 315 if (function.IsLocalFunction()) { |
| 316 enclosing_scope = LocalScope::RestoreOuterScope( | 316 enclosing_scope = LocalScope::RestoreOuterScope( |
| 317 ContextScope::Handle(Z, function.context_scope())); | 317 ContextScope::Handle(Z, function.context_scope())); |
| 318 } | 318 } |
| 319 current_function_scope_ = scope_ = new (Z) LocalScope(enclosing_scope, 0, 0); | 319 current_function_scope_ = scope_ = new (Z) LocalScope(enclosing_scope, 0, 0); |
| 320 scope_->set_begin_token_pos(function.token_pos()); | 320 scope_->set_begin_token_pos(function.token_pos()); |
| 321 scope_->set_end_token_pos(function.end_token_pos()); | 321 scope_->set_end_token_pos(function.end_token_pos()); |
| 322 | 322 |
| 323 if (FLAG_reify_generic_functions && function.IsGeneric()) { |
| 324 LocalVariable* type_args_var = MakeVariable( |
| 325 TokenPosition::kNoSource, TokenPosition::kNoSource, |
| 326 Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type()); |
| 327 type_args_var->set_is_forced_stack(); // TODO(regis): Necessary? |
| 328 scope_->AddVariable(type_args_var); |
| 329 ASSERT(parsed_function->function_type_arguments() == NULL); |
| 330 parsed_function->set_function_type_arguments(type_args_var); |
| 331 } |
| 323 LocalVariable* context_var = parsed_function->current_context_var(); | 332 LocalVariable* context_var = parsed_function->current_context_var(); |
| 324 context_var->set_is_forced_stack(); | 333 context_var->set_is_forced_stack(); |
| 325 scope_->AddVariable(context_var); | 334 scope_->AddVariable(context_var); |
| 326 | 335 |
| 327 parsed_function->SetNodeSequence( | 336 parsed_function->SetNodeSequence( |
| 328 new SequenceNode(TokenPosition::kNoSource, scope_)); | 337 new SequenceNode(TokenPosition::kNoSource, scope_)); |
| 329 | 338 |
| 330 switch (function.kind()) { | 339 switch (function.kind()) { |
| 331 case RawFunction::kClosureFunction: | 340 case RawFunction::kClosureFunction: |
| 332 case RawFunction::kRegularFunction: | 341 case RawFunction::kRegularFunction: |
| (...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2542 ArgumentArray arguments = GetArguments(argument_count); | 2551 ArgumentArray arguments = GetArguments(argument_count); |
| 2543 const intptr_t kTypeArgsLen = 0; // Generic instance calls not yet supported. | 2552 const intptr_t kTypeArgsLen = 0; // Generic instance calls not yet supported. |
| 2544 InstanceCallInstr* call = new (Z) InstanceCallInstr( | 2553 InstanceCallInstr* call = new (Z) InstanceCallInstr( |
| 2545 position, name, kind, arguments, kTypeArgsLen, argument_names, | 2554 position, name, kind, arguments, kTypeArgsLen, argument_names, |
| 2546 num_args_checked, ic_data_array_, GetNextDeoptId()); | 2555 num_args_checked, ic_data_array_, GetNextDeoptId()); |
| 2547 Push(call); | 2556 Push(call); |
| 2548 return Fragment(call); | 2557 return Fragment(call); |
| 2549 } | 2558 } |
| 2550 | 2559 |
| 2551 | 2560 |
| 2552 Fragment FlowGraphBuilder::ClosureCall(int argument_count, | 2561 Fragment FlowGraphBuilder::ClosureCall(intptr_t type_args_len, |
| 2562 intptr_t argument_count, |
| 2553 const Array& argument_names) { | 2563 const Array& argument_names) { |
| 2554 Value* function = Pop(); | 2564 Value* function = Pop(); |
| 2555 ArgumentArray arguments = GetArguments(argument_count); | 2565 const intptr_t total_count = argument_count + (type_args_len > 0 ? 1 : 0); |
| 2556 const intptr_t kTypeArgsLen = 0; // Generic closures not yet supported. | 2566 ArgumentArray arguments = GetArguments(total_count); |
| 2557 ClosureCallInstr* call = new (Z) | 2567 ClosureCallInstr* call = new (Z) |
| 2558 ClosureCallInstr(function, arguments, kTypeArgsLen, argument_names, | 2568 ClosureCallInstr(function, arguments, type_args_len, argument_names, |
| 2559 TokenPosition::kNoSource, GetNextDeoptId()); | 2569 TokenPosition::kNoSource, GetNextDeoptId()); |
| 2560 Push(call); | 2570 Push(call); |
| 2561 return Fragment(call); | 2571 return Fragment(call); |
| 2562 } | 2572 } |
| 2563 | 2573 |
| 2564 | 2574 |
| 2565 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { | 2575 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { |
| 2566 Fragment instructions; | 2576 Fragment instructions; |
| 2567 instructions += Drop(); | 2577 instructions += Drop(); |
| 2568 instructions += | 2578 instructions += |
| (...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4209 | 4219 |
| 4210 TargetEntryInstr* normal_entry = BuildTargetEntry(); | 4220 TargetEntryInstr* normal_entry = BuildTargetEntry(); |
| 4211 graph_entry_ = new (Z) | 4221 graph_entry_ = new (Z) |
| 4212 GraphEntryInstr(*parsed_function_, normal_entry, Compiler::kNoOSRDeoptId); | 4222 GraphEntryInstr(*parsed_function_, normal_entry, Compiler::kNoOSRDeoptId); |
| 4213 | 4223 |
| 4214 Fragment body(normal_entry); | 4224 Fragment body(normal_entry); |
| 4215 body += CheckStackOverflowInPrologue(); | 4225 body += CheckStackOverflowInPrologue(); |
| 4216 | 4226 |
| 4217 LocalScope* scope = parsed_function_->node_sequence()->scope(); | 4227 LocalScope* scope = parsed_function_->node_sequence()->scope(); |
| 4218 | 4228 |
| 4229 if (descriptor.TypeArgsLen() > 0) { |
| 4230 LocalVariable* type_args = parsed_function_->function_type_arguments(); |
| 4231 ASSERT(type_args != NULL); |
| 4232 body += LoadLocal(type_args); |
| 4233 body += PushArgument(); |
| 4234 } |
| 4235 |
| 4219 LocalVariable* closure = NULL; | 4236 LocalVariable* closure = NULL; |
| 4220 if (is_closure_call) { | 4237 if (is_closure_call) { |
| 4221 closure = scope->VariableAt(0); | 4238 closure = scope->VariableAt(0); |
| 4222 | 4239 |
| 4223 // The closure itself is the first argument. | 4240 // The closure itself is the first argument. |
| 4224 body += LoadLocal(closure); | 4241 body += LoadLocal(closure); |
| 4225 } else { | 4242 } else { |
| 4226 // Invoke the getter to get the field value. | 4243 // Invoke the getter to get the field value. |
| 4227 body += LoadLocal(scope->VariableAt(0)); | 4244 body += LoadLocal(scope->VariableAt(0)); |
| 4228 body += PushArgument(); | 4245 body += PushArgument(); |
| 4229 body += | 4246 body += |
| 4230 InstanceCall(TokenPosition::kMinSource, getter_name, Token::kGET, 1); | 4247 InstanceCall(TokenPosition::kMinSource, getter_name, Token::kGET, 1); |
| 4231 } | 4248 } |
| 4232 | 4249 |
| 4233 body += PushArgument(); | 4250 body += PushArgument(); |
| 4234 | 4251 |
| 4235 // Push all arguments onto the stack. | 4252 // Push all arguments onto the stack. |
| 4236 intptr_t pos = 1; | 4253 intptr_t pos = 1; |
| 4237 for (; pos < descriptor.Count(); pos++) { | 4254 for (; pos < descriptor.Count(); pos++) { |
| 4238 body += LoadLocal(scope->VariableAt(pos)); | 4255 body += LoadLocal(scope->VariableAt(pos)); |
| 4239 body += PushArgument(); | 4256 body += PushArgument(); |
| 4240 } | 4257 } |
| 4241 | 4258 |
| 4242 if (is_closure_call) { | 4259 if (is_closure_call) { |
| 4243 // Lookup the function in the closure. | 4260 // Lookup the function in the closure. |
| 4244 body += LoadLocal(closure); | 4261 body += LoadLocal(closure); |
| 4245 body += LoadField(Closure::function_offset()); | 4262 body += LoadField(Closure::function_offset()); |
| 4246 | 4263 |
| 4247 body += ClosureCall(descriptor.Count(), argument_names); | 4264 body += ClosureCall(descriptor.TypeArgsLen(), descriptor.Count(), |
| 4265 argument_names); |
| 4248 } else { | 4266 } else { |
| 4267 if (descriptor.TypeArgsLen() > 0) { |
| 4268 UNIMPLEMENTED(); |
| 4269 } |
| 4249 body += InstanceCall(TokenPosition::kMinSource, Symbols::Call(), | 4270 body += InstanceCall(TokenPosition::kMinSource, Symbols::Call(), |
| 4250 Token::kILLEGAL, descriptor.Count(), argument_names); | 4271 Token::kILLEGAL, descriptor.Count(), argument_names); |
| 4251 } | 4272 } |
| 4252 | 4273 |
| 4253 body += Return(TokenPosition::kNoSource); | 4274 body += Return(TokenPosition::kNoSource); |
| 4254 | 4275 |
| 4255 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); | 4276 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); |
| 4256 } | 4277 } |
| 4257 | 4278 |
| 4258 | 4279 |
| (...skipping 2610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6869 thread->clear_sticky_error(); | 6890 thread->clear_sticky_error(); |
| 6870 return error.raw(); | 6891 return error.raw(); |
| 6871 } | 6892 } |
| 6872 } | 6893 } |
| 6873 | 6894 |
| 6874 | 6895 |
| 6875 } // namespace kernel | 6896 } // namespace kernel |
| 6876 } // namespace dart | 6897 } // namespace dart |
| 6877 | 6898 |
| 6878 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6899 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |