5 #include "src/interpreter/control-flow-builders.h" 6 #include "src/objects-inl.h" 10 namespace interpreter {
13 BreakableControlFlowBuilder::~BreakableControlFlowBuilder() {
15 DCHECK(break_labels_.empty() || break_labels_.is_bound());
16 if (block_coverage_builder_ !=
nullptr && needs_continuation_counter()) {
17 block_coverage_builder_->IncrementBlockCounter(
18 node_, SourceRangeKind::kContinuation);
22 void BreakableControlFlowBuilder::BindBreakTarget() {
23 break_labels_.Bind(builder());
26 void BreakableControlFlowBuilder::EmitJump(BytecodeLabels* sites) {
27 builder()->Jump(sites->New());
30 void BreakableControlFlowBuilder::EmitJumpIfTrue(
31 BytecodeArrayBuilder::ToBooleanMode mode, BytecodeLabels* sites) {
32 builder()->JumpIfTrue(mode, sites->New());
35 void BreakableControlFlowBuilder::EmitJumpIfFalse(
36 BytecodeArrayBuilder::ToBooleanMode mode, BytecodeLabels* sites) {
37 builder()->JumpIfFalse(mode, sites->New());
40 void BreakableControlFlowBuilder::EmitJumpIfUndefined(BytecodeLabels* sites) {
41 builder()->JumpIfUndefined(sites->New());
44 void BreakableControlFlowBuilder::EmitJumpIfNull(BytecodeLabels* sites) {
45 builder()->JumpIfNull(sites->New());
48 LoopBuilder::~LoopBuilder() {
49 DCHECK(continue_labels_.empty() || continue_labels_.is_bound());
52 void LoopBuilder::LoopHeader() {
57 DCHECK(break_labels_.empty() && continue_labels_.empty());
58 builder()->Bind(&loop_header_);
61 void LoopBuilder::LoopBody() {
62 if (block_coverage_builder_ !=
nullptr) {
63 block_coverage_builder_->IncrementBlockCounter(block_coverage_body_slot_);
67 void LoopBuilder::JumpToHeader(
int loop_depth) {
70 int level = Min(loop_depth, AbstractCode::kMaxLoopNestingMarker - 1);
73 DCHECK(loop_header_.is_bound());
74 builder()->JumpLoop(&loop_header_, level);
77 void LoopBuilder::BindContinueTarget() { continue_labels_.Bind(builder()); }
79 SwitchBuilder::~SwitchBuilder() {
81 for (
auto site : case_sites_) {
82 DCHECK(site.is_bound());
87 void SwitchBuilder::SetCaseTarget(
int index, CaseClause* clause) {
88 BytecodeLabel& site = case_sites_.at(index);
89 builder()->Bind(&site);
90 if (block_coverage_builder_) {
91 block_coverage_builder_->IncrementBlockCounter(clause,
92 SourceRangeKind::kBody);
96 TryCatchBuilder::~TryCatchBuilder() {
97 if (block_coverage_builder_ !=
nullptr) {
98 block_coverage_builder_->IncrementBlockCounter(
99 statement_, SourceRangeKind::kContinuation);
103 void TryCatchBuilder::BeginTry(Register context) {
104 builder()->MarkTryBegin(handler_id_, context);
108 void TryCatchBuilder::EndTry() {
109 builder()->MarkTryEnd(handler_id_);
110 builder()->Jump(&exit_);
111 builder()->Bind(&handler_);
112 builder()->MarkHandler(handler_id_, catch_prediction_);
114 if (block_coverage_builder_ !=
nullptr) {
115 block_coverage_builder_->IncrementBlockCounter(statement_,
116 SourceRangeKind::kCatch);
120 void TryCatchBuilder::EndCatch() { builder()->Bind(&exit_); }
122 TryFinallyBuilder::~TryFinallyBuilder() {
123 if (block_coverage_builder_ !=
nullptr) {
124 block_coverage_builder_->IncrementBlockCounter(
125 statement_, SourceRangeKind::kContinuation);
129 void TryFinallyBuilder::BeginTry(Register context) {
130 builder()->MarkTryBegin(handler_id_, context);
134 void TryFinallyBuilder::LeaveTry() {
135 builder()->Jump(finalization_sites_.New());
139 void TryFinallyBuilder::EndTry() {
140 builder()->MarkTryEnd(handler_id_);
144 void TryFinallyBuilder::BeginHandler() {
145 builder()->Bind(&handler_);
146 builder()->MarkHandler(handler_id_, catch_prediction_);
149 void TryFinallyBuilder::BeginFinally() {
150 finalization_sites_.Bind(builder());
152 if (block_coverage_builder_ !=
nullptr) {
153 block_coverage_builder_->IncrementBlockCounter(statement_,
154 SourceRangeKind::kFinally);
158 void TryFinallyBuilder::EndFinally() {
162 ConditionalControlFlowBuilder::~ConditionalControlFlowBuilder() {
163 if (!else_labels_.is_bound()) else_labels_.Bind(builder());
164 end_labels_.Bind(builder());
166 DCHECK(end_labels_.empty() || end_labels_.is_bound());
167 DCHECK(then_labels_.empty() || then_labels_.is_bound());
168 DCHECK(else_labels_.empty() || else_labels_.is_bound());
172 if (block_coverage_builder_ !=
nullptr && node_->IsIfStatement()) {
173 block_coverage_builder_->IncrementBlockCounter(
174 node_, SourceRangeKind::kContinuation);
178 void ConditionalControlFlowBuilder::JumpToEnd() {
179 DCHECK(end_labels_.empty());
180 builder()->Jump(end_labels_.New());
183 void ConditionalControlFlowBuilder::Then() {
184 then_labels()->Bind(builder());
185 if (block_coverage_builder_ !=
nullptr) {
186 block_coverage_builder_->IncrementBlockCounter(block_coverage_then_slot_);
190 void ConditionalControlFlowBuilder::Else() {
191 else_labels()->Bind(builder());
192 if (block_coverage_builder_ !=
nullptr) {
193 block_coverage_builder_->IncrementBlockCounter(block_coverage_else_slot_);