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/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/compiler/graph-builder.h" | 10 #include "src/compiler/graph-builder.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 Zone* zone() const { return builder_->local_zone(); } | 34 Zone* zone() const { return builder_->local_zone(); } |
35 Environment* environment() { return builder_->environment(); } | 35 Environment* environment() { return builder_->environment(); } |
36 void set_environment(Environment* env) { builder_->set_environment(env); } | 36 void set_environment(Environment* env) { builder_->set_environment(env); } |
37 | 37 |
38 Builder* builder_; | 38 Builder* builder_; |
39 }; | 39 }; |
40 | 40 |
41 | 41 |
42 // Tracks control flow for a conditional statement. | 42 // Tracks control flow for a conditional statement. |
43 class IfBuilder : public ControlBuilder { | 43 class IfBuilder FINAL : public ControlBuilder { |
44 public: | 44 public: |
45 explicit IfBuilder(StructuredGraphBuilder* builder) | 45 explicit IfBuilder(StructuredGraphBuilder* builder) |
46 : ControlBuilder(builder), | 46 : ControlBuilder(builder), |
47 then_environment_(NULL), | 47 then_environment_(NULL), |
48 else_environment_(NULL) {} | 48 else_environment_(NULL) {} |
49 | 49 |
50 // Primitive control commands. | 50 // Primitive control commands. |
51 void If(Node* condition, BranchHint hint = BranchHint::kNone); | 51 void If(Node* condition, BranchHint hint = BranchHint::kNone); |
52 void Then(); | 52 void Then(); |
53 void Else(); | 53 void Else(); |
54 void End(); | 54 void End(); |
55 | 55 |
56 private: | 56 private: |
57 Environment* then_environment_; // Environment after the 'then' body. | 57 Environment* then_environment_; // Environment after the 'then' body. |
58 Environment* else_environment_; // Environment for the 'else' body. | 58 Environment* else_environment_; // Environment for the 'else' body. |
59 }; | 59 }; |
60 | 60 |
61 | 61 |
62 // Tracks control flow for an iteration statement. | 62 // Tracks control flow for an iteration statement. |
63 class LoopBuilder : public ControlBuilder { | 63 class LoopBuilder FINAL : public ControlBuilder { |
64 public: | 64 public: |
65 explicit LoopBuilder(StructuredGraphBuilder* builder) | 65 explicit LoopBuilder(StructuredGraphBuilder* builder) |
66 : ControlBuilder(builder), | 66 : ControlBuilder(builder), |
67 loop_environment_(NULL), | 67 loop_environment_(NULL), |
68 continue_environment_(NULL), | 68 continue_environment_(NULL), |
69 break_environment_(NULL) {} | 69 break_environment_(NULL) {} |
70 | 70 |
71 // Primitive control commands. | 71 // Primitive control commands. |
72 void BeginLoop(BitVector* assigned); | 72 void BeginLoop(BitVector* assigned); |
73 void EndBody(); | 73 void EndBody(); |
74 void EndLoop(); | 74 void EndLoop(); |
75 | 75 |
76 // Primitive support for break and continue. | 76 // Primitive support for break and continue. |
77 virtual void Continue(); | 77 void Continue() FINAL; |
78 virtual void Break(); | 78 void Break() FINAL; |
79 | 79 |
80 // Compound control command for conditional break. | 80 // Compound control command for conditional break. |
81 void BreakUnless(Node* condition); | 81 void BreakUnless(Node* condition); |
82 | 82 |
83 private: | 83 private: |
84 Environment* loop_environment_; // Environment of the loop header. | 84 Environment* loop_environment_; // Environment of the loop header. |
85 Environment* continue_environment_; // Environment after the loop body. | 85 Environment* continue_environment_; // Environment after the loop body. |
86 Environment* break_environment_; // Environment after the loop exits. | 86 Environment* break_environment_; // Environment after the loop exits. |
87 }; | 87 }; |
88 | 88 |
89 | 89 |
90 // Tracks control flow for a switch statement. | 90 // Tracks control flow for a switch statement. |
91 class SwitchBuilder : public ControlBuilder { | 91 class SwitchBuilder FINAL : public ControlBuilder { |
92 public: | 92 public: |
93 explicit SwitchBuilder(StructuredGraphBuilder* builder, int case_count) | 93 explicit SwitchBuilder(StructuredGraphBuilder* builder, int case_count) |
94 : ControlBuilder(builder), | 94 : ControlBuilder(builder), |
95 body_environment_(NULL), | 95 body_environment_(NULL), |
96 label_environment_(NULL), | 96 label_environment_(NULL), |
97 break_environment_(NULL), | 97 break_environment_(NULL), |
98 body_environments_(case_count, zone()) {} | 98 body_environments_(case_count, zone()) {} |
99 | 99 |
100 // Primitive control commands. | 100 // Primitive control commands. |
101 void BeginSwitch(); | 101 void BeginSwitch(); |
102 void BeginLabel(int index, Node* condition); | 102 void BeginLabel(int index, Node* condition); |
103 void EndLabel(); | 103 void EndLabel(); |
104 void DefaultAt(int index); | 104 void DefaultAt(int index); |
105 void BeginCase(int index); | 105 void BeginCase(int index); |
106 void EndCase(); | 106 void EndCase(); |
107 void EndSwitch(); | 107 void EndSwitch(); |
108 | 108 |
109 // Primitive support for break. | 109 // Primitive support for break. |
110 virtual void Break(); | 110 void Break() FINAL; |
111 | 111 |
112 // The number of cases within a switch is statically known. | 112 // The number of cases within a switch is statically known. |
113 size_t case_count() const { return body_environments_.size(); } | 113 size_t case_count() const { return body_environments_.size(); } |
114 | 114 |
115 private: | 115 private: |
116 Environment* body_environment_; // Environment after last case body. | 116 Environment* body_environment_; // Environment after last case body. |
117 Environment* label_environment_; // Environment for next label condition. | 117 Environment* label_environment_; // Environment for next label condition. |
118 Environment* break_environment_; // Environment after the switch exits. | 118 Environment* break_environment_; // Environment after the switch exits. |
119 ZoneVector<Environment*> body_environments_; | 119 ZoneVector<Environment*> body_environments_; |
120 }; | 120 }; |
121 | 121 |
122 | 122 |
123 // Tracks control flow for a block statement. | 123 // Tracks control flow for a block statement. |
124 class BlockBuilder : public ControlBuilder { | 124 class BlockBuilder FINAL : public ControlBuilder { |
125 public: | 125 public: |
126 explicit BlockBuilder(StructuredGraphBuilder* builder) | 126 explicit BlockBuilder(StructuredGraphBuilder* builder) |
127 : ControlBuilder(builder), break_environment_(NULL) {} | 127 : ControlBuilder(builder), break_environment_(NULL) {} |
128 | 128 |
129 // Primitive control commands. | 129 // Primitive control commands. |
130 void BeginBlock(); | 130 void BeginBlock(); |
131 void EndBlock(); | 131 void EndBlock(); |
132 | 132 |
133 // Primitive support for break. | 133 // Primitive support for break. |
134 virtual void Break(); | 134 void Break() FINAL; |
135 | 135 |
136 private: | 136 private: |
137 Environment* break_environment_; // Environment after the block exits. | 137 Environment* break_environment_; // Environment after the block exits. |
138 }; | 138 }; |
139 } | 139 |
140 } | 140 } // namespace compiler |
141 } // namespace v8::internal::compiler | 141 } // namespace internal |
| 142 } // namespace v8 |
142 | 143 |
143 #endif // V8_COMPILER_CONTROL_BUILDERS_H_ | 144 #endif // V8_COMPILER_CONTROL_BUILDERS_H_ |
OLD | NEW |