Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_FLOW_GRAPH_BUILDER_H_ | 5 #ifndef VM_FLOW_GRAPH_BUILDER_H_ |
| 6 #define VM_FLOW_GRAPH_BUILDER_H_ | 6 #define VM_FLOW_GRAPH_BUILDER_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
| 10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 | 84 |
| 85 // Append a 'while loop' test and back edge to this graph, depending on | 85 // Append a 'while loop' test and back edge to this graph, depending on |
| 86 // which parts are reachable. Afterward, the graph exit is the false | 86 // which parts are reachable. Afterward, the graph exit is the false |
| 87 // successor of the loop condition. | 87 // successor of the loop condition. |
| 88 void TieLoop(const TestGraphVisitor& test_fragment, | 88 void TieLoop(const TestGraphVisitor& test_fragment, |
| 89 const EffectGraphVisitor& body_fragment); | 89 const EffectGraphVisitor& body_fragment); |
| 90 | 90 |
| 91 protected: | 91 protected: |
| 92 // Helpers for translating parts of the AST. | 92 // Helpers for translating parts of the AST. |
| 93 void TranslateArgumentList(const ArgumentListNode& node, | 93 void TranslateArgumentList(const ArgumentListNode& node, |
| 94 intptr_t next_temp_index, | |
| 94 ZoneGrowableArray<Value*>* values); | 95 ZoneGrowableArray<Value*>* values); |
| 95 | 96 |
| 96 void CloseFragment() { exit_ = NULL; } | 97 void CloseFragment() { exit_ = NULL; } |
| 97 intptr_t AllocateTempIndex() { return temp_index_++; } | 98 intptr_t AllocateTempIndex() { return temp_index_++; } |
| 98 | 99 |
| 99 private: | 100 private: |
| 100 // Specify a computation as the final result. Adds a Do instruction to | 101 // Specify a computation as the final result. Adds a Do instruction to |
| 101 // the graph, but normally overridden in subclasses. | 102 // the graph, but normally overridden in subclasses. |
| 102 virtual void ReturnComputation(Computation* computation) { | 103 virtual void ReturnComputation(Computation* computation) { |
| 103 AddInstruction(new DoInstr(computation)); | 104 AddInstruction(new DoInstr(computation)); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 124 public: | 125 public: |
| 125 ValueGraphVisitor(FlowGraphBuilder* owner, intptr_t temp_index) | 126 ValueGraphVisitor(FlowGraphBuilder* owner, intptr_t temp_index) |
| 126 : EffectGraphVisitor(owner, temp_index), value_(NULL) { } | 127 : EffectGraphVisitor(owner, temp_index), value_(NULL) { } |
| 127 | 128 |
| 128 // Visit functions overridden by this class. | 129 // Visit functions overridden by this class. |
| 129 virtual void VisitLiteralNode(LiteralNode* node); | 130 virtual void VisitLiteralNode(LiteralNode* node); |
| 130 virtual void VisitLoadLocalNode(LoadLocalNode* node); | 131 virtual void VisitLoadLocalNode(LoadLocalNode* node); |
| 131 | 132 |
| 132 Value* value() const { return value_; } | 133 Value* value() const { return value_; } |
| 133 | 134 |
| 135 protected: | |
| 136 // Output parameters. | |
| 137 Value* value_; | |
| 138 | |
| 134 private: | 139 private: |
| 135 // Helper to set the output state to return a Value. | 140 // Helper to set the output state to return a Value. |
| 136 void ReturnValue(Value* value) { value_ = value; } | 141 virtual void ReturnValue(Value* value) { value_ = value; } |
| 137 | 142 |
| 138 // Specify a computation as the final result. Adds a Bind instruction to | 143 // Specify a computation as the final result. Adds a Bind instruction to |
| 139 // the graph and returns its temporary value (i.e., set the output | 144 // the graph and returns its temporary value (i.e., set the output |
| 140 // parameters). | 145 // parameters). |
| 141 virtual void ReturnComputation(Computation* computation) { | 146 virtual void ReturnComputation(Computation* computation) { |
| 142 AddInstruction(new BindInstr(temp_index(), computation)); | 147 AddInstruction(new BindInstr(temp_index(), computation)); |
| 143 value_ = new TempVal(AllocateTempIndex()); | 148 value_ = new TempVal(AllocateTempIndex()); |
| 144 } | 149 } |
| 145 | |
| 146 // Output parameters. | |
| 147 Value* value_; | |
| 148 }; | 150 }; |
| 149 | 151 |
| 150 | 152 |
| 153 // Translate an AstNode to a control-flow graph fragment for both its effects | |
| 154 // and value as an outgoing argument. Implements a function from an AstNode | |
| 155 // and next temporary index to a graph fragment (as in the | |
| 156 // EffectGraphBuilder), an updated temporary index, and an intermediate | |
| 157 // language Value. | |
|
srdjan
2012/03/01 17:50:12
Why do we need both ArgumentGraphVisitor and Value
| |
| 158 class ArgumentGraphVisitor : public ValueGraphVisitor { | |
| 159 public: | |
| 160 ArgumentGraphVisitor(FlowGraphBuilder* owner, intptr_t temp_index) | |
| 161 : ValueGraphVisitor(owner, temp_index) { } | |
| 162 | |
| 163 private: | |
| 164 // Override the returning of constants to ensure they are materialized. | |
| 165 virtual void ReturnValue(Value* value); | |
| 166 }; | |
| 167 | |
| 168 | |
| 151 // Translate an AstNode to a control-flow graph fragment for both its | 169 // Translate an AstNode to a control-flow graph fragment for both its |
| 152 // effects and true/false control flow (e.g., for an expression in a test | 170 // effects and true/false control flow (e.g., for an expression in a test |
| 153 // context). The resulting graph is always closed (even if it is empty) | 171 // context). The resulting graph is always closed (even if it is empty) |
| 154 // Successor control flow is explicitly set by a pair of pointers to | 172 // Successor control flow is explicitly set by a pair of pointers to |
| 155 // TargetEntryInstr*. | 173 // TargetEntryInstr*. |
| 156 // | 174 // |
| 157 // To distinguish between the graphs with only nonlocal exits and graphs | 175 // To distinguish between the graphs with only nonlocal exits and graphs |
| 158 // with both true and false exits, there are a pair of TargetEntryInstr**: | 176 // with both true and false exits, there are a pair of TargetEntryInstr**: |
| 159 // | 177 // |
| 160 // - Both NULL: only non-local exits, truly closed | 178 // - Both NULL: only non-local exits, truly closed |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 } | 227 } |
| 210 | 228 |
| 211 // Output parameters. | 229 // Output parameters. |
| 212 TargetEntryInstr** true_successor_address_; | 230 TargetEntryInstr** true_successor_address_; |
| 213 TargetEntryInstr** false_successor_address_; | 231 TargetEntryInstr** false_successor_address_; |
| 214 }; | 232 }; |
| 215 | 233 |
| 216 } // namespace dart | 234 } // namespace dart |
| 217 | 235 |
| 218 #endif // VM_FLOW_GRAPH_BUILDER_H_ | 236 #endif // VM_FLOW_GRAPH_BUILDER_H_ |
| OLD | NEW |