| OLD | NEW |
| 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/compiler/ast-graph-builder.h" | 8 #include "src/compiler/ast-graph-builder.h" |
| 9 #include "src/compiler/node.h" | 9 #include "src/compiler/node.h" |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 Builder* builder_; | 35 Builder* builder_; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 | 38 |
| 39 // Tracks control flow for a conditional statement. | 39 // Tracks control flow for a conditional statement. |
| 40 class IfBuilder final : public ControlBuilder { | 40 class IfBuilder final : public ControlBuilder { |
| 41 public: | 41 public: |
| 42 explicit IfBuilder(AstGraphBuilder* builder) | 42 explicit IfBuilder(AstGraphBuilder* builder) |
| 43 : ControlBuilder(builder), | 43 : ControlBuilder(builder), |
| 44 then_environment_(NULL), | 44 then_environment_(nullptr), |
| 45 else_environment_(NULL) {} | 45 else_environment_(nullptr) {} |
| 46 | 46 |
| 47 // Primitive control commands. | 47 // Primitive control commands. |
| 48 void If(Node* condition, BranchHint hint = BranchHint::kNone); | 48 void If(Node* condition, BranchHint hint = BranchHint::kNone); |
| 49 void Then(); | 49 void Then(); |
| 50 void Else(); | 50 void Else(); |
| 51 void End(); | 51 void End(); |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 Environment* then_environment_; // Environment after the 'then' body. | 54 Environment* then_environment_; // Environment after the 'then' body. |
| 55 Environment* else_environment_; // Environment for the 'else' body. | 55 Environment* else_environment_; // Environment for the 'else' body. |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 | 58 |
| 59 // Tracks control flow for an iteration statement. | 59 // Tracks control flow for an iteration statement. |
| 60 class LoopBuilder final : public ControlBuilder { | 60 class LoopBuilder final : public ControlBuilder { |
| 61 public: | 61 public: |
| 62 explicit LoopBuilder(AstGraphBuilder* builder) | 62 explicit LoopBuilder(AstGraphBuilder* builder) |
| 63 : ControlBuilder(builder), | 63 : ControlBuilder(builder), |
| 64 loop_environment_(NULL), | 64 loop_environment_(nullptr), |
| 65 continue_environment_(NULL), | 65 continue_environment_(nullptr), |
| 66 break_environment_(NULL) {} | 66 break_environment_(nullptr) {} |
| 67 | 67 |
| 68 // Primitive control commands. | 68 // Primitive control commands. |
| 69 void BeginLoop(BitVector* assigned, bool is_osr = false); | 69 void BeginLoop(BitVector* assigned, bool is_osr = false); |
| 70 void Continue(); | 70 void Continue(); |
| 71 void EndBody(); | 71 void EndBody(); |
| 72 void EndLoop(); | 72 void EndLoop(); |
| 73 | 73 |
| 74 // Primitive support for break. | 74 // Primitive support for break. |
| 75 void Break() final; | 75 void Break() final; |
| 76 | 76 |
| 77 // Compound control commands for conditional break. | 77 // Compound control commands for conditional break. |
| 78 void BreakUnless(Node* condition); | 78 void BreakUnless(Node* condition); |
| 79 void BreakWhen(Node* condition); | 79 void BreakWhen(Node* condition); |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 Environment* loop_environment_; // Environment of the loop header. | 82 Environment* loop_environment_; // Environment of the loop header. |
| 83 Environment* continue_environment_; // Environment after the loop body. | 83 Environment* continue_environment_; // Environment after the loop body. |
| 84 Environment* break_environment_; // Environment after the loop exits. | 84 Environment* break_environment_; // Environment after the loop exits. |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 | 87 |
| 88 // Tracks control flow for a switch statement. | 88 // Tracks control flow for a switch statement. |
| 89 class SwitchBuilder final : public ControlBuilder { | 89 class SwitchBuilder final : public ControlBuilder { |
| 90 public: | 90 public: |
| 91 explicit SwitchBuilder(AstGraphBuilder* builder, int case_count) | 91 explicit SwitchBuilder(AstGraphBuilder* builder, int case_count) |
| 92 : ControlBuilder(builder), | 92 : ControlBuilder(builder), |
| 93 body_environment_(NULL), | 93 body_environment_(nullptr), |
| 94 label_environment_(NULL), | 94 label_environment_(nullptr), |
| 95 break_environment_(NULL), | 95 break_environment_(nullptr), |
| 96 body_environments_(case_count, zone()) {} | 96 body_environments_(case_count, zone()) {} |
| 97 | 97 |
| 98 // Primitive control commands. | 98 // Primitive control commands. |
| 99 void BeginSwitch(); | 99 void BeginSwitch(); |
| 100 void BeginLabel(int index, Node* condition); | 100 void BeginLabel(int index, Node* condition); |
| 101 void EndLabel(); | 101 void EndLabel(); |
| 102 void DefaultAt(int index); | 102 void DefaultAt(int index); |
| 103 void BeginCase(int index); | 103 void BeginCase(int index); |
| 104 void EndCase(); | 104 void EndCase(); |
| 105 void EndSwitch(); | 105 void EndSwitch(); |
| 106 | 106 |
| 107 // Primitive support for break. | 107 // Primitive support for break. |
| 108 void Break() final; | 108 void Break() final; |
| 109 | 109 |
| 110 // The number of cases within a switch is statically known. | 110 // The number of cases within a switch is statically known. |
| 111 size_t case_count() const { return body_environments_.size(); } | 111 size_t case_count() const { return body_environments_.size(); } |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 Environment* body_environment_; // Environment after last case body. | 114 Environment* body_environment_; // Environment after last case body. |
| 115 Environment* label_environment_; // Environment for next label condition. | 115 Environment* label_environment_; // Environment for next label condition. |
| 116 Environment* break_environment_; // Environment after the switch exits. | 116 Environment* break_environment_; // Environment after the switch exits. |
| 117 ZoneVector<Environment*> body_environments_; | 117 ZoneVector<Environment*> body_environments_; |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 | 120 |
| 121 // Tracks control flow for a block statement. | 121 // Tracks control flow for a block statement. |
| 122 class BlockBuilder final : public ControlBuilder { | 122 class BlockBuilder final : public ControlBuilder { |
| 123 public: | 123 public: |
| 124 explicit BlockBuilder(AstGraphBuilder* builder) | 124 explicit BlockBuilder(AstGraphBuilder* builder) |
| 125 : ControlBuilder(builder), break_environment_(NULL) {} | 125 : ControlBuilder(builder), break_environment_(nullptr) {} |
| 126 | 126 |
| 127 // Primitive control commands. | 127 // Primitive control commands. |
| 128 void BeginBlock(); | 128 void BeginBlock(); |
| 129 void EndBlock(); | 129 void EndBlock(); |
| 130 | 130 |
| 131 // Primitive support for break. | 131 // Primitive support for break. |
| 132 void Break() final; | 132 void Break() final; |
| 133 | 133 |
| 134 // Compound control commands for conditional break. | 134 // Compound control commands for conditional break. |
| 135 void BreakWhen(Node* condition, BranchHint = BranchHint::kNone); | 135 void BreakWhen(Node* condition, BranchHint = BranchHint::kNone); |
| 136 void BreakUnless(Node* condition, BranchHint hint = BranchHint::kNone); | 136 void BreakUnless(Node* condition, BranchHint hint = BranchHint::kNone); |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 Environment* break_environment_; // Environment after the block exits. | 139 Environment* break_environment_; // Environment after the block exits. |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 | 142 |
| 143 // Tracks control flow for a try-catch statement. | 143 // Tracks control flow for a try-catch statement. |
| 144 class TryCatchBuilder final : public ControlBuilder { | 144 class TryCatchBuilder final : public ControlBuilder { |
| 145 public: | 145 public: |
| 146 explicit TryCatchBuilder(AstGraphBuilder* builder) | 146 explicit TryCatchBuilder(AstGraphBuilder* builder) |
| 147 : ControlBuilder(builder), | 147 : ControlBuilder(builder), |
| 148 catch_environment_(NULL), | 148 catch_environment_(nullptr), |
| 149 exit_environment_(NULL), | 149 exit_environment_(nullptr), |
| 150 exception_node_(NULL) {} | 150 exception_node_(nullptr) {} |
| 151 | 151 |
| 152 // Primitive control commands. | 152 // Primitive control commands. |
| 153 void BeginTry(); | 153 void BeginTry(); |
| 154 void Throw(Node* exception); | 154 void Throw(Node* exception); |
| 155 void EndTry(); | 155 void EndTry(); |
| 156 void EndCatch(); | 156 void EndCatch(); |
| 157 | 157 |
| 158 // Returns the exception value inside the 'catch' body. | 158 // Returns the exception value inside the 'catch' body. |
| 159 Node* GetExceptionNode() const { return exception_node_; } | 159 Node* GetExceptionNode() const { return exception_node_; } |
| 160 | 160 |
| 161 private: | 161 private: |
| 162 Environment* catch_environment_; // Environment for the 'catch' body. | 162 Environment* catch_environment_; // Environment for the 'catch' body. |
| 163 Environment* exit_environment_; // Environment after the statement. | 163 Environment* exit_environment_; // Environment after the statement. |
| 164 Node* exception_node_; // Node for exception in 'catch' body. | 164 Node* exception_node_; // Node for exception in 'catch' body. |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 | 167 |
| 168 // Tracks control flow for a try-finally statement. | 168 // Tracks control flow for a try-finally statement. |
| 169 class TryFinallyBuilder final : public ControlBuilder { | 169 class TryFinallyBuilder final : public ControlBuilder { |
| 170 public: | 170 public: |
| 171 explicit TryFinallyBuilder(AstGraphBuilder* builder) | 171 explicit TryFinallyBuilder(AstGraphBuilder* builder) |
| 172 : ControlBuilder(builder), | 172 : ControlBuilder(builder), |
| 173 finally_environment_(NULL), | 173 finally_environment_(nullptr), |
| 174 token_node_(NULL), | 174 token_node_(nullptr), |
| 175 value_node_(NULL) {} | 175 value_node_(nullptr) {} |
| 176 | 176 |
| 177 // Primitive control commands. | 177 // Primitive control commands. |
| 178 void BeginTry(); | 178 void BeginTry(); |
| 179 void LeaveTry(Node* token, Node* value); | 179 void LeaveTry(Node* token, Node* value); |
| 180 void EndTry(Node* token, Node* value); | 180 void EndTry(Node* token, Node* value); |
| 181 void EndFinally(); | 181 void EndFinally(); |
| 182 | 182 |
| 183 // Returns the dispatch token value inside the 'finally' body. | 183 // Returns the dispatch token value inside the 'finally' body. |
| 184 Node* GetDispatchTokenNode() const { return token_node_; } | 184 Node* GetDispatchTokenNode() const { return token_node_; } |
| 185 | 185 |
| 186 // Returns the saved result value inside the 'finally' body. | 186 // Returns the saved result value inside the 'finally' body. |
| 187 Node* GetResultValueNode() const { return value_node_; } | 187 Node* GetResultValueNode() const { return value_node_; } |
| 188 | 188 |
| 189 private: | 189 private: |
| 190 Environment* finally_environment_; // Environment for the 'finally' body. | 190 Environment* finally_environment_; // Environment for the 'finally' body. |
| 191 Node* token_node_; // Node for token in 'finally' body. | 191 Node* token_node_; // Node for token in 'finally' body. |
| 192 Node* value_node_; // Node for value in 'finally' body. | 192 Node* value_node_; // Node for value in 'finally' body. |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 } // namespace compiler | 195 } // namespace compiler |
| 196 } // namespace internal | 196 } // namespace internal |
| 197 } // namespace v8 | 197 } // namespace v8 |
| 198 | 198 |
| 199 #endif // V8_COMPILER_CONTROL_BUILDERS_H_ | 199 #endif // V8_COMPILER_CONTROL_BUILDERS_H_ |
| OLD | NEW |