Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: src/interpreter/control-flow-builders.h

Issue 1524893003: [Interpreter] Add support for break statements in labelled blocks. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@oth-0009-phi
Patch Set: Rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | src/interpreter/control-flow-builders.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ 5 #ifndef V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_
6 #define V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ 6 #define V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_
7 7
8 #include "src/interpreter/bytecode-array-builder.h" 8 #include "src/interpreter/bytecode-array-builder.h"
9 9
10 #include "src/zone-containers.h" 10 #include "src/zone-containers.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 void EmitJumpIfUndefined(ZoneVector<BytecodeLabel>* labels); 58 void EmitJumpIfUndefined(ZoneVector<BytecodeLabel>* labels);
59 void EmitJumpIfNull(ZoneVector<BytecodeLabel>* labels); 59 void EmitJumpIfNull(ZoneVector<BytecodeLabel>* labels);
60 60
61 void BindLabels(const BytecodeLabel& target, ZoneVector<BytecodeLabel>* site); 61 void BindLabels(const BytecodeLabel& target, ZoneVector<BytecodeLabel>* site);
62 62
63 private: 63 private:
64 // Unbound labels that identify jumps for break statements in the code. 64 // Unbound labels that identify jumps for break statements in the code.
65 ZoneVector<BytecodeLabel> break_sites_; 65 ZoneVector<BytecodeLabel> break_sites_;
66 }; 66 };
67 67
68
69 // Class to track control flow for block statements (which can break in JS).
70 class BlockBuilder final : public BreakableControlFlowBuilder {
71 public:
72 explicit BlockBuilder(BytecodeArrayBuilder* builder)
73 : BreakableControlFlowBuilder(builder) {}
74
75 void EndBlock();
76
77 private:
78 BytecodeLabel block_end_;
79 };
80
81
68 // A class to help with co-ordinating break and continue statements with 82 // A class to help with co-ordinating break and continue statements with
69 // their loop. 83 // their loop.
70 class LoopBuilder final : public BreakableControlFlowBuilder { 84 class LoopBuilder final : public BreakableControlFlowBuilder {
71 public: 85 public:
72 explicit LoopBuilder(BytecodeArrayBuilder* builder) 86 explicit LoopBuilder(BytecodeArrayBuilder* builder)
73 : BreakableControlFlowBuilder(builder), 87 : BreakableControlFlowBuilder(builder),
74 continue_sites_(builder->zone()) {} 88 continue_sites_(builder->zone()) {}
75 ~LoopBuilder(); 89 ~LoopBuilder();
76 90
77 void LoopHeader() { builder()->Bind(&loop_header_); } 91 void LoopHeader() { builder()->Bind(&loop_header_); }
78 void Condition() { builder()->Bind(&condition_); } 92 void Condition() { builder()->Bind(&condition_); }
79 void Next() { builder()->Bind(&next_); } 93 void Next() { builder()->Bind(&next_); }
80 void JumpToHeader() { builder()->Jump(&loop_header_); } 94 void JumpToHeader() { builder()->Jump(&loop_header_); }
81 void JumpToHeaderIfTrue() { builder()->JumpIfTrue(&loop_header_); } 95 void JumpToHeaderIfTrue() { builder()->JumpIfTrue(&loop_header_); }
82 void LoopEnd(); 96 void EndLoop();
83 97
84 // This method is called when visiting continue statements in the AST. 98 // This method is called when visiting continue statements in the AST.
85 // Inserts a jump to a unbound label that is patched when the corresponding 99 // Inserts a jump to a unbound label that is patched when the corresponding
86 // SetContinueTarget is called. 100 // SetContinueTarget is called.
87 void Continue() { EmitJump(&continue_sites_); } 101 void Continue() { EmitJump(&continue_sites_); }
88 void ContinueIfTrue() { EmitJumpIfTrue(&continue_sites_); } 102 void ContinueIfTrue() { EmitJumpIfTrue(&continue_sites_); }
89 void ContinueIfUndefined() { EmitJumpIfUndefined(&continue_sites_); } 103 void ContinueIfUndefined() { EmitJumpIfUndefined(&continue_sites_); }
90 void ContinueIfNull() { EmitJumpIfNull(&continue_sites_); } 104 void ContinueIfNull() { EmitJumpIfNull(&continue_sites_); }
91 105
92 private: 106 private:
93 void SetContinueTarget(const BytecodeLabel& continue_target); 107 void SetContinueTarget(const BytecodeLabel& continue_target);
94 108
95 BytecodeLabel loop_header_; 109 BytecodeLabel loop_header_;
96 BytecodeLabel condition_; 110 BytecodeLabel condition_;
97 BytecodeLabel next_; 111 BytecodeLabel next_;
98 BytecodeLabel loop_end_; 112 BytecodeLabel loop_end_;
99 113
100 // Unbound labels that identify jumps for continue statements in the code. 114 // Unbound labels that identify jumps for continue statements in the code.
101 ZoneVector<BytecodeLabel> continue_sites_; 115 ZoneVector<BytecodeLabel> continue_sites_;
102 }; 116 };
103 117
118
104 // A class to help with co-ordinating break statements with their switch. 119 // A class to help with co-ordinating break statements with their switch.
105 // TODO(oth): add support for TF branch/merge info.
106 class SwitchBuilder final : public BreakableControlFlowBuilder { 120 class SwitchBuilder final : public BreakableControlFlowBuilder {
107 public: 121 public:
108 explicit SwitchBuilder(BytecodeArrayBuilder* builder, int number_of_cases) 122 explicit SwitchBuilder(BytecodeArrayBuilder* builder, int number_of_cases)
109 : BreakableControlFlowBuilder(builder), 123 : BreakableControlFlowBuilder(builder),
110 case_sites_(builder->zone()) { 124 case_sites_(builder->zone()) {
111 case_sites_.resize(number_of_cases); 125 case_sites_.resize(number_of_cases);
112 } 126 }
113 ~SwitchBuilder(); 127 ~SwitchBuilder();
114 128
115 // This method should be called by the SwitchBuilder owner when the case 129 // This method should be called by the SwitchBuilder owner when the case
(...skipping 13 matching lines...) Expand all
129 private: 143 private:
130 // Unbound labels that identify jumps for case statements in the code. 144 // Unbound labels that identify jumps for case statements in the code.
131 ZoneVector<BytecodeLabel> case_sites_; 145 ZoneVector<BytecodeLabel> case_sites_;
132 }; 146 };
133 147
134 } // namespace interpreter 148 } // namespace interpreter
135 } // namespace internal 149 } // namespace internal
136 } // namespace v8 150 } // namespace v8
137 151
138 #endif // V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ 152 #endif // V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | src/interpreter/control-flow-builders.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698