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

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

Issue 2517953002: Revert "Merge of source position information from kernel-sdk." (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « runtime/vm/kernel_to_il.h ('k') | runtime/vm/object.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) 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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 8
9 #include "vm/kernel_to_il.h" 9 #include "vm/kernel_to_il.h"
10 10
(...skipping 2269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 return Fragment(new (Z) GotoInstr(destination)).closed(); 2280 return Fragment(new (Z) GotoInstr(destination)).closed();
2281 } 2281 }
2282 2282
2283 2283
2284 Fragment FlowGraphBuilder::IntConstant(int64_t value) { 2284 Fragment FlowGraphBuilder::IntConstant(int64_t value) {
2285 return Fragment( 2285 return Fragment(
2286 Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld)))); 2286 Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld))));
2287 } 2287 }
2288 2288
2289 2289
2290 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, 2290 Fragment FlowGraphBuilder::InstanceCall(const dart::String& name,
2291 const dart::String& name,
2292 Token::Kind kind, 2291 Token::Kind kind,
2293 intptr_t argument_count, 2292 intptr_t argument_count,
2294 intptr_t num_args_checked) { 2293 intptr_t num_args_checked) {
2295 return InstanceCall(position, name, kind, argument_count, Array::null_array(), 2294 return InstanceCall(name, kind, argument_count, Array::null_array(),
2296 num_args_checked); 2295 num_args_checked);
2297 } 2296 }
2298 2297
2299 2298
2300 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, 2299 Fragment FlowGraphBuilder::InstanceCall(const dart::String& name,
2301 const dart::String& name,
2302 Token::Kind kind, 2300 Token::Kind kind,
2303 intptr_t argument_count, 2301 intptr_t argument_count,
2304 const Array& argument_names, 2302 const Array& argument_names,
2305 intptr_t num_args_checked) { 2303 intptr_t num_args_checked) {
2306 ArgumentArray arguments = GetArguments(argument_count); 2304 ArgumentArray arguments = GetArguments(argument_count);
2307 InstanceCallInstr* call = 2305 InstanceCallInstr* call = new (Z)
2308 new (Z) InstanceCallInstr(position, name, kind, arguments, argument_names, 2306 InstanceCallInstr(TokenPosition::kNoSource, name, kind, arguments,
2309 num_args_checked, ic_data_array_); 2307 argument_names, num_args_checked, ic_data_array_);
2310 Push(call); 2308 Push(call);
2311 return Fragment(call); 2309 return Fragment(call);
2312 } 2310 }
2313 2311
2314 2312
2315 Fragment FlowGraphBuilder::ClosureCall(int argument_count, 2313 Fragment FlowGraphBuilder::ClosureCall(int argument_count,
2316 const Array& argument_names) { 2314 const Array& argument_names) {
2317 Value* function = Pop(); 2315 Value* function = Pop();
2318 ArgumentArray arguments = GetArguments(argument_count); 2316 ArgumentArray arguments = GetArguments(argument_count);
2319 ClosureCallInstr* call = new (Z) ClosureCallInstr( 2317 ClosureCallInstr* call = new (Z) ClosureCallInstr(
2320 function, arguments, argument_names, TokenPosition::kNoSource); 2318 function, arguments, argument_names, TokenPosition::kNoSource);
2321 Push(call); 2319 Push(call);
2322 return Fragment(call); 2320 return Fragment(call);
2323 } 2321 }
2324 2322
2325 2323
2326 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { 2324 Fragment FlowGraphBuilder::ThrowException() {
2327 Fragment instructions; 2325 Fragment instructions;
2328 instructions += Drop(); 2326 instructions += Drop();
2329 instructions += Fragment(new (Z) ThrowInstr(position)).closed(); 2327 instructions +=
2328 Fragment(new (Z) ThrowInstr(TokenPosition::kNoSource)).closed();
2330 // Use it's side effect of leaving a constant on the stack (does not change 2329 // Use it's side effect of leaving a constant on the stack (does not change
2331 // the graph). 2330 // the graph).
2332 NullConstant(); 2331 NullConstant();
2333 2332
2334 pending_argument_count_ -= 1; 2333 pending_argument_count_ -= 1;
2335 2334
2336 return instructions; 2335 return instructions;
2337 } 2336 }
2338 2337
2339 2338
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 Fragment FlowGraphBuilder::Return() { 2464 Fragment FlowGraphBuilder::Return() {
2466 Value* value = Pop(); 2465 Value* value = Pop();
2467 ASSERT(stack_ == NULL); 2466 ASSERT(stack_ == NULL);
2468 ReturnInstr* return_instr = 2467 ReturnInstr* return_instr =
2469 new (Z) ReturnInstr(TokenPosition::kNoSource, value); 2468 new (Z) ReturnInstr(TokenPosition::kNoSource, value);
2470 if (exit_collector_ != NULL) exit_collector_->AddExit(return_instr); 2469 if (exit_collector_ != NULL) exit_collector_->AddExit(return_instr);
2471 return Fragment(return_instr).closed(); 2470 return Fragment(return_instr).closed();
2472 } 2471 }
2473 2472
2474 2473
2475 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, 2474 Fragment FlowGraphBuilder::StaticCall(const Function& target,
2476 const Function& target,
2477 intptr_t argument_count) { 2475 intptr_t argument_count) {
2478 return StaticCall(position, target, argument_count, Array::null_array()); 2476 return StaticCall(target, argument_count, Array::null_array());
2479 } 2477 }
2480 2478
2481 2479
2482 static intptr_t GetResultCidOfListFactory(Zone* zone, 2480 static intptr_t GetResultCidOfListFactory(Zone* zone,
2483 const Function& function, 2481 const Function& function,
2484 intptr_t argument_count) { 2482 intptr_t argument_count) {
2485 if (!function.IsFactory()) { 2483 if (!function.IsFactory()) {
2486 return kDynamicCid; 2484 return kDynamicCid;
2487 } 2485 }
2488 2486
2489 const dart::Class& owner = dart::Class::Handle(zone, function.Owner()); 2487 const dart::Class& owner = dart::Class::Handle(zone, function.Owner());
2490 if ((owner.library() != dart::Library::CoreLibrary()) && 2488 if ((owner.library() != dart::Library::CoreLibrary()) &&
2491 (owner.library() != dart::Library::TypedDataLibrary())) { 2489 (owner.library() != dart::Library::TypedDataLibrary())) {
2492 return kDynamicCid; 2490 return kDynamicCid;
2493 } 2491 }
2494 2492
2495 if ((owner.Name() == Symbols::List().raw()) && 2493 if ((owner.Name() == Symbols::List().raw()) &&
2496 (function.name() == Symbols::ListFactory().raw())) { 2494 (function.name() == Symbols::ListFactory().raw())) {
2497 ASSERT(argument_count == 1 || argument_count == 2); 2495 ASSERT(argument_count == 1 || argument_count == 2);
2498 return (argument_count == 1) ? kGrowableObjectArrayCid : kArrayCid; 2496 return (argument_count == 1) ? kGrowableObjectArrayCid : kArrayCid;
2499 } 2497 }
2500 return FactoryRecognizer::ResultCid(function); 2498 return FactoryRecognizer::ResultCid(function);
2501 } 2499 }
2502 2500
2503 2501
2504 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, 2502 Fragment FlowGraphBuilder::StaticCall(const Function& target,
2505 const Function& target,
2506 intptr_t argument_count, 2503 intptr_t argument_count,
2507 const Array& argument_names) { 2504 const Array& argument_names) {
2508 ArgumentArray arguments = GetArguments(argument_count); 2505 ArgumentArray arguments = GetArguments(argument_count);
2509 StaticCallInstr* call = new (Z) StaticCallInstr( 2506 StaticCallInstr* call =
2510 position, target, argument_names, arguments, ic_data_array_); 2507 new (Z) StaticCallInstr(TokenPosition::kNoSource, target, argument_names,
2508 arguments, ic_data_array_);
2511 const intptr_t list_cid = 2509 const intptr_t list_cid =
2512 GetResultCidOfListFactory(Z, target, argument_count); 2510 GetResultCidOfListFactory(Z, target, argument_count);
2513 if (list_cid != kDynamicCid) { 2511 if (list_cid != kDynamicCid) {
2514 call->set_result_cid(list_cid); 2512 call->set_result_cid(list_cid);
2515 call->set_is_known_list_constructor(true); 2513 call->set_is_known_list_constructor(true);
2516 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { 2514 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) {
2517 call->set_result_cid(MethodRecognizer::ResultCid(target)); 2515 call->set_result_cid(MethodRecognizer::ResultCid(target));
2518 } 2516 }
2519 Push(call); 2517 Push(call);
2520 return Fragment(call); 2518 return Fragment(call);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2640 2638
2641 instructions += NullConstant(); 2639 instructions += NullConstant();
2642 instructions += PushArgument(); // line 2640 instructions += PushArgument(); // line
2643 2641
2644 instructions += IntConstant(0); 2642 instructions += IntConstant(0);
2645 instructions += PushArgument(); // column 2643 instructions += PushArgument(); // column
2646 2644
2647 instructions += Constant(H.DartSymbol("Malformed type.")); 2645 instructions += Constant(H.DartSymbol("Malformed type."));
2648 instructions += PushArgument(); // message 2646 instructions += PushArgument(); // message
2649 2647
2650 instructions += StaticCall(TokenPosition::kNoSource, constructor, 5); 2648 instructions += StaticCall(constructor, 5);
2651 instructions += Drop(); 2649 instructions += Drop();
2652 2650
2653 // Throw the exception 2651 // Throw the exception
2654 instructions += PushArgument(); 2652 instructions += PushArgument();
2655 instructions += ThrowException(TokenPosition::kNoSource); 2653 instructions += ThrowException();
2656 2654
2657 return instructions; 2655 return instructions;
2658 } 2656 }
2659 2657
2660 2658
2661 Fragment FlowGraphBuilder::ThrowNoSuchMethodError() { 2659 Fragment FlowGraphBuilder::ThrowNoSuchMethodError() {
2662 const dart::Class& klass = dart::Class::ZoneHandle( 2660 const dart::Class& klass = dart::Class::ZoneHandle(
2663 Z, dart::Library::LookupCoreClass(Symbols::NoSuchMethodError())); 2661 Z, dart::Library::LookupCoreClass(Symbols::NoSuchMethodError()));
2664 ASSERT(!klass.IsNull()); 2662 ASSERT(!klass.IsNull());
2665 const dart::Function& throw_function = dart::Function::ZoneHandle( 2663 const dart::Function& throw_function = dart::Function::ZoneHandle(
(...skipping 14 matching lines...) Expand all
2680 2678
2681 instructions += NullConstant(); 2679 instructions += NullConstant();
2682 instructions += PushArgument(); // arguments 2680 instructions += PushArgument(); // arguments
2683 2681
2684 instructions += NullConstant(); 2682 instructions += NullConstant();
2685 instructions += PushArgument(); // argumentNames 2683 instructions += PushArgument(); // argumentNames
2686 2684
2687 instructions += NullConstant(); 2685 instructions += NullConstant();
2688 instructions += PushArgument(); // existingArgumentNames 2686 instructions += PushArgument(); // existingArgumentNames
2689 2687
2690 instructions += StaticCall(TokenPosition::kNoSource, throw_function, 6); 2688 instructions += StaticCall(throw_function, 6);
2691 // Leave "result" on the stack since callers expect it to be there (even 2689 // Leave "result" on the stack since callers expect it to be there (even
2692 // though the function will result in an exception). 2690 // though the function will result in an exception).
2693 2691
2694 return instructions; 2692 return instructions;
2695 } 2693 }
2696 2694
2697 2695
2698 dart::RawFunction* FlowGraphBuilder::LookupMethodByMember( 2696 dart::RawFunction* FlowGraphBuilder::LookupMethodByMember(
2699 Member* target, 2697 Member* target,
2700 const dart::String& method_name) { 2698 const dart::String& method_name) {
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
3442 for (intptr_t i = 0; i < named_argument_count; i++) { 3440 for (intptr_t i = 0; i < named_argument_count; i++) {
3443 VariableDeclaration* variable = kernel_function->named_parameters()[i]; 3441 VariableDeclaration* variable = kernel_function->named_parameters()[i];
3444 body += LoadLocal(LookupVariable(variable)); 3442 body += LoadLocal(LookupVariable(variable));
3445 body += PushArgument(); 3443 body += PushArgument();
3446 argument_names.SetAt(i, H.DartSymbol(variable->name())); 3444 argument_names.SetAt(i, H.DartSymbol(variable->name()));
3447 } 3445 }
3448 } 3446 }
3449 // Forward them to the target. 3447 // Forward them to the target.
3450 intptr_t argument_count = positional_argument_count + named_argument_count; 3448 intptr_t argument_count = positional_argument_count + named_argument_count;
3451 if (!target.is_static()) ++argument_count; 3449 if (!target.is_static()) ++argument_count;
3452 body += StaticCall(TokenPosition::kNoSource, target, argument_count, 3450 body += StaticCall(target, argument_count, argument_names);
3453 argument_names);
3454 3451
3455 // Return the result. 3452 // Return the result.
3456 body += Return(); 3453 body += Return();
3457 3454
3458 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); 3455 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1);
3459 } 3456 }
3460 3457
3461 3458
3462 FlowGraph* FlowGraphBuilder::BuildGraphOfNoSuchMethodDispatcher( 3459 FlowGraph* FlowGraphBuilder::BuildGraphOfNoSuchMethodDispatcher(
3463 const Function& function) { 3460 const Function& function) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3530 body += Constant(Bool::False()); 3527 body += Constant(Bool::False());
3531 body += PushArgument(); 3528 body += PushArgument();
3532 3529
3533 const dart::Class& mirror_class = dart::Class::Handle( 3530 const dart::Class& mirror_class = dart::Class::Handle(
3534 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); 3531 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror()));
3535 ASSERT(!mirror_class.IsNull()); 3532 ASSERT(!mirror_class.IsNull());
3536 const Function& allocation_function = Function::ZoneHandle( 3533 const Function& allocation_function = Function::ZoneHandle(
3537 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( 3534 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName(
3538 Symbols::AllocateInvocationMirror()))); 3535 Symbols::AllocateInvocationMirror())));
3539 ASSERT(!allocation_function.IsNull()); 3536 ASSERT(!allocation_function.IsNull());
3540 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4); 3537 body += StaticCall(allocation_function, 4);
3541 body += PushArgument(); // For the call to noSuchMethod. 3538 body += PushArgument(); // For the call to noSuchMethod.
3542 3539
3543 ArgumentsDescriptor two_arguments( 3540 ArgumentsDescriptor two_arguments(
3544 Array::Handle(Z, ArgumentsDescriptor::New(2))); 3541 Array::Handle(Z, ArgumentsDescriptor::New(2)));
3545 Function& no_such_method = 3542 Function& no_such_method =
3546 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( 3543 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass(
3547 dart::Class::Handle(Z, function.Owner()), 3544 dart::Class::Handle(Z, function.Owner()),
3548 Symbols::NoSuchMethod(), two_arguments)); 3545 Symbols::NoSuchMethod(), two_arguments));
3549 if (no_such_method.IsNull()) { 3546 if (no_such_method.IsNull()) {
3550 // If noSuchMethod is not found on the receiver class, call 3547 // If noSuchMethod is not found on the receiver class, call
3551 // Object.noSuchMethod. 3548 // Object.noSuchMethod.
3552 no_such_method = Resolver::ResolveDynamicForReceiverClass( 3549 no_such_method = Resolver::ResolveDynamicForReceiverClass(
3553 dart::Class::Handle(Z, I->object_store()->object_class()), 3550 dart::Class::Handle(Z, I->object_store()->object_class()),
3554 Symbols::NoSuchMethod(), two_arguments); 3551 Symbols::NoSuchMethod(), two_arguments);
3555 } 3552 }
3556 body += StaticCall(TokenPosition::kMinSource, no_such_method, 2); 3553 body += StaticCall(no_such_method, 2);
3557 body += Return(); 3554 body += Return();
3558 3555
3559 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); 3556 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1);
3560 } 3557 }
3561 3558
3562 3559
3563 FlowGraph* FlowGraphBuilder::BuildGraphOfInvokeFieldDispatcher( 3560 FlowGraph* FlowGraphBuilder::BuildGraphOfInvokeFieldDispatcher(
3564 const Function& function) { 3561 const Function& function) {
3565 // Find the name of the field we should dispatch to. 3562 // Find the name of the field we should dispatch to.
3566 const dart::Class& owner = dart::Class::Handle(Z, function.Owner()); 3563 const dart::Class& owner = dart::Class::Handle(Z, function.Owner());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3610 LocalVariable* closure = NULL; 3607 LocalVariable* closure = NULL;
3611 if (is_closure_call) { 3608 if (is_closure_call) {
3612 closure = scope->VariableAt(0); 3609 closure = scope->VariableAt(0);
3613 3610
3614 // The closure itself is the first argument. 3611 // The closure itself is the first argument.
3615 body += LoadLocal(closure); 3612 body += LoadLocal(closure);
3616 } else { 3613 } else {
3617 // Invoke the getter to get the field value. 3614 // Invoke the getter to get the field value.
3618 body += LoadLocal(scope->VariableAt(0)); 3615 body += LoadLocal(scope->VariableAt(0));
3619 body += PushArgument(); 3616 body += PushArgument();
3620 body += 3617 body += InstanceCall(getter_name, Token::kGET, 1);
3621 InstanceCall(TokenPosition::kMinSource, getter_name, Token::kGET, 1);
3622 } 3618 }
3623 3619
3624 body += PushArgument(); 3620 body += PushArgument();
3625 3621
3626 // Push all arguments onto the stack. 3622 // Push all arguments onto the stack.
3627 intptr_t pos = 1; 3623 intptr_t pos = 1;
3628 for (; pos < descriptor.Count(); pos++) { 3624 for (; pos < descriptor.Count(); pos++) {
3629 body += LoadLocal(scope->VariableAt(pos)); 3625 body += LoadLocal(scope->VariableAt(pos));
3630 body += PushArgument(); 3626 body += PushArgument();
3631 } 3627 }
3632 3628
3633 if (is_closure_call) { 3629 if (is_closure_call) {
3634 // Lookup the function in the closure. 3630 // Lookup the function in the closure.
3635 body += LoadLocal(closure); 3631 body += LoadLocal(closure);
3636 body += LoadField(Closure::function_offset()); 3632 body += LoadField(Closure::function_offset());
3637 3633
3638 body += ClosureCall(descriptor.Count(), argument_names); 3634 body += ClosureCall(descriptor.Count(), argument_names);
3639 } else { 3635 } else {
3640 body += InstanceCall(TokenPosition::kMinSource, Symbols::Call(), 3636 body += InstanceCall(Symbols::Call(), Token::kILLEGAL, descriptor.Count(),
3641 Token::kILLEGAL, descriptor.Count(), argument_names); 3637 argument_names);
3642 } 3638 }
3643 3639
3644 body += Return(); 3640 body += Return();
3645 3641
3646 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); 3642 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1);
3647 } 3643 }
3648 3644
3649 3645
3650 void FlowGraphBuilder::SetupDefaultParameterValues(FunctionNode* function) { 3646 void FlowGraphBuilder::SetupDefaultParameterValues(FunctionNode* function) {
3651 intptr_t num_optional_parameters = 3647 intptr_t num_optional_parameters =
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3744 instructions += LoadLocal(scopes_->this_variable); 3740 instructions += LoadLocal(scopes_->this_variable);
3745 instructions += PushArgument(); 3741 instructions += PushArgument();
3746 3742
3747 ASSERT(init->arguments()->types().length() == 0); 3743 ASSERT(init->arguments()->types().length() == 0);
3748 Array& argument_names = Array::ZoneHandle(Z); 3744 Array& argument_names = Array::ZoneHandle(Z);
3749 instructions += TranslateArguments(init->arguments(), &argument_names); 3745 instructions += TranslateArguments(init->arguments(), &argument_names);
3750 3746
3751 const Function& target = Function::ZoneHandle( 3747 const Function& target = Function::ZoneHandle(
3752 Z, H.LookupConstructorByKernelConstructor(init->target())); 3748 Z, H.LookupConstructorByKernelConstructor(init->target()));
3753 intptr_t argument_count = init->arguments()->count() + 1; 3749 intptr_t argument_count = init->arguments()->count() + 1;
3754 instructions += StaticCall(TokenPosition::kNoSource, target, 3750 instructions += StaticCall(target, argument_count, argument_names);
3755 argument_count, argument_names);
3756 instructions += Drop(); 3751 instructions += Drop();
3757 } else if (initializer->IsRedirectingInitializer()) { 3752 } else if (initializer->IsRedirectingInitializer()) {
3758 RedirectingInitializer* init = RedirectingInitializer::Cast(initializer); 3753 RedirectingInitializer* init = RedirectingInitializer::Cast(initializer);
3759 3754
3760 instructions += LoadLocal(scopes_->this_variable); 3755 instructions += LoadLocal(scopes_->this_variable);
3761 instructions += PushArgument(); 3756 instructions += PushArgument();
3762 3757
3763 ASSERT(init->arguments()->types().length() == 0); 3758 ASSERT(init->arguments()->types().length() == 0);
3764 Array& argument_names = Array::ZoneHandle(Z); 3759 Array& argument_names = Array::ZoneHandle(Z);
3765 instructions += TranslateArguments(init->arguments(), &argument_names); 3760 instructions += TranslateArguments(init->arguments(), &argument_names);
3766 3761
3767 const Function& target = Function::ZoneHandle( 3762 const Function& target = Function::ZoneHandle(
3768 Z, H.LookupConstructorByKernelConstructor(init->target())); 3763 Z, H.LookupConstructorByKernelConstructor(init->target()));
3769 intptr_t argument_count = init->arguments()->count() + 1; 3764 intptr_t argument_count = init->arguments()->count() + 1;
3770 instructions += StaticCall(TokenPosition::kNoSource, target, 3765 instructions += StaticCall(target, argument_count, argument_names);
3771 argument_count, argument_names);
3772 instructions += Drop(); 3766 instructions += Drop();
3773 } else if (initializer->IsLocalInitializer()) { 3767 } else if (initializer->IsLocalInitializer()) {
3774 // The other initializers following this one might read the variable. This 3768 // The other initializers following this one might read the variable. This
3775 // is used e.g. for evaluating the arguments to a super call first, run 3769 // is used e.g. for evaluating the arguments to a super call first, run
3776 // normal field initializers next and then make the actual super call: 3770 // normal field initializers next and then make the actual super call:
3777 // 3771 //
3778 // The frontend converts 3772 // The frontend converts
3779 // 3773 //
3780 // class A { 3774 // class A {
3781 // var x; 3775 // var x;
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
4188 fragment_ = Constant(constant_evaluator_.EvaluateExpression(node)); 4182 fragment_ = Constant(constant_evaluator_.EvaluateExpression(node));
4189 } else { 4183 } else {
4190 const dart::Class& owner = dart::Class::Handle(Z, field.Owner()); 4184 const dart::Class& owner = dart::Class::Handle(Z, field.Owner());
4191 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); 4185 const dart::String& getter_name = H.DartGetterName(kernel_field->name());
4192 const Function& getter = 4186 const Function& getter =
4193 Function::ZoneHandle(Z, owner.LookupStaticFunction(getter_name)); 4187 Function::ZoneHandle(Z, owner.LookupStaticFunction(getter_name));
4194 if (getter.IsNull() || !field.has_initializer()) { 4188 if (getter.IsNull() || !field.has_initializer()) {
4195 Fragment instructions = Constant(field); 4189 Fragment instructions = Constant(field);
4196 fragment_ = instructions + LoadStaticField(); 4190 fragment_ = instructions + LoadStaticField();
4197 } else { 4191 } else {
4198 fragment_ = StaticCall(node->position(), getter, 0); 4192 fragment_ = StaticCall(getter, 0);
4199 } 4193 }
4200 } 4194 }
4201 } else { 4195 } else {
4202 Procedure* procedure = Procedure::Cast(target); 4196 Procedure* procedure = Procedure::Cast(target);
4203 const Function& target = Function::ZoneHandle( 4197 const Function& target = Function::ZoneHandle(
4204 Z, H.LookupStaticMethodByKernelProcedure(procedure)); 4198 Z, H.LookupStaticMethodByKernelProcedure(procedure));
4205 4199
4206 if (procedure->kind() == Procedure::kGetter) { 4200 if (procedure->kind() == Procedure::kGetter) {
4207 fragment_ = StaticCall(node->position(), target, 0); 4201 fragment_ = StaticCall(target, 0);
4208 } else if (procedure->kind() == Procedure::kMethod) { 4202 } else if (procedure->kind() == Procedure::kMethod) {
4209 ASSERT(procedure->IsStatic()); 4203 ASSERT(procedure->IsStatic());
4210 Function& closure_function = 4204 Function& closure_function =
4211 Function::ZoneHandle(Z, target.ImplicitClosureFunction()); 4205 Function::ZoneHandle(Z, target.ImplicitClosureFunction());
4212 closure_function.set_kernel_function(target.kernel_function()); 4206 closure_function.set_kernel_function(target.kernel_function());
4213 const Instance& closure = 4207 const Instance& closure =
4214 Instance::ZoneHandle(Z, closure_function.ImplicitStaticClosure()); 4208 Instance::ZoneHandle(Z, closure_function.ImplicitStaticClosure());
4215 fragment_ = Constant(closure); 4209 fragment_ = Constant(closure);
4216 } else { 4210 } else {
4217 UNIMPLEMENTED(); 4211 UNIMPLEMENTED();
(...skipping 20 matching lines...) Expand all
4238 LocalVariable* variable = MakeTemporary(); 4232 LocalVariable* variable = MakeTemporary();
4239 4233
4240 // Prepare argument. 4234 // Prepare argument.
4241 instructions += LoadLocal(variable); 4235 instructions += LoadLocal(variable);
4242 instructions += PushArgument(); 4236 instructions += PushArgument();
4243 4237
4244 // Invoke the setter function. 4238 // Invoke the setter function.
4245 Procedure* procedure = Procedure::Cast(target); 4239 Procedure* procedure = Procedure::Cast(target);
4246 const Function& target = Function::ZoneHandle( 4240 const Function& target = Function::ZoneHandle(
4247 Z, H.LookupStaticMethodByKernelProcedure(procedure)); 4241 Z, H.LookupStaticMethodByKernelProcedure(procedure));
4248 instructions += StaticCall(node->position(), target, 1); 4242 instructions += StaticCall(target, 1);
4249 4243
4250 // Drop the unused result & leave the stored value on the stack. 4244 // Drop the unused result & leave the stored value on the stack.
4251 fragment_ = instructions + Drop(); 4245 fragment_ = instructions + Drop();
4252 } 4246 }
4253 } 4247 }
4254 4248
4255 4249
4256 void FlowGraphBuilder::VisitPropertyGet(PropertyGet* node) { 4250 void FlowGraphBuilder::VisitPropertyGet(PropertyGet* node) {
4257 Fragment instructions = TranslateExpression(node->receiver()); 4251 Fragment instructions = TranslateExpression(node->receiver());
4258 instructions += PushArgument(); 4252 instructions += PushArgument();
4259 const dart::String& getter_name = H.DartGetterName(node->name()); 4253 const dart::String& getter_name = H.DartGetterName(node->name());
4260 fragment_ = instructions + 4254 fragment_ = instructions + InstanceCall(getter_name, Token::kGET, 1);
4261 InstanceCall(node->position(), getter_name, Token::kGET, 1);
4262 } 4255 }
4263 4256
4264 4257
4265 void FlowGraphBuilder::VisitPropertySet(PropertySet* node) { 4258 void FlowGraphBuilder::VisitPropertySet(PropertySet* node) {
4266 Fragment instructions(NullConstant()); 4259 Fragment instructions(NullConstant());
4267 LocalVariable* variable = MakeTemporary(); 4260 LocalVariable* variable = MakeTemporary();
4268 instructions += TranslateExpression(node->receiver()); 4261 instructions += TranslateExpression(node->receiver());
4269 instructions += PushArgument(); 4262 instructions += PushArgument();
4270 instructions += TranslateExpression(node->value()); 4263 instructions += TranslateExpression(node->value());
4271 instructions += StoreLocal(variable); 4264 instructions += StoreLocal(variable);
4272 instructions += PushArgument(); 4265 instructions += PushArgument();
4273 4266
4274 const dart::String& setter_name = H.DartSetterName(node->name()); 4267 const dart::String& setter_name = H.DartSetterName(node->name());
4275 instructions += InstanceCall(node->position(), setter_name, Token::kSET, 2); 4268 instructions += InstanceCall(setter_name, Token::kSET, 2);
4276 fragment_ = instructions + Drop(); 4269 fragment_ = instructions + Drop();
4277 } 4270 }
4278 4271
4279 4272
4280 void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) { 4273 void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) {
4281 Function& target = Function::ZoneHandle(Z); 4274 Function& target = Function::ZoneHandle(Z);
4282 if (node->target()->IsProcedure()) { 4275 if (node->target()->IsProcedure()) {
4283 Procedure* kernel_procedure = Procedure::Cast(node->target()); 4276 Procedure* kernel_procedure = Procedure::Cast(node->target());
4284 Name* kernel_name = kernel_procedure->name(); 4277 Name* kernel_name = kernel_procedure->name();
4285 if (kernel_procedure->kind() == Procedure::kGetter) { 4278 if (kernel_procedure->kind() == Procedure::kGetter) {
4286 target = 4279 target =
4287 LookupMethodByMember(kernel_procedure, H.DartGetterName(kernel_name)); 4280 LookupMethodByMember(kernel_procedure, H.DartGetterName(kernel_name));
4288 } else { 4281 } else {
4289 target = 4282 target =
4290 LookupMethodByMember(kernel_procedure, H.DartMethodName(kernel_name)); 4283 LookupMethodByMember(kernel_procedure, H.DartMethodName(kernel_name));
4291 target = target.ImplicitClosureFunction(); 4284 target = target.ImplicitClosureFunction();
4292 ASSERT(!target.IsNull()); 4285 ASSERT(!target.IsNull());
4293 fragment_ = BuildImplicitClosureCreation(target); 4286 fragment_ = BuildImplicitClosureCreation(target);
4294 return; 4287 return;
4295 } 4288 }
4296 } else { 4289 } else {
4297 ASSERT(node->target()->IsField()); 4290 ASSERT(node->target()->IsField());
4298 const dart::String& getter_name = H.DartGetterName(node->target()->name()); 4291 const dart::String& getter_name = H.DartGetterName(node->target()->name());
4299 target = LookupMethodByMember(node->target(), getter_name); 4292 target = LookupMethodByMember(node->target(), getter_name);
4300 ASSERT(target.IsGetterFunction() || target.IsImplicitGetterFunction()); 4293 ASSERT(target.IsGetterFunction() || target.IsImplicitGetterFunction());
4301 } 4294 }
4302 4295
4303 Fragment instructions = TranslateExpression(node->receiver()); 4296 Fragment instructions = TranslateExpression(node->receiver());
4304 instructions += PushArgument(); 4297 instructions += PushArgument();
4305 fragment_ = instructions + StaticCall(node->position(), target, 1); 4298 fragment_ = instructions + StaticCall(target, 1);
4306 } 4299 }
4307 4300
4308 4301
4309 void FlowGraphBuilder::VisitDirectPropertySet(DirectPropertySet* node) { 4302 void FlowGraphBuilder::VisitDirectPropertySet(DirectPropertySet* node) {
4310 const dart::String& method_name = H.DartSetterName(node->target()->name()); 4303 const dart::String& method_name = H.DartSetterName(node->target()->name());
4311 const Function& target = Function::ZoneHandle( 4304 const Function& target = Function::ZoneHandle(
4312 Z, LookupMethodByMember(node->target(), method_name)); 4305 Z, LookupMethodByMember(node->target(), method_name));
4313 ASSERT(target.IsSetterFunction() || target.IsImplicitSetterFunction()); 4306 ASSERT(target.IsSetterFunction() || target.IsImplicitSetterFunction());
4314 4307
4315 Fragment instructions(NullConstant()); 4308 Fragment instructions(NullConstant());
4316 LocalVariable* value = MakeTemporary(); 4309 LocalVariable* value = MakeTemporary();
4317 instructions += TranslateExpression(node->receiver()); 4310 instructions += TranslateExpression(node->receiver());
4318 instructions += PushArgument(); 4311 instructions += PushArgument();
4319 instructions += TranslateExpression(node->value()); 4312 instructions += TranslateExpression(node->value());
4320 instructions += StoreLocal(value); 4313 instructions += StoreLocal(value);
4321 instructions += PushArgument(); 4314 instructions += PushArgument();
4322 instructions += StaticCall(node->position(), target, 2); 4315 instructions += StaticCall(target, 2);
4323 4316
4324 fragment_ = instructions + Drop(); 4317 fragment_ = instructions + Drop();
4325 } 4318 }
4326 4319
4327 4320
4328 void FlowGraphBuilder::VisitStaticInvocation(StaticInvocation* node) { 4321 void FlowGraphBuilder::VisitStaticInvocation(StaticInvocation* node) {
4329 const Function& target = Function::ZoneHandle( 4322 const Function& target = Function::ZoneHandle(
4330 Z, H.LookupStaticMethodByKernelProcedure(node->procedure())); 4323 Z, H.LookupStaticMethodByKernelProcedure(node->procedure()));
4331 const dart::Class& klass = dart::Class::ZoneHandle(Z, target.Owner()); 4324 const dart::Class& klass = dart::Class::ZoneHandle(Z, target.Owner());
4332 intptr_t argument_count = node->arguments()->count(); 4325 intptr_t argument_count = node->arguments()->count();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
4397 (target.name() == Symbols::Identical().raw())) { 4390 (target.name() == Symbols::Identical().raw())) {
4398 ASSERT(argument_count == 2); 4391 ASSERT(argument_count == 2);
4399 4392
4400 List<Expression>& positional = node->arguments()->positional(); 4393 List<Expression>& positional = node->arguments()->positional();
4401 for (intptr_t i = 0; i < positional.length(); ++i) { 4394 for (intptr_t i = 0; i < positional.length(); ++i) {
4402 instructions += TranslateExpression(positional[i]); 4395 instructions += TranslateExpression(positional[i]);
4403 } 4396 }
4404 instructions += StrictCompare(Token::kEQ_STRICT, /*number_check=*/true); 4397 instructions += StrictCompare(Token::kEQ_STRICT, /*number_check=*/true);
4405 } else { 4398 } else {
4406 instructions += TranslateArguments(node->arguments(), NULL); 4399 instructions += TranslateArguments(node->arguments(), NULL);
4407 instructions += 4400 instructions += StaticCall(target, argument_count, argument_names);
4408 StaticCall(node->position(), target, argument_count, argument_names);
4409 4401
4410 if (target.IsGenerativeConstructor()) { 4402 if (target.IsGenerativeConstructor()) {
4411 // Drop the result of the constructor call and leave [instance_variable] 4403 // Drop the result of the constructor call and leave [instance_variable]
4412 // on top-of-stack. 4404 // on top-of-stack.
4413 instructions += Drop(); 4405 instructions += Drop();
4414 } 4406 }
4415 } 4407 }
4416 4408
4417 fragment_ = instructions; 4409 fragment_ = instructions;
4418 } 4410 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4455 instructions += TranslateArguments(node->arguments(), &argument_names); 4447 instructions += TranslateArguments(node->arguments(), &argument_names);
4456 4448
4457 intptr_t num_args_checked = 1; 4449 intptr_t num_args_checked = 1;
4458 // If we have a special operation (e.g. +/-/==) we mark both arguments as 4450 // If we have a special operation (e.g. +/-/==) we mark both arguments as
4459 // to be checked. 4451 // to be checked.
4460 if (token_kind != Token::kILLEGAL) { 4452 if (token_kind != Token::kILLEGAL) {
4461 ASSERT(argument_count <= 2); 4453 ASSERT(argument_count <= 2);
4462 num_args_checked = argument_count; 4454 num_args_checked = argument_count;
4463 } 4455 }
4464 4456
4465 fragment_ = instructions + InstanceCall(node->position(), name, token_kind, 4457 fragment_ = instructions + InstanceCall(name, token_kind, argument_count,
4466 argument_count, argument_names, 4458 argument_names, num_args_checked);
4467 num_args_checked);
4468 } 4459 }
4469 4460
4470 4461
4471 void FlowGraphBuilder::VisitDirectMethodInvocation( 4462 void FlowGraphBuilder::VisitDirectMethodInvocation(
4472 DirectMethodInvocation* node) { 4463 DirectMethodInvocation* node) {
4473 const dart::String& method_name = H.DartMethodName(node->target()->name()); 4464 const dart::String& method_name = H.DartMethodName(node->target()->name());
4474 const Function& target = Function::ZoneHandle( 4465 const Function& target = Function::ZoneHandle(
4475 Z, LookupMethodByMember(node->target(), method_name)); 4466 Z, LookupMethodByMember(node->target(), method_name));
4476 4467
4477 intptr_t argument_count = node->arguments()->count() + 1; 4468 intptr_t argument_count = node->arguments()->count() + 1;
4478 Array& argument_names = Array::ZoneHandle(Z); 4469 Array& argument_names = Array::ZoneHandle(Z);
4479 4470
4480 ASSERT(node->arguments()->types().length() == 0); 4471 ASSERT(node->arguments()->types().length() == 0);
4481 Fragment instructions = TranslateExpression(node->receiver()); 4472 Fragment instructions = TranslateExpression(node->receiver());
4482 instructions += PushArgument(); 4473 instructions += PushArgument();
4483 instructions += TranslateArguments(node->arguments(), &argument_names); 4474 instructions += TranslateArguments(node->arguments(), &argument_names);
4484 fragment_ = instructions + StaticCall(node->position(), target, 4475 fragment_ = instructions + StaticCall(target, argument_count, argument_names);
4485 argument_count, argument_names);
4486 } 4476 }
4487 4477
4488 4478
4489 void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) { 4479 void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) {
4490 if (node->is_const()) { 4480 if (node->is_const()) {
4491 fragment_ = 4481 fragment_ =
4492 Constant(constant_evaluator_.EvaluateConstructorInvocation(node)); 4482 Constant(constant_evaluator_.EvaluateConstructorInvocation(node));
4493 return; 4483 return;
4494 } 4484 }
4495 4485
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4535 4525
4536 instructions += LoadLocal(variable); 4526 instructions += LoadLocal(variable);
4537 instructions += PushArgument(); 4527 instructions += PushArgument();
4538 4528
4539 Array& argument_names = Array::ZoneHandle(Z); 4529 Array& argument_names = Array::ZoneHandle(Z);
4540 instructions += TranslateArguments(node->arguments(), &argument_names); 4530 instructions += TranslateArguments(node->arguments(), &argument_names);
4541 4531
4542 const Function& target = Function::ZoneHandle( 4532 const Function& target = Function::ZoneHandle(
4543 Z, H.LookupConstructorByKernelConstructor(klass, node->target())); 4533 Z, H.LookupConstructorByKernelConstructor(klass, node->target()));
4544 intptr_t argument_count = node->arguments()->count() + 1; 4534 intptr_t argument_count = node->arguments()->count() + 1;
4545 instructions += 4535 instructions += StaticCall(target, argument_count, argument_names);
4546 StaticCall(node->position(), target, argument_count, argument_names);
4547 fragment_ = instructions + Drop(); 4536 fragment_ = instructions + Drop();
4548 } 4537 }
4549 4538
4550 4539
4551 void FlowGraphBuilder::VisitIsExpression(IsExpression* node) { 4540 void FlowGraphBuilder::VisitIsExpression(IsExpression* node) {
4552 Fragment instructions = TranslateExpression(node->operand()); 4541 Fragment instructions = TranslateExpression(node->operand());
4553 4542
4554 // The VM does not like an instanceOf call with a dynamic type. We need to 4543 // The VM does not like an instanceOf call with a dynamic type. We need to
4555 // special case this situation. 4544 // special case this situation.
4556 const Type& object_type = Type::Handle(Z, Type::ObjectType()); 4545 const Type& object_type = Type::Handle(Z, Type::ObjectType());
(...skipping 22 matching lines...) Expand all
4579 } 4568 }
4580 instructions += PushArgument(); // Type arguments. 4569 instructions += PushArgument(); // Type arguments.
4581 4570
4582 instructions += Constant(type); 4571 instructions += Constant(type);
4583 instructions += PushArgument(); // Type. 4572 instructions += PushArgument(); // Type.
4584 4573
4585 instructions += Constant(Bool::False()); 4574 instructions += Constant(Bool::False());
4586 instructions += PushArgument(); // Negate?. 4575 instructions += PushArgument(); // Negate?.
4587 4576
4588 instructions += 4577 instructions +=
4589 InstanceCall(TokenPosition::kNoSource, 4578 InstanceCall(dart::Library::PrivateCoreLibName(Symbols::_instanceOf()),
4590 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()),
4591 Token::kIS, 4); 4579 Token::kIS, 4);
4592 } 4580 }
4593 4581
4594 fragment_ = instructions; 4582 fragment_ = instructions;
4595 } 4583 }
4596 4584
4597 4585
4598 void FlowGraphBuilder::VisitAsExpression(AsExpression* node) { 4586 void FlowGraphBuilder::VisitAsExpression(AsExpression* node) {
4599 Fragment instructions = TranslateExpression(node->operand()); 4587 Fragment instructions = TranslateExpression(node->operand());
4600 4588
(...skipping 19 matching lines...) Expand all
4620 instructions += LoadInstantiatorTypeArguments(); 4608 instructions += LoadInstantiatorTypeArguments();
4621 } else { 4609 } else {
4622 instructions += NullConstant(); 4610 instructions += NullConstant();
4623 } 4611 }
4624 instructions += PushArgument(); // Type arguments. 4612 instructions += PushArgument(); // Type arguments.
4625 4613
4626 instructions += Constant(type); 4614 instructions += Constant(type);
4627 instructions += PushArgument(); // Type. 4615 instructions += PushArgument(); // Type.
4628 4616
4629 instructions += InstanceCall( 4617 instructions += InstanceCall(
4630 TokenPosition::kNoSource,
4631 dart::Library::PrivateCoreLibName(Symbols::_as()), Token::kAS, 3); 4618 dart::Library::PrivateCoreLibName(Symbols::_as()), Token::kAS, 3);
4632 } 4619 }
4633 4620
4634 fragment_ = instructions; 4621 fragment_ = instructions;
4635 } 4622 }
4636 4623
4637 4624
4638 void FlowGraphBuilder::VisitConditionalExpression(ConditionalExpression* node) { 4625 void FlowGraphBuilder::VisitConditionalExpression(ConditionalExpression* node) {
4639 bool negate; 4626 bool negate;
4640 Fragment instructions = TranslateCondition(node->condition(), &negate); 4627 Fragment instructions = TranslateCondition(node->condition(), &negate);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
4767 instructions += Drop(); 4754 instructions += Drop();
4768 } 4755 }
4769 } 4756 }
4770 instructions += PushArgument(); // The array. 4757 instructions += PushArgument(); // The array.
4771 4758
4772 const dart::Class& factory_class = 4759 const dart::Class& factory_class =
4773 dart::Class::Handle(Z, dart::Library::LookupCoreClass(Symbols::List())); 4760 dart::Class::Handle(Z, dart::Library::LookupCoreClass(Symbols::List()));
4774 const Function& factory_method = Function::ZoneHandle( 4761 const Function& factory_method = Function::ZoneHandle(
4775 Z, factory_class.LookupFactory( 4762 Z, factory_class.LookupFactory(
4776 dart::Library::PrivateCoreLibName(Symbols::ListLiteralFactory()))); 4763 dart::Library::PrivateCoreLibName(Symbols::ListLiteralFactory())));
4777 fragment_ = instructions + StaticCall(node->position(), factory_method, 2); 4764 fragment_ = instructions + StaticCall(factory_method, 2);
4778 } 4765 }
4779 4766
4780 4767
4781 void FlowGraphBuilder::VisitMapLiteral(MapLiteral* node) { 4768 void FlowGraphBuilder::VisitMapLiteral(MapLiteral* node) {
4782 if (node->is_const()) { 4769 if (node->is_const()) {
4783 fragment_ = Constant(constant_evaluator_.EvaluateMapLiteral(node)); 4770 fragment_ = Constant(constant_evaluator_.EvaluateMapLiteral(node));
4784 return; 4771 return;
4785 } 4772 }
4786 4773
4787 const dart::Class& map_class = 4774 const dart::Class& map_class =
(...skipping 30 matching lines...) Expand all
4818 4805
4819 instructions += LoadLocal(array); 4806 instructions += LoadLocal(array);
4820 instructions += IntConstant(2 * i + 1); 4807 instructions += IntConstant(2 * i + 1);
4821 instructions += TranslateExpression(entries[i]->value()); 4808 instructions += TranslateExpression(entries[i]->value());
4822 instructions += StoreIndexed(kArrayCid); 4809 instructions += StoreIndexed(kArrayCid);
4823 instructions += Drop(); 4810 instructions += Drop();
4824 } 4811 }
4825 } 4812 }
4826 instructions += PushArgument(); // The array. 4813 instructions += PushArgument(); // The array.
4827 4814
4828 fragment_ = instructions + StaticCall(node->position(), factory_method, 2); 4815 fragment_ = instructions + StaticCall(factory_method, 2);
4829 } 4816 }
4830 4817
4831 4818
4832 void FlowGraphBuilder::VisitFunctionExpression(FunctionExpression* node) { 4819 void FlowGraphBuilder::VisitFunctionExpression(FunctionExpression* node) {
4833 fragment_ = TranslateFunctionNode(node->function(), node); 4820 fragment_ = TranslateFunctionNode(node->function(), node);
4834 } 4821 }
4835 4822
4836 4823
4837 void FlowGraphBuilder::VisitLet(Let* node) { 4824 void FlowGraphBuilder::VisitLet(Let* node) {
4838 Fragment instructions = TranslateStatement(node->variable()); 4825 Fragment instructions = TranslateStatement(node->variable());
4839 instructions += TranslateExpression(node->body()); 4826 instructions += TranslateExpression(node->body());
4840 fragment_ = instructions; 4827 fragment_ = instructions;
4841 } 4828 }
4842 4829
4843 4830
4844 void FlowGraphBuilder::VisitThrow(Throw* node) { 4831 void FlowGraphBuilder::VisitThrow(Throw* node) {
4845 Fragment instructions; 4832 Fragment instructions;
4846 4833
4847 instructions += TranslateExpression(node->expression()); 4834 instructions += TranslateExpression(node->expression());
4848 instructions += PushArgument(); 4835 instructions += PushArgument();
4849 instructions += ThrowException(node->position()); 4836 instructions += ThrowException();
4850 ASSERT(instructions.is_closed()); 4837 ASSERT(instructions.is_closed());
4851 4838
4852 fragment_ = instructions; 4839 fragment_ = instructions;
4853 } 4840 }
4854 4841
4855 4842
4856 void FlowGraphBuilder::VisitRethrow(Rethrow* node) { 4843 void FlowGraphBuilder::VisitRethrow(Rethrow* node) {
4857 Fragment instructions; 4844 Fragment instructions;
4858 4845
4859 instructions += LoadLocal(catch_block_->exception_var()); 4846 instructions += LoadLocal(catch_block_->exception_var());
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
5123 fragment_ = loop; 5110 fragment_ = loop;
5124 } 5111 }
5125 5112
5126 5113
5127 void FlowGraphBuilder::VisitForInStatement(ForInStatement* node) { 5114 void FlowGraphBuilder::VisitForInStatement(ForInStatement* node) {
5128 Fragment instructions = TranslateExpression(node->iterable()); 5115 Fragment instructions = TranslateExpression(node->iterable());
5129 instructions += PushArgument(); 5116 instructions += PushArgument();
5130 5117
5131 const dart::String& iterator_getter = dart::String::ZoneHandle( 5118 const dart::String& iterator_getter = dart::String::ZoneHandle(
5132 Z, dart::Field::GetterSymbol(Symbols::Iterator())); 5119 Z, dart::Field::GetterSymbol(Symbols::Iterator()));
5133 instructions += 5120 instructions += InstanceCall(iterator_getter, Token::kGET, 1);
5134 InstanceCall(TokenPosition::kNoSource, iterator_getter, Token::kGET, 1);
5135 LocalVariable* iterator = scopes_->iterator_variables[for_in_depth_]; 5121 LocalVariable* iterator = scopes_->iterator_variables[for_in_depth_];
5136 instructions += StoreLocal(iterator); 5122 instructions += StoreLocal(iterator);
5137 instructions += Drop(); 5123 instructions += Drop();
5138 5124
5139 ++for_in_depth_; 5125 ++for_in_depth_;
5140 ++loop_depth_; 5126 ++loop_depth_;
5141 Fragment condition = LoadLocal(iterator); 5127 Fragment condition = LoadLocal(iterator);
5142 condition += PushArgument(); 5128 condition += PushArgument();
5143 condition += InstanceCall(TokenPosition::kNoSource, Symbols::MoveNext(), 5129 condition += InstanceCall(Symbols::MoveNext(), Token::kILLEGAL, 1);
5144 Token::kILLEGAL, 1);
5145 TargetEntryInstr* body_entry; 5130 TargetEntryInstr* body_entry;
5146 TargetEntryInstr* loop_exit; 5131 TargetEntryInstr* loop_exit;
5147 condition += BranchIfTrue(&body_entry, &loop_exit); 5132 condition += BranchIfTrue(&body_entry, &loop_exit);
5148 5133
5149 Fragment body(body_entry); 5134 Fragment body(body_entry);
5150 body += EnterScope(node); 5135 body += EnterScope(node);
5151 body += LoadLocal(iterator); 5136 body += LoadLocal(iterator);
5152 body += PushArgument(); 5137 body += PushArgument();
5153 const dart::String& current_getter = dart::String::ZoneHandle( 5138 const dart::String& current_getter = dart::String::ZoneHandle(
5154 Z, dart::Field::GetterSymbol(Symbols::Current())); 5139 Z, dart::Field::GetterSymbol(Symbols::Current()));
5155 body += 5140 body += InstanceCall(current_getter, Token::kGET, 1);
5156 InstanceCall(TokenPosition::kNoSource, current_getter, Token::kGET, 1);
5157 body += StoreLocal(LookupVariable(node->variable())); 5141 body += StoreLocal(LookupVariable(node->variable()));
5158 body += Drop(); 5142 body += Drop();
5159 body += TranslateStatement(node->body()); 5143 body += TranslateStatement(node->body());
5160 body += ExitScope(node); 5144 body += ExitScope(node);
5161 5145
5162 if (body.is_open()) { 5146 if (body.is_open()) {
5163 JoinEntryInstr* join = BuildJoinEntry(); 5147 JoinEntryInstr* join = BuildJoinEntry();
5164 instructions += Goto(join); 5148 instructions += Goto(join);
5165 body += Goto(join); 5149 body += Goto(join);
5166 5150
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
5267 // Call _AssertionError._create constructor. 5251 // Call _AssertionError._create constructor.
5268 body_fragment += LoadLocal(instance); 5252 body_fragment += LoadLocal(instance);
5269 body_fragment += PushArgument(); // this 5253 body_fragment += PushArgument(); // this
5270 5254
5271 body_fragment += Constant(url); 5255 body_fragment += Constant(url);
5272 body_fragment += PushArgument(); // url 5256 body_fragment += PushArgument(); // url
5273 5257
5274 body_fragment += NullConstant(); 5258 body_fragment += NullConstant();
5275 body_fragment += PushArgument(); // line 5259 body_fragment += PushArgument(); // line
5276 5260
5277 body_fragment += StaticCall(TokenPosition::kNoSource, constructor, 3); 5261 body_fragment += StaticCall(constructor, 3);
5278 body_fragment += Drop(); 5262 body_fragment += Drop();
5279 5263
5280 // Throw the exception 5264 // Throw the exception
5281 body_fragment += PushArgument(); 5265 body_fragment += PushArgument();
5282 body_fragment += ThrowException(TokenPosition::kNoSource); 5266 body_fragment += ThrowException();
5283 body_fragment += Drop(); 5267 body_fragment += Drop();
5284 } 5268 }
5285 5269
5286 // If there is an implicit fall-through we have one [SwitchCase] and 5270 // If there is an implicit fall-through we have one [SwitchCase] and
5287 // multiple expressions, e.g. 5271 // multiple expressions, e.g.
5288 // 5272 //
5289 // switch(expr) { 5273 // switch(expr) {
5290 // case a: 5274 // case a:
5291 // case b: 5275 // case b:
5292 // <stmt-body> 5276 // <stmt-body>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
5336 5320
5337 for (intptr_t j = 0; j < switch_case->expressions().length(); j++) { 5321 for (intptr_t j = 0; j < switch_case->expressions().length(); j++) {
5338 TargetEntryInstr* then; 5322 TargetEntryInstr* then;
5339 TargetEntryInstr* otherwise; 5323 TargetEntryInstr* otherwise;
5340 5324
5341 current_instructions += Constant(constant_evaluator_.EvaluateExpression( 5325 current_instructions += Constant(constant_evaluator_.EvaluateExpression(
5342 switch_case->expressions()[j])); 5326 switch_case->expressions()[j]));
5343 current_instructions += PushArgument(); 5327 current_instructions += PushArgument();
5344 current_instructions += LoadLocal(scopes_->switch_variable); 5328 current_instructions += LoadLocal(scopes_->switch_variable);
5345 current_instructions += PushArgument(); 5329 current_instructions += PushArgument();
5346 current_instructions += InstanceCall( 5330 current_instructions +=
5347 TokenPosition::kNoSource, Symbols::EqualOperator(), Token::kEQ, 5331 InstanceCall(Symbols::EqualOperator(), Token::kEQ,
5348 /*argument_count=*/2, 5332 /*argument_count=*/2,
5349 /*num_args_checked=*/2); 5333 /*num_args_checked=*/2);
5350 current_instructions += BranchIfTrue(&then, &otherwise); 5334 current_instructions += BranchIfTrue(&then, &otherwise);
5351 5335
5352 Fragment then_fragment(then); 5336 Fragment then_fragment(then);
5353 5337
5354 if (body_join != NULL) { 5338 if (body_join != NULL) {
5355 // There are several branches to the body, so we will make a goto to 5339 // There are several branches to the body, so we will make a goto to
5356 // the join block (the real body has already been prepended with a 5340 // the join block (the real body has already been prepended with a
5357 // join instruction). 5341 // join instruction).
5358 then_fragment += Goto(body_join); 5342 then_fragment += Goto(body_join);
5359 } else { 5343 } else {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
5459 5443
5460 otherwise_fragment += Constant(url); 5444 otherwise_fragment += Constant(url);
5461 otherwise_fragment += PushArgument(); // url 5445 otherwise_fragment += PushArgument(); // url
5462 5446
5463 otherwise_fragment += IntConstant(0); 5447 otherwise_fragment += IntConstant(0);
5464 otherwise_fragment += PushArgument(); // line 5448 otherwise_fragment += PushArgument(); // line
5465 5449
5466 otherwise_fragment += IntConstant(0); 5450 otherwise_fragment += IntConstant(0);
5467 otherwise_fragment += PushArgument(); // column 5451 otherwise_fragment += PushArgument(); // column
5468 5452
5469 otherwise_fragment += StaticCall(TokenPosition::kNoSource, constructor, 5); 5453 otherwise_fragment += StaticCall(constructor, 5);
5470 otherwise_fragment += Drop(); 5454 otherwise_fragment += Drop();
5471 5455
5472 // Throw _AssertionError exception. 5456 // Throw _AssertionError exception.
5473 otherwise_fragment += PushArgument(); 5457 otherwise_fragment += PushArgument();
5474 otherwise_fragment += ThrowException(TokenPosition::kNoSource); 5458 otherwise_fragment += ThrowException();
5475 otherwise_fragment += Drop(); 5459 otherwise_fragment += Drop();
5476 5460
5477 fragment_ = Fragment(instructions.entry, then); 5461 fragment_ = Fragment(instructions.entry, then);
5478 } 5462 }
5479 5463
5480 5464
5481 void FlowGraphBuilder::VisitTryFinally(TryFinally* node) { 5465 void FlowGraphBuilder::VisitTryFinally(TryFinally* node) {
5482 InlineBailout("kernel::FlowgraphBuilder::VisitTryFinally"); 5466 InlineBailout("kernel::FlowgraphBuilder::VisitTryFinally");
5483 5467
5484 // There are 5 different cases where we need to execute the finally block: 5468 // There are 5 different cases where we need to execute the finally block:
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
5619 } else { 5603 } else {
5620 catch_body += LoadLocal(CurrentException()); 5604 catch_body += LoadLocal(CurrentException());
5621 catch_body += PushArgument(); // exception 5605 catch_body += PushArgument(); // exception
5622 catch_body += NullConstant(); 5606 catch_body += NullConstant();
5623 catch_body += PushArgument(); // type arguments 5607 catch_body += PushArgument(); // type arguments
5624 catch_body += Constant(*type_guard); 5608 catch_body += Constant(*type_guard);
5625 catch_body += PushArgument(); // guard type 5609 catch_body += PushArgument(); // guard type
5626 catch_body += Constant(Object::bool_false()); 5610 catch_body += Constant(Object::bool_false());
5627 catch_body += PushArgument(); // negate 5611 catch_body += PushArgument(); // negate
5628 catch_body += InstanceCall( 5612 catch_body += InstanceCall(
5629 TokenPosition::kNoSource,
5630 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), 5613 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()),
5631 Token::kIS, 4); 5614 Token::kIS, 4);
5632 5615
5633 TargetEntryInstr* catch_entry; 5616 TargetEntryInstr* catch_entry;
5634 TargetEntryInstr* next_catch_entry; 5617 TargetEntryInstr* next_catch_entry;
5635 catch_body += BranchIfTrue(&catch_entry, &next_catch_entry); 5618 catch_body += BranchIfTrue(&catch_entry, &next_catch_entry);
5636 5619
5637 Fragment(catch_entry) + catch_handler_body; 5620 Fragment(catch_entry) + catch_handler_body;
5638 catch_body = Fragment(next_catch_entry); 5621 catch_body = Fragment(next_catch_entry);
5639 } 5622 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
5737 Fragment FlowGraphBuilder::TranslateFunctionNode(FunctionNode* node, 5720 Fragment FlowGraphBuilder::TranslateFunctionNode(FunctionNode* node,
5738 TreeNode* parent) { 5721 TreeNode* parent) {
5739 // The VM has a per-isolate table of functions indexed by the enclosing 5722 // The VM has a per-isolate table of functions indexed by the enclosing
5740 // function and token position. We don't have token positions, so we've 5723 // function and token position. We don't have token positions, so we've
5741 // simply numbered the immediately-nested functions with respect to the 5724 // simply numbered the immediately-nested functions with respect to the
5742 // parent. 5725 // parent.
5743 Function& function = Function::ZoneHandle(Z); 5726 Function& function = Function::ZoneHandle(Z);
5744 for (intptr_t i = 0; i < scopes_->function_scopes.length(); ++i) { 5727 for (intptr_t i = 0; i < scopes_->function_scopes.length(); ++i) {
5745 if (scopes_->function_scopes[i].function != node) continue; 5728 if (scopes_->function_scopes[i].function != node) continue;
5746 5729
5747 // NOTE: This is not TokenPosition in the general sense!
5748 function = I->LookupClosureFunction(parsed_function_->function(), 5730 function = I->LookupClosureFunction(parsed_function_->function(),
5749 TokenPosition(i)); 5731 TokenPosition(i));
5750 if (function.IsNull()) { 5732 if (function.IsNull()) {
5751 const dart::String* name; 5733 const dart::String* name;
5752 if (parent->IsFunctionExpression()) { 5734 if (parent->IsFunctionExpression()) {
5753 name = &Symbols::AnonymousClosure(); 5735 name = &Symbols::AnonymousClosure();
5754 } else { 5736 } else {
5755 ASSERT(parent->IsFunctionDeclaration()); 5737 ASSERT(parent->IsFunctionDeclaration());
5756 name = &H.DartSymbol( 5738 name = &H.DartSymbol(
5757 FunctionDeclaration::Cast(parent)->variable()->name()); 5739 FunctionDeclaration::Cast(parent)->variable()->name());
5758 } 5740 }
5759 // NOTE: This is not TokenPosition in the general sense!
5760 function = Function::NewClosureFunction( 5741 function = Function::NewClosureFunction(
5761 *name, parsed_function_->function(), TokenPosition(i)); 5742 *name, parsed_function_->function(), TokenPosition(i));
5762 function.set_is_debuggable(false); 5743 function.set_is_debuggable(false);
5763 LocalScope* scope = scopes_->function_scopes[i].scope; 5744 LocalScope* scope = scopes_->function_scopes[i].scope;
5764 const ContextScope& context_scope = 5745 const ContextScope& context_scope =
5765 ContextScope::Handle(Z, scope->PreserveOuterScope(context_depth_)); 5746 ContextScope::Handle(Z, scope->PreserveOuterScope(context_depth_));
5766 function.set_context_scope(context_scope); 5747 function.set_context_scope(context_scope);
5767 function.set_kernel_function(node); 5748 function.set_kernel_function(node);
5768 KernelReader::SetupFunctionParameters(H, T, dart::Class::Handle(Z), 5749 KernelReader::SetupFunctionParameters(H, T, dart::Class::Handle(Z),
5769 function, node, 5750 function, node,
(...skipping 27 matching lines...) Expand all
5797 instructions += LoadLocal(parsed_function_->current_context_var()); 5778 instructions += LoadLocal(parsed_function_->current_context_var());
5798 instructions += StoreInstanceField(Closure::context_offset()); 5779 instructions += StoreInstanceField(Closure::context_offset());
5799 5780
5800 return instructions; 5781 return instructions;
5801 } 5782 }
5802 5783
5803 5784
5804 } // namespace kernel 5785 } // namespace kernel
5805 } // namespace dart 5786 } // namespace dart
5806 #endif // !defined(DART_PRECOMPILED_RUNTIME) 5787 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_to_il.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698