| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/interpreter/control-flow-builders.h" | 5 #include "src/interpreter/control-flow-builders.h" |
| 6 | 6 |
| 7 namespace v8 { | 7 namespace v8 { |
| 8 namespace internal { | 8 namespace internal { |
| 9 namespace interpreter { | 9 namespace interpreter { |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 } | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 void BreakableControlFlowBuilder::EmitJumpIfTrue( | 28 void BreakableControlFlowBuilder::EmitJumpIfTrue( |
| 29 ZoneVector<BytecodeLabel>* sites) { | 29 ZoneVector<BytecodeLabel>* sites) { |
| 30 sites->push_back(BytecodeLabel()); | 30 sites->push_back(BytecodeLabel()); |
| 31 builder()->JumpIfTrue(&sites->back()); | 31 builder()->JumpIfTrue(&sites->back()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 | 34 |
| 35 void BreakableControlFlowBuilder::EmitJumpIfFalse( |
| 36 ZoneVector<BytecodeLabel>* sites) { |
| 37 sites->push_back(BytecodeLabel()); |
| 38 builder()->JumpIfFalse(&sites->back()); |
| 39 } |
| 40 |
| 41 |
| 35 void BreakableControlFlowBuilder::EmitJumpIfUndefined( | 42 void BreakableControlFlowBuilder::EmitJumpIfUndefined( |
| 36 ZoneVector<BytecodeLabel>* sites) { | 43 ZoneVector<BytecodeLabel>* sites) { |
| 37 sites->push_back(BytecodeLabel()); | 44 sites->push_back(BytecodeLabel()); |
| 38 builder()->JumpIfUndefined(&sites->back()); | 45 builder()->JumpIfUndefined(&sites->back()); |
| 39 } | 46 } |
| 40 | 47 |
| 41 | 48 |
| 42 void BreakableControlFlowBuilder::EmitJumpIfNull( | 49 void BreakableControlFlowBuilder::EmitJumpIfNull( |
| 43 ZoneVector<BytecodeLabel>* sites) { | 50 ZoneVector<BytecodeLabel>* sites) { |
| 44 sites->push_back(BytecodeLabel()); | 51 sites->push_back(BytecodeLabel()); |
| 45 builder()->JumpIfNull(&sites->back()); | 52 builder()->JumpIfNull(&sites->back()); |
| 46 } | 53 } |
| 47 | 54 |
| 48 | 55 |
| 49 void BreakableControlFlowBuilder::EmitJump(ZoneVector<BytecodeLabel>* sites, | 56 void BreakableControlFlowBuilder::EmitJump(ZoneVector<BytecodeLabel>* sites, |
| 50 int index) { | 57 int index) { |
| 51 builder()->Jump(&sites->at(index)); | 58 builder()->Jump(&sites->at(index)); |
| 52 } | 59 } |
| 53 | 60 |
| 54 | 61 |
| 55 void BreakableControlFlowBuilder::EmitJumpIfTrue( | 62 void BreakableControlFlowBuilder::EmitJumpIfTrue( |
| 56 ZoneVector<BytecodeLabel>* sites, int index) { | 63 ZoneVector<BytecodeLabel>* sites, int index) { |
| 57 builder()->JumpIfTrue(&sites->at(index)); | 64 builder()->JumpIfTrue(&sites->at(index)); |
| 58 } | 65 } |
| 59 | 66 |
| 60 | 67 |
| 68 void BreakableControlFlowBuilder::EmitJumpIfFalse( |
| 69 ZoneVector<BytecodeLabel>* sites, int index) { |
| 70 builder()->JumpIfFalse(&sites->at(index)); |
| 71 } |
| 72 |
| 73 |
| 61 void BreakableControlFlowBuilder::BindLabels(const BytecodeLabel& target, | 74 void BreakableControlFlowBuilder::BindLabels(const BytecodeLabel& target, |
| 62 ZoneVector<BytecodeLabel>* sites) { | 75 ZoneVector<BytecodeLabel>* sites) { |
| 63 for (size_t i = 0; i < sites->size(); i++) { | 76 for (size_t i = 0; i < sites->size(); i++) { |
| 64 BytecodeLabel& site = sites->at(i); | 77 BytecodeLabel& site = sites->at(i); |
| 65 builder()->Bind(target, &site); | 78 builder()->Bind(target, &site); |
| 66 } | 79 } |
| 67 sites->clear(); | 80 sites->clear(); |
| 68 } | 81 } |
| 69 | 82 |
| 70 | 83 |
| 71 LoopBuilder::~LoopBuilder() { DCHECK(continue_sites_.empty()); } | 84 LoopBuilder::~LoopBuilder() { DCHECK(continue_sites_.empty()); } |
| 72 | 85 |
| 73 | 86 |
| 87 void LoopBuilder::LoopEnd() { |
| 88 // Loop must have closed form, i.e. all loop elements are within the loop, |
| 89 // the loop header precedes the body and next elements in the loop. |
| 90 DCHECK(loop_header_.is_bound()); |
| 91 builder()->Bind(&loop_end_); |
| 92 SetBreakTarget(loop_end_); |
| 93 if (next_.is_bound()) { |
| 94 DCHECK(!condition_.is_bound() || next_.offset() >= condition_.offset()); |
| 95 SetContinueTarget(next_); |
| 96 } else { |
| 97 DCHECK(condition_.is_bound()); |
| 98 DCHECK_GE(condition_.offset(), loop_header_.offset()); |
| 99 DCHECK_LE(condition_.offset(), loop_end_.offset()); |
| 100 SetContinueTarget(condition_); |
| 101 } |
| 102 } |
| 103 |
| 104 |
| 74 void LoopBuilder::SetContinueTarget(const BytecodeLabel& target) { | 105 void LoopBuilder::SetContinueTarget(const BytecodeLabel& target) { |
| 75 BindLabels(target, &continue_sites_); | 106 BindLabels(target, &continue_sites_); |
| 76 } | 107 } |
| 77 | 108 |
| 78 | 109 |
| 79 SwitchBuilder::~SwitchBuilder() { | 110 SwitchBuilder::~SwitchBuilder() { |
| 80 #ifdef DEBUG | 111 #ifdef DEBUG |
| 81 for (auto site : case_sites_) { | 112 for (auto site : case_sites_) { |
| 82 DCHECK(site.is_bound()); | 113 DCHECK(site.is_bound()); |
| 83 } | 114 } |
| 84 #endif | 115 #endif |
| 85 } | 116 } |
| 86 | 117 |
| 87 | 118 |
| 88 void SwitchBuilder::SetCaseTarget(int index) { | 119 void SwitchBuilder::SetCaseTarget(int index) { |
| 89 BytecodeLabel& site = case_sites_.at(index); | 120 BytecodeLabel& site = case_sites_.at(index); |
| 90 builder()->Bind(&site); | 121 builder()->Bind(&site); |
| 91 } | 122 } |
| 92 | 123 |
| 93 } // namespace interpreter | 124 } // namespace interpreter |
| 94 } // namespace internal | 125 } // namespace internal |
| 95 } // namespace v8 | 126 } // namespace v8 |
| OLD | NEW |