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

Side by Side Diff: src/compiler/control-builders.h

Issue 873423004: First stab at try-catch and try-finally in TurboFan. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed moarer comments by Ben Titzer. Created 5 years, 10 months 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/compiler/ast-graph-builder.cc ('k') | src/compiler/control-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 2013 the V8 project authors. All rights reserved. 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 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_COMPILER_CONTROL_BUILDERS_H_ 5 #ifndef V8_COMPILER_CONTROL_BUILDERS_H_
6 #define V8_COMPILER_CONTROL_BUILDERS_H_ 6 #define V8_COMPILER_CONTROL_BUILDERS_H_
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/compiler/ast-graph-builder.h" 10 #include "src/compiler/ast-graph-builder.h"
11 #include "src/compiler/node.h" 11 #include "src/compiler/node.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 namespace compiler { 15 namespace compiler {
16 16
17 // Base class for all control builders. Also provides a common interface for 17 // Base class for all control builders. Also provides a common interface for
18 // control builders to handle 'break' and 'continue' statements when they are 18 // control builders to handle 'break' statements when they are used to model
19 // used to model breakable statements. 19 // breakable statements.
20 class ControlBuilder { 20 class ControlBuilder {
21 public: 21 public:
22 explicit ControlBuilder(AstGraphBuilder* builder) : builder_(builder) {} 22 explicit ControlBuilder(AstGraphBuilder* builder) : builder_(builder) {}
23 virtual ~ControlBuilder() {} 23 virtual ~ControlBuilder() {}
24 24
25 // Interface for break and continue. 25 // Interface for break.
26 virtual void Break() { UNREACHABLE(); } 26 virtual void Break() { UNREACHABLE(); }
27 virtual void Continue() { UNREACHABLE(); }
28 27
29 protected: 28 protected:
30 typedef AstGraphBuilder Builder; 29 typedef AstGraphBuilder Builder;
31 typedef AstGraphBuilder::Environment Environment; 30 typedef AstGraphBuilder::Environment Environment;
32 31
33 Zone* zone() const { return builder_->local_zone(); } 32 Zone* zone() const { return builder_->local_zone(); }
34 Environment* environment() { return builder_->environment(); } 33 Environment* environment() { return builder_->environment(); }
35 void set_environment(Environment* env) { builder_->set_environment(env); } 34 void set_environment(Environment* env) { builder_->set_environment(env); }
36 35
37 Builder* builder_; 36 Builder* builder_;
(...skipping 24 matching lines...) Expand all
62 class LoopBuilder FINAL : public ControlBuilder { 61 class LoopBuilder FINAL : public ControlBuilder {
63 public: 62 public:
64 explicit LoopBuilder(AstGraphBuilder* builder) 63 explicit LoopBuilder(AstGraphBuilder* builder)
65 : ControlBuilder(builder), 64 : ControlBuilder(builder),
66 loop_environment_(NULL), 65 loop_environment_(NULL),
67 continue_environment_(NULL), 66 continue_environment_(NULL),
68 break_environment_(NULL) {} 67 break_environment_(NULL) {}
69 68
70 // Primitive control commands. 69 // Primitive control commands.
71 void BeginLoop(BitVector* assigned, bool is_osr = false); 70 void BeginLoop(BitVector* assigned, bool is_osr = false);
71 void Continue();
72 void EndBody(); 72 void EndBody();
73 void EndLoop(); 73 void EndLoop();
74 74
75 // Primitive support for break and continue. 75 // Primitive support for break.
76 void Continue() FINAL;
77 void Break() FINAL; 76 void Break() FINAL;
78 77
79 // Compound control commands for conditional break. 78 // Compound control commands for conditional break.
80 void BreakUnless(Node* condition); 79 void BreakUnless(Node* condition);
81 void BreakWhen(Node* condition); 80 void BreakWhen(Node* condition);
82 81
83 private: 82 private:
84 Environment* loop_environment_; // Environment of the loop header. 83 Environment* loop_environment_; // Environment of the loop header.
85 Environment* continue_environment_; // Environment after the loop body. 84 Environment* continue_environment_; // Environment after the loop body.
86 Environment* break_environment_; // Environment after the loop exits. 85 Environment* break_environment_; // Environment after the loop exits.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void BeginBlock(); 129 void BeginBlock();
131 void EndBlock(); 130 void EndBlock();
132 131
133 // Primitive support for break. 132 // Primitive support for break.
134 void Break() FINAL; 133 void Break() FINAL;
135 134
136 private: 135 private:
137 Environment* break_environment_; // Environment after the block exits. 136 Environment* break_environment_; // Environment after the block exits.
138 }; 137 };
139 138
139
140 // Tracks control flow for a try-catch statement.
141 class TryCatchBuilder FINAL : public ControlBuilder {
142 public:
143 explicit TryCatchBuilder(AstGraphBuilder* builder)
144 : ControlBuilder(builder),
145 catch_environment_(NULL),
146 exit_environment_(NULL),
147 exception_node_(NULL) {}
148
149 // Primitive control commands.
150 void BeginTry();
151 void Throw(Node* exception);
152 void EndTry();
153 void EndCatch();
154
155 // Returns the exception value inside the 'catch' body.
156 Node* GetExceptionNode() const { return exception_node_; }
157
158 private:
159 Environment* catch_environment_; // Environment for the 'catch' body.
160 Environment* exit_environment_; // Environment after the statement.
161 Node* exception_node_; // Node for exception in 'catch' body.
162 };
163
164
165 // Tracks control flow for a try-finally statement.
166 class TryFinallyBuilder FINAL : public ControlBuilder {
167 public:
168 explicit TryFinallyBuilder(AstGraphBuilder* builder)
169 : ControlBuilder(builder),
170 finally_environment_(NULL),
171 token_node_(NULL) {}
172
173 // Primitive control commands.
174 void BeginTry();
175 void LeaveTry(Node* token);
176 void EndTry(Node* token);
177 void EndFinally();
178
179 // Returns the dispatch token value inside the 'finally' body.
180 Node* GetDispatchTokenNode() const { return token_node_; }
181
182 private:
183 Environment* finally_environment_; // Environment for the 'finally' body.
184 Node* token_node_; // Node for token in 'finally' body.
185 };
186
140 } // namespace compiler 187 } // namespace compiler
141 } // namespace internal 188 } // namespace internal
142 } // namespace v8 189 } // namespace v8
143 190
144 #endif // V8_COMPILER_CONTROL_BUILDERS_H_ 191 #endif // V8_COMPILER_CONTROL_BUILDERS_H_
OLDNEW
« no previous file with comments | « src/compiler/ast-graph-builder.cc ('k') | src/compiler/control-builders.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698