Chromium Code Reviews| 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 <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 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 | 727 |
| 728 | 728 |
| 729 class BreakableBlock { | 729 class BreakableBlock { |
| 730 public: | 730 public: |
| 731 BreakableBlock(FlowGraphBuilder* builder, LabeledStatement* statement) | 731 BreakableBlock(FlowGraphBuilder* builder, LabeledStatement* statement) |
| 732 : builder_(builder), | 732 : builder_(builder), |
| 733 labeled_statement_(statement), | 733 labeled_statement_(statement), |
| 734 outer_(builder->breakable_block_), | 734 outer_(builder->breakable_block_), |
| 735 destination_(NULL), | 735 destination_(NULL), |
| 736 outer_finally_(builder->try_finally_block_), | 736 outer_finally_(builder->try_finally_block_), |
| 737 context_depth_(builder->context_depth_) { | 737 context_depth_(builder->context_depth_), |
| 738 try_index_(builder->CurrentTryIndex()) { | |
| 738 builder_->breakable_block_ = this; | 739 builder_->breakable_block_ = this; |
| 739 } | 740 } |
| 740 ~BreakableBlock() { builder_->breakable_block_ = outer_; } | 741 ~BreakableBlock() { builder_->breakable_block_ = outer_; } |
| 741 | 742 |
| 742 bool HadJumper() { return destination_ != NULL; } | 743 bool HadJumper() { return destination_ != NULL; } |
| 743 | 744 |
| 744 JoinEntryInstr* destination() { return destination_; } | 745 JoinEntryInstr* destination() { return destination_; } |
| 745 | 746 |
| 746 JoinEntryInstr* BreakDestination(LabeledStatement* label, | 747 JoinEntryInstr* BreakDestination(LabeledStatement* label, |
| 747 TryFinallyBlock** outer_finally, | 748 TryFinallyBlock** outer_finally, |
| 748 intptr_t* context_depth) { | 749 intptr_t* context_depth) { |
| 749 BreakableBlock* block = builder_->breakable_block_; | 750 BreakableBlock* block = builder_->breakable_block_; |
| 750 while (block->labeled_statement_ != label) { | 751 while (block->labeled_statement_ != label) { |
| 751 block = block->outer_; | 752 block = block->outer_; |
| 752 } | 753 } |
| 753 ASSERT(block != NULL); | 754 ASSERT(block != NULL); |
| 754 *outer_finally = block->outer_finally_; | 755 *outer_finally = block->outer_finally_; |
| 755 *context_depth = block->context_depth_; | 756 *context_depth = block->context_depth_; |
| 756 return block->EnsureDestination(); | 757 return block->EnsureDestination(); |
| 757 } | 758 } |
| 758 | 759 |
| 759 private: | 760 private: |
| 760 JoinEntryInstr* EnsureDestination() { | 761 JoinEntryInstr* EnsureDestination() { |
| 761 if (destination_ == NULL) { | 762 if (destination_ == NULL) { |
| 762 destination_ = builder_->BuildJoinEntry(); | 763 destination_ = builder_->BuildJoinEntry(try_index_); |
| 763 } | 764 } |
| 764 return destination_; | 765 return destination_; |
| 765 } | 766 } |
| 766 | 767 |
| 767 FlowGraphBuilder* builder_; | 768 FlowGraphBuilder* builder_; |
| 768 LabeledStatement* labeled_statement_; | 769 LabeledStatement* labeled_statement_; |
| 769 BreakableBlock* outer_; | 770 BreakableBlock* outer_; |
| 770 JoinEntryInstr* destination_; | 771 JoinEntryInstr* destination_; |
| 771 TryFinallyBlock* outer_finally_; | 772 TryFinallyBlock* outer_finally_; |
| 772 intptr_t context_depth_; | 773 intptr_t context_depth_; |
| 774 intptr_t try_index_; | |
|
Vyacheslav Egorov (Google)
2017/01/17 22:24:08
const?
| |
| 773 }; | 775 }; |
| 774 | 776 |
| 775 | 777 |
| 776 class SwitchBlock { | 778 class SwitchBlock { |
| 777 public: | 779 public: |
| 778 SwitchBlock(FlowGraphBuilder* builder, SwitchStatement* switch_stmt) | 780 SwitchBlock(FlowGraphBuilder* builder, SwitchStatement* switch_stmt) |
| 779 : builder_(builder), | 781 : builder_(builder), |
| 780 outer_(builder->switch_block_), | 782 outer_(builder->switch_block_), |
| 781 outer_finally_(builder->try_finally_block_), | 783 outer_finally_(builder->try_finally_block_), |
| 782 switch_statement_(switch_stmt), | 784 switch_statement_(switch_stmt), |
| 783 context_depth_(builder->context_depth_) { | 785 context_depth_(builder->context_depth_), |
| 786 try_index_(builder->CurrentTryIndex()) { | |
| 784 builder_->switch_block_ = this; | 787 builder_->switch_block_ = this; |
| 785 } | 788 } |
| 786 ~SwitchBlock() { builder_->switch_block_ = outer_; } | 789 ~SwitchBlock() { builder_->switch_block_ = outer_; } |
| 787 | 790 |
| 788 bool HadJumper(SwitchCase* switch_case) { | 791 bool HadJumper(SwitchCase* switch_case) { |
| 789 return destinations_.Lookup(switch_case) != NULL; | 792 return destinations_.Lookup(switch_case) != NULL; |
| 790 } | 793 } |
| 791 | 794 |
| 792 JoinEntryInstr* Destination(SwitchCase* label, | 795 JoinEntryInstr* Destination(SwitchCase* label, |
| 793 TryFinallyBlock** outer_finally = NULL, | 796 TryFinallyBlock** outer_finally = NULL, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 809 // Ensure there's [JoinEntryInstr] for that [SwitchCase]. | 812 // Ensure there's [JoinEntryInstr] for that [SwitchCase]. |
| 810 return block->EnsureDestination(label); | 813 return block->EnsureDestination(label); |
| 811 } | 814 } |
| 812 | 815 |
| 813 private: | 816 private: |
| 814 typedef std::set<SwitchCase*> DestinationSwitches; | 817 typedef std::set<SwitchCase*> DestinationSwitches; |
| 815 | 818 |
| 816 JoinEntryInstr* EnsureDestination(SwitchCase* switch_case) { | 819 JoinEntryInstr* EnsureDestination(SwitchCase* switch_case) { |
| 817 JoinEntryInstr* cached_inst = destinations_.Lookup(switch_case); | 820 JoinEntryInstr* cached_inst = destinations_.Lookup(switch_case); |
| 818 if (cached_inst == NULL) { | 821 if (cached_inst == NULL) { |
| 819 JoinEntryInstr* inst = builder_->BuildJoinEntry(); | 822 JoinEntryInstr* inst = builder_->BuildJoinEntry(try_index_); |
| 820 destinations_.Insert(switch_case, inst); | 823 destinations_.Insert(switch_case, inst); |
| 821 return inst; | 824 return inst; |
| 822 } | 825 } |
| 823 return cached_inst; | 826 return cached_inst; |
| 824 } | 827 } |
| 825 | 828 |
| 826 void EnsureSwitchCaseMapping() { | 829 void EnsureSwitchCaseMapping() { |
| 827 if (destination_switches_.begin() == destination_switches_.end()) { | 830 if (destination_switches_.begin() == destination_switches_.end()) { |
| 828 List<SwitchCase>& cases = switch_statement_->cases(); | 831 List<SwitchCase>& cases = switch_statement_->cases(); |
| 829 for (intptr_t i = 0; i < cases.length(); i++) { | 832 for (intptr_t i = 0; i < cases.length(); i++) { |
| 830 destination_switches_.insert(cases[i]); | 833 destination_switches_.insert(cases[i]); |
| 831 } | 834 } |
| 832 } | 835 } |
| 833 } | 836 } |
| 834 | 837 |
| 835 bool Contains(SwitchCase* sc) { | 838 bool Contains(SwitchCase* sc) { |
| 836 return destination_switches_.find(sc) != destination_switches_.end(); | 839 return destination_switches_.find(sc) != destination_switches_.end(); |
| 837 } | 840 } |
| 838 | 841 |
| 839 FlowGraphBuilder* builder_; | 842 FlowGraphBuilder* builder_; |
| 840 SwitchBlock* outer_; | 843 SwitchBlock* outer_; |
| 841 | 844 |
| 842 Map<SwitchCase, JoinEntryInstr*> destinations_; | 845 Map<SwitchCase, JoinEntryInstr*> destinations_; |
| 843 DestinationSwitches destination_switches_; | 846 DestinationSwitches destination_switches_; |
| 844 | 847 |
| 845 TryFinallyBlock* outer_finally_; | 848 TryFinallyBlock* outer_finally_; |
| 846 SwitchStatement* switch_statement_; | 849 SwitchStatement* switch_statement_; |
| 847 intptr_t context_depth_; | 850 intptr_t context_depth_; |
| 851 intptr_t try_index_; | |
|
Vyacheslav Egorov (Google)
2017/01/17 22:24:08
const?
| |
| 848 }; | 852 }; |
| 849 | 853 |
| 850 | 854 |
| 851 class TryFinallyBlock { | 855 class TryFinallyBlock { |
| 852 public: | 856 public: |
| 853 TryFinallyBlock(FlowGraphBuilder* builder, Statement* finalizer) | 857 TryFinallyBlock(FlowGraphBuilder* builder, Statement* finalizer) |
| 854 : builder_(builder), | 858 : builder_(builder), |
| 855 outer_(builder->try_finally_block_), | 859 outer_(builder->try_finally_block_), |
| 856 finalizer_(finalizer), | 860 finalizer_(finalizer), |
| 857 context_depth_(builder->context_depth_), | 861 context_depth_(builder->context_depth_), |
| (...skipping 2866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3724 parsed_function_->set_default_parameter_values(default_values); | 3728 parsed_function_->set_default_parameter_values(default_values); |
| 3725 } | 3729 } |
| 3726 } | 3730 } |
| 3727 | 3731 |
| 3728 | 3732 |
| 3729 TargetEntryInstr* FlowGraphBuilder::BuildTargetEntry() { | 3733 TargetEntryInstr* FlowGraphBuilder::BuildTargetEntry() { |
| 3730 return new (Z) TargetEntryInstr(AllocateBlockId(), CurrentTryIndex()); | 3734 return new (Z) TargetEntryInstr(AllocateBlockId(), CurrentTryIndex()); |
| 3731 } | 3735 } |
| 3732 | 3736 |
| 3733 | 3737 |
| 3738 JoinEntryInstr* FlowGraphBuilder::BuildJoinEntry(intptr_t try_index) { | |
| 3739 return new (Z) JoinEntryInstr(AllocateBlockId(), try_index); | |
| 3740 } | |
| 3741 | |
| 3742 | |
| 3734 JoinEntryInstr* FlowGraphBuilder::BuildJoinEntry() { | 3743 JoinEntryInstr* FlowGraphBuilder::BuildJoinEntry() { |
| 3735 return new (Z) JoinEntryInstr(AllocateBlockId(), CurrentTryIndex()); | 3744 return new (Z) JoinEntryInstr(AllocateBlockId(), CurrentTryIndex()); |
| 3736 } | 3745 } |
| 3737 | 3746 |
| 3738 | 3747 |
| 3739 Fragment FlowGraphBuilder::TranslateInitializers( | 3748 Fragment FlowGraphBuilder::TranslateInitializers( |
| 3740 Class* kernel_klass, | 3749 Class* kernel_klass, |
| 3741 List<Initializer>* initializers) { | 3750 List<Initializer>* initializers) { |
| 3742 Fragment instructions; | 3751 Fragment instructions; |
| 3743 | 3752 |
| (...skipping 2234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5978 thread->clear_sticky_error(); | 5987 thread->clear_sticky_error(); |
| 5979 return error.raw(); | 5988 return error.raw(); |
| 5980 } | 5989 } |
| 5981 } | 5990 } |
| 5982 | 5991 |
| 5983 | 5992 |
| 5984 } // namespace kernel | 5993 } // namespace kernel |
| 5985 } // namespace dart | 5994 } // namespace dart |
| 5986 | 5995 |
| 5987 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 5996 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |