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 |
11 | 11 |
12 LoopBuilder::~LoopBuilder() { | 12 BreakableControlFlowBuilder::~BreakableControlFlowBuilder() { |
13 DCHECK(continue_sites_.empty()); | |
14 DCHECK(break_sites_.empty()); | 13 DCHECK(break_sites_.empty()); |
15 } | 14 } |
16 | 15 |
17 | 16 |
18 void LoopBuilder::SetContinueTarget(const BytecodeLabel& target) { | 17 void BreakableControlFlowBuilder::SetBreakTarget(const BytecodeLabel& target) { |
19 BindLabels(target, &continue_sites_); | |
20 } | |
21 | |
22 | |
23 void LoopBuilder::SetBreakTarget(const BytecodeLabel& target) { | |
24 BindLabels(target, &break_sites_); | 18 BindLabels(target, &break_sites_); |
25 } | 19 } |
26 | 20 |
27 | 21 |
28 void LoopBuilder::EmitJump(ZoneVector<BytecodeLabel>* sites) { | 22 void BreakableControlFlowBuilder::EmitJump(ZoneVector<BytecodeLabel>* sites) { |
29 sites->push_back(BytecodeLabel()); | 23 sites->push_back(BytecodeLabel()); |
30 builder()->Jump(&sites->back()); | 24 builder()->Jump(&sites->back()); |
31 } | 25 } |
32 | 26 |
33 | 27 |
34 void LoopBuilder::EmitJumpIfTrue(ZoneVector<BytecodeLabel>* sites) { | 28 void BreakableControlFlowBuilder::EmitJumpIfTrue( |
| 29 ZoneVector<BytecodeLabel>* sites) { |
35 sites->push_back(BytecodeLabel()); | 30 sites->push_back(BytecodeLabel()); |
36 builder()->JumpIfTrue(&sites->back()); | 31 builder()->JumpIfTrue(&sites->back()); |
37 } | 32 } |
38 | 33 |
39 | 34 |
40 void LoopBuilder::EmitJumpIfUndefined(ZoneVector<BytecodeLabel>* sites) { | 35 void BreakableControlFlowBuilder::EmitJumpIfUndefined( |
| 36 ZoneVector<BytecodeLabel>* sites) { |
41 sites->push_back(BytecodeLabel()); | 37 sites->push_back(BytecodeLabel()); |
42 builder()->JumpIfUndefined(&sites->back()); | 38 builder()->JumpIfUndefined(&sites->back()); |
43 } | 39 } |
44 | 40 |
45 | 41 |
46 void LoopBuilder::EmitJumpIfNull(ZoneVector<BytecodeLabel>* sites) { | 42 void BreakableControlFlowBuilder::EmitJumpIfNull( |
| 43 ZoneVector<BytecodeLabel>* sites) { |
47 sites->push_back(BytecodeLabel()); | 44 sites->push_back(BytecodeLabel()); |
48 builder()->JumpIfNull(&sites->back()); | 45 builder()->JumpIfNull(&sites->back()); |
49 } | 46 } |
50 | 47 |
51 | 48 |
52 void LoopBuilder::BindLabels(const BytecodeLabel& target, | 49 void BreakableControlFlowBuilder::EmitJump(ZoneVector<BytecodeLabel>* sites, |
53 ZoneVector<BytecodeLabel>* sites) { | 50 int index) { |
| 51 builder()->Jump(&sites->at(index)); |
| 52 } |
| 53 |
| 54 |
| 55 void BreakableControlFlowBuilder::EmitJumpIfTrue( |
| 56 ZoneVector<BytecodeLabel>* sites, int index) { |
| 57 builder()->JumpIfTrue(&sites->at(index)); |
| 58 } |
| 59 |
| 60 |
| 61 void BreakableControlFlowBuilder::BindLabels(const BytecodeLabel& target, |
| 62 ZoneVector<BytecodeLabel>* sites) { |
54 for (size_t i = 0; i < sites->size(); i++) { | 63 for (size_t i = 0; i < sites->size(); i++) { |
55 BytecodeLabel& site = sites->at(i); | 64 BytecodeLabel& site = sites->at(i); |
56 builder()->Bind(target, &site); | 65 builder()->Bind(target, &site); |
57 } | 66 } |
58 sites->clear(); | 67 sites->clear(); |
59 } | 68 } |
60 | 69 |
| 70 |
| 71 LoopBuilder::~LoopBuilder() { DCHECK(continue_sites_.empty()); } |
| 72 |
| 73 |
| 74 void LoopBuilder::SetContinueTarget(const BytecodeLabel& target) { |
| 75 BindLabels(target, &continue_sites_); |
| 76 } |
| 77 |
| 78 |
| 79 SwitchBuilder::~SwitchBuilder() { |
| 80 #ifdef DEBUG |
| 81 for (auto site : case_sites_) { |
| 82 DCHECK(site.is_bound()); |
| 83 } |
| 84 #endif |
| 85 } |
| 86 |
| 87 |
| 88 void SwitchBuilder::SetCaseTarget(int index) { |
| 89 BytecodeLabel& site = case_sites_.at(index); |
| 90 builder()->Bind(&site); |
| 91 } |
| 92 |
61 } // namespace interpreter | 93 } // namespace interpreter |
62 } // namespace internal | 94 } // namespace internal |
63 } // namespace v8 | 95 } // namespace v8 |
OLD | NEW |