1 // Copyright 2013 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "control-builders.h" 6 7 namespace v8 { 8 namespace internal { 9 namespace compiler { 10 11 If(Node * condition)12void IfBuilder::If(Node* condition) { 13 builder_->NewBranch(condition); 14 else_environment_ = environment()->CopyForConditional(); 15 } 16 17 Then()18void IfBuilder::Then() { builder_->NewIfTrue(); } 19 20 Else()21void IfBuilder::Else() { 22 builder_->NewMerge(); 23 then_environment_ = environment(); 24 set_environment(else_environment_); 25 builder_->NewIfFalse(); 26 } 27 28 End()29void IfBuilder::End() { 30 then_environment_->Merge(environment()); 31 set_environment(then_environment_); 32 } 33 34 BeginLoop()35void LoopBuilder::BeginLoop() { 36 builder_->NewLoop(); 37 loop_environment_ = environment()->CopyForLoop(); 38 continue_environment_ = environment()->CopyAsUnreachable(); 39 break_environment_ = environment()->CopyAsUnreachable(); 40 } 41 42 Continue()43void LoopBuilder::Continue() { 44 continue_environment_->Merge(environment()); 45 environment()->MarkAsUnreachable(); 46 } 47 48 Break()49void LoopBuilder::Break() { 50 break_environment_->Merge(environment()); 51 environment()->MarkAsUnreachable(); 52 } 53 54 EndBody()55void LoopBuilder::EndBody() { 56 continue_environment_->Merge(environment()); 57 set_environment(continue_environment_); 58 } 59 60 EndLoop()61void LoopBuilder::EndLoop() { 62 loop_environment_->Merge(environment()); 63 set_environment(break_environment_); 64 } 65 66 BreakUnless(Node * condition)67void LoopBuilder::BreakUnless(Node* condition) { 68 IfBuilder control_if(builder_); 69 control_if.If(condition); 70 control_if.Then(); 71 control_if.Else(); 72 Break(); 73 control_if.End(); 74 } 75 76 BeginSwitch()77void SwitchBuilder::BeginSwitch() { 78 body_environment_ = environment()->CopyAsUnreachable(); 79 label_environment_ = environment()->CopyAsUnreachable(); 80 break_environment_ = environment()->CopyAsUnreachable(); 81 body_environments_.AddBlock(NULL, case_count(), zone()); 82 } 83 84 BeginLabel(int index,Node * condition)85void SwitchBuilder::BeginLabel(int index, Node* condition) { 86 builder_->NewBranch(condition); 87 label_environment_ = environment()->CopyForConditional(); 88 builder_->NewIfTrue(); 89 body_environments_[index] = environment(); 90 } 91 92 EndLabel()93void SwitchBuilder::EndLabel() { 94 set_environment(label_environment_); 95 builder_->NewIfFalse(); 96 } 97 98 DefaultAt(int index)99void SwitchBuilder::DefaultAt(int index) { 100 label_environment_ = environment()->CopyAsUnreachable(); 101 body_environments_[index] = environment(); 102 } 103 104 BeginCase(int index)105void SwitchBuilder::BeginCase(int index) { 106 set_environment(body_environments_[index]); 107 environment()->Merge(body_environment_); 108 } 109 110 Break()111void SwitchBuilder::Break() { 112 break_environment_->Merge(environment()); 113 environment()->MarkAsUnreachable(); 114 } 115 116 EndCase()117void SwitchBuilder::EndCase() { body_environment_ = environment(); } 118 119 EndSwitch()120void SwitchBuilder::EndSwitch() { 121 break_environment_->Merge(label_environment_); 122 break_environment_->Merge(environment()); 123 set_environment(break_environment_); 124 } 125 126 BeginBlock()127void BlockBuilder::BeginBlock() { 128 break_environment_ = environment()->CopyAsUnreachable(); 129 } 130 131 Break()132void BlockBuilder::Break() { 133 break_environment_->Merge(environment()); 134 environment()->MarkAsUnreachable(); 135 } 136 137 EndBlock()138void BlockBuilder::EndBlock() { 139 break_environment_->Merge(environment()); 140 set_environment(break_environment_); 141 } 142 } 143 } 144 } // namespace v8::internal::compiler 145