| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 num_copied_params_(parsed_function->num_copied_params()), | 51 num_copied_params_(parsed_function->num_copied_params()), |
| 52 // All parameters are copied if any parameter is. | 52 // All parameters are copied if any parameter is. |
| 53 num_non_copied_params_((num_copied_params_ == 0) | 53 num_non_copied_params_((num_copied_params_ == 0) |
| 54 ? parsed_function->function().num_fixed_parameters() | 54 ? parsed_function->function().num_fixed_parameters() |
| 55 : 0), | 55 : 0), |
| 56 num_stack_locals_(parsed_function->num_stack_locals()), | 56 num_stack_locals_(parsed_function->num_stack_locals()), |
| 57 exit_collector_(exit_collector), | 57 exit_collector_(exit_collector), |
| 58 last_used_block_id_(0), // 0 is used for the graph entry. | 58 last_used_block_id_(0), // 0 is used for the graph entry. |
| 59 context_level_(0), | 59 context_level_(0), |
| 60 try_index_(CatchClauseNode::kInvalidTryIndex), | 60 try_index_(CatchClauseNode::kInvalidTryIndex), |
| 61 catch_try_index_(CatchClauseNode::kInvalidTryIndex), |
| 61 loop_depth_(0), | 62 loop_depth_(0), |
| 62 graph_entry_(NULL), | 63 graph_entry_(NULL), |
| 63 args_pushed_(0), | 64 args_pushed_(0), |
| 64 osr_id_(osr_id) { } | 65 osr_id_(osr_id) { } |
| 65 | 66 |
| 66 | 67 |
| 67 void FlowGraphBuilder::AddCatchEntry(CatchBlockEntryInstr* entry) { | 68 void FlowGraphBuilder::AddCatchEntry(CatchBlockEntryInstr* entry) { |
| 68 graph_entry_->AddCatchEntry(entry); | 69 graph_entry_->AddCatchEntry(entry); |
| 69 } | 70 } |
| 70 | 71 |
| (...skipping 3388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3459 | 3460 |
| 3460 EffectGraphVisitor for_catch(owner(), temp_index()); | 3461 EffectGraphVisitor for_catch(owner(), temp_index()); |
| 3461 node->VisitChildren(&for_catch); | 3462 node->VisitChildren(&for_catch); |
| 3462 Append(for_catch); | 3463 Append(for_catch); |
| 3463 } | 3464 } |
| 3464 | 3465 |
| 3465 | 3466 |
| 3466 void EffectGraphVisitor::VisitTryCatchNode(TryCatchNode* node) { | 3467 void EffectGraphVisitor::VisitTryCatchNode(TryCatchNode* node) { |
| 3467 InlineBailout("EffectGraphVisitor::VisitTryCatchNode (exception)"); | 3468 InlineBailout("EffectGraphVisitor::VisitTryCatchNode (exception)"); |
| 3468 intptr_t original_handler_index = owner()->try_index(); | 3469 intptr_t original_handler_index = owner()->try_index(); |
| 3469 intptr_t try_handler_index = node->try_index(); | 3470 const intptr_t try_handler_index = node->try_index(); |
| 3470 ASSERT(try_handler_index != original_handler_index); | 3471 ASSERT(try_handler_index != original_handler_index); |
| 3471 owner()->set_try_index(try_handler_index); | 3472 owner()->set_try_index(try_handler_index); |
| 3472 | 3473 |
| 3473 // Preserve CTX into local variable '%saved_context'. | 3474 // Preserve CTX into local variable '%saved_context'. |
| 3474 BuildSaveContext(node->context_var()); | 3475 BuildSaveContext(node->context_var()); |
| 3475 | 3476 |
| 3476 EffectGraphVisitor for_try(owner(), temp_index()); | 3477 EffectGraphVisitor for_try(owner(), temp_index()); |
| 3477 node->try_block()->Visit(&for_try); | 3478 node->try_block()->Visit(&for_try); |
| 3478 | 3479 |
| 3479 if (for_try.is_open()) { | 3480 if (for_try.is_open()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3495 | 3496 |
| 3496 CatchClauseNode* catch_block = node->catch_block(); | 3497 CatchClauseNode* catch_block = node->catch_block(); |
| 3497 SequenceNode* finally_block = node->finally_block(); | 3498 SequenceNode* finally_block = node->finally_block(); |
| 3498 | 3499 |
| 3499 // If there is a finally block, it is the handler for code in the catch | 3500 // If there is a finally block, it is the handler for code in the catch |
| 3500 // block. | 3501 // block. |
| 3501 const intptr_t catch_handler_index = (finally_block == NULL) | 3502 const intptr_t catch_handler_index = (finally_block == NULL) |
| 3502 ? original_handler_index | 3503 ? original_handler_index |
| 3503 : catch_block->catch_handler_index(); | 3504 : catch_block->catch_handler_index(); |
| 3504 | 3505 |
| 3506 const intptr_t prev_catch_try_index = owner()->catch_try_index(); |
| 3507 |
| 3505 owner()->set_try_index(catch_handler_index); | 3508 owner()->set_try_index(catch_handler_index); |
| 3509 owner()->set_catch_try_index(try_handler_index); |
| 3506 EffectGraphVisitor for_catch(owner(), temp_index()); | 3510 EffectGraphVisitor for_catch(owner(), temp_index()); |
| 3507 catch_block->Visit(&for_catch); | 3511 catch_block->Visit(&for_catch); |
| 3512 owner()->set_catch_try_index(prev_catch_try_index); |
| 3508 | 3513 |
| 3509 // NOTE: The implicit variables ':saved_context', ':exception_var' | 3514 // NOTE: The implicit variables ':saved_context', ':exception_var' |
| 3510 // and ':stacktrace_var' can never be captured variables. | 3515 // and ':stacktrace_var' can never be captured variables. |
| 3511 ASSERT(!catch_block->exception_var().is_captured()); | 3516 ASSERT(!catch_block->exception_var().is_captured()); |
| 3512 ASSERT(!catch_block->stacktrace_var().is_captured()); | 3517 ASSERT(!catch_block->stacktrace_var().is_captured()); |
| 3513 | 3518 |
| 3514 CatchBlockEntryInstr* catch_entry = | 3519 CatchBlockEntryInstr* catch_entry = |
| 3515 new CatchBlockEntryInstr(owner()->AllocateBlockId(), | 3520 new CatchBlockEntryInstr(owner()->AllocateBlockId(), |
| 3516 catch_handler_index, | 3521 catch_handler_index, |
| 3517 catch_block->handler_types(), | 3522 catch_block->handler_types(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3539 | 3544 |
| 3540 finally_block->Visit(&for_finally); | 3545 finally_block->Visit(&for_finally); |
| 3541 if (for_finally.is_open()) { | 3546 if (for_finally.is_open()) { |
| 3542 // Rethrow the exception. Manually build the graph for rethrow. | 3547 // Rethrow the exception. Manually build the graph for rethrow. |
| 3543 Value* exception = for_finally.Bind( | 3548 Value* exception = for_finally.Bind( |
| 3544 for_finally.BuildLoadLocal(catch_block->exception_var())); | 3549 for_finally.BuildLoadLocal(catch_block->exception_var())); |
| 3545 for_finally.PushArgument(exception); | 3550 for_finally.PushArgument(exception); |
| 3546 Value* stacktrace = for_finally.Bind( | 3551 Value* stacktrace = for_finally.Bind( |
| 3547 for_finally.BuildLoadLocal(catch_block->stacktrace_var())); | 3552 for_finally.BuildLoadLocal(catch_block->stacktrace_var())); |
| 3548 for_finally.PushArgument(stacktrace); | 3553 for_finally.PushArgument(stacktrace); |
| 3549 for_finally.AddInstruction(new ReThrowInstr(catch_block->token_pos())); | 3554 for_finally.AddInstruction( |
| 3555 new ReThrowInstr(catch_block->token_pos(), catch_handler_index)); |
| 3550 for_finally.CloseFragment(); | 3556 for_finally.CloseFragment(); |
| 3551 } | 3557 } |
| 3552 ASSERT(!for_finally.is_open()); | 3558 ASSERT(!for_finally.is_open()); |
| 3553 | 3559 |
| 3554 const Array& types = Array::ZoneHandle(Array::New(1, Heap::kOld)); | 3560 const Array& types = Array::ZoneHandle(Array::New(1, Heap::kOld)); |
| 3555 types.SetAt(0, Type::Handle(Type::DynamicType())); | 3561 types.SetAt(0, Type::Handle(Type::DynamicType())); |
| 3556 CatchBlockEntryInstr* finally_entry = | 3562 CatchBlockEntryInstr* finally_entry = |
| 3557 new CatchBlockEntryInstr(owner()->AllocateBlockId(), | 3563 new CatchBlockEntryInstr(owner()->AllocateBlockId(), |
| 3558 original_handler_index, | 3564 original_handler_index, |
| 3559 types, | 3565 types, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3685 Append(for_exception); | 3691 Append(for_exception); |
| 3686 PushArgument(for_exception.value()); | 3692 PushArgument(for_exception.value()); |
| 3687 Instruction* instr = NULL; | 3693 Instruction* instr = NULL; |
| 3688 if (node->stacktrace() == NULL) { | 3694 if (node->stacktrace() == NULL) { |
| 3689 instr = new ThrowInstr(node->token_pos()); | 3695 instr = new ThrowInstr(node->token_pos()); |
| 3690 } else { | 3696 } else { |
| 3691 ValueGraphVisitor for_stack_trace(owner(), temp_index()); | 3697 ValueGraphVisitor for_stack_trace(owner(), temp_index()); |
| 3692 node->stacktrace()->Visit(&for_stack_trace); | 3698 node->stacktrace()->Visit(&for_stack_trace); |
| 3693 Append(for_stack_trace); | 3699 Append(for_stack_trace); |
| 3694 PushArgument(for_stack_trace.value()); | 3700 PushArgument(for_stack_trace.value()); |
| 3695 instr = new ReThrowInstr(node->token_pos()); | 3701 instr = new ReThrowInstr(node->token_pos(), owner()->catch_try_index()); |
| 3696 } | 3702 } |
| 3697 AddInstruction(instr); | 3703 AddInstruction(instr); |
| 3698 } | 3704 } |
| 3699 | 3705 |
| 3700 | 3706 |
| 3701 void EffectGraphVisitor::VisitThrowNode(ThrowNode* node) { | 3707 void EffectGraphVisitor::VisitThrowNode(ThrowNode* node) { |
| 3702 BuildThrowNode(node); | 3708 BuildThrowNode(node); |
| 3703 CloseFragment(); | 3709 CloseFragment(); |
| 3704 } | 3710 } |
| 3705 | 3711 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3802 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 3808 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 3803 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3809 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 3804 OS::SNPrint(chars, len, kFormat, function_name, reason); | 3810 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 3805 const Error& error = Error::Handle( | 3811 const Error& error = Error::Handle( |
| 3806 LanguageError::New(String::Handle(String::New(chars)))); | 3812 LanguageError::New(String::Handle(String::New(chars)))); |
| 3807 Isolate::Current()->long_jump_base()->Jump(1, error); | 3813 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 3808 } | 3814 } |
| 3809 | 3815 |
| 3810 | 3816 |
| 3811 } // namespace dart | 3817 } // namespace dart |
| OLD | NEW |