| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 157 |
| 158 // Perform a type check on the given value. | 158 // Perform a type check on the given value. |
| 159 void BuildAssertAssignable(intptr_t node_id, | 159 void BuildAssertAssignable(intptr_t node_id, |
| 160 intptr_t token_index, | 160 intptr_t token_index, |
| 161 Value* value, | 161 Value* value, |
| 162 const AbstractType& dst_type, | 162 const AbstractType& dst_type, |
| 163 const String& dst_name, | 163 const String& dst_name, |
| 164 intptr_t start_index); | 164 intptr_t start_index); |
| 165 | 165 |
| 166 // Perform a type check on the given value and return it. | 166 // Perform a type check on the given value and return it. |
| 167 Value* BuildAssignableValue(intptr_t node_id, | 167 Value* BuildAssignableValue(intptr_t assignment_node_id, |
| 168 intptr_t token_index, | 168 AstNode* value_node, |
| 169 Value* value, | 169 Value* value, |
| 170 const AbstractType& dst_type, | 170 const AbstractType& dst_type, |
| 171 const String& dst_name, | 171 const String& dst_name, |
| 172 intptr_t start_index); | 172 intptr_t start_index); |
| 173 | 173 |
| 174 virtual void BuildInstanceOf(ComparisonNode* node); | 174 virtual void BuildInstanceOf(ComparisonNode* node); |
| 175 | 175 |
| 176 bool MustSaveRestoreContext(SequenceNode* node) const; | 176 bool MustSaveRestoreContext(SequenceNode* node) const; |
| 177 | 177 |
| 178 // Moves parent context into the context register. | 178 // Moves parent context into the context register. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 virtual void VisitThrowNode(ThrowNode* node); | 235 virtual void VisitThrowNode(ThrowNode* node); |
| 236 | 236 |
| 237 Value* value() const { return value_; } | 237 Value* value() const { return value_; } |
| 238 | 238 |
| 239 protected: | 239 protected: |
| 240 // Output parameters. | 240 // Output parameters. |
| 241 Value* value_; | 241 Value* value_; |
| 242 | 242 |
| 243 private: | 243 private: |
| 244 // Helper to set the output state to return a Value. | 244 // Helper to set the output state to return a Value. |
| 245 virtual void ReturnValue(Value* value) { value_ = value; } | 245 virtual void ReturnValue(Value* value) { |
| 246 ASSERT(value->IsUse() || value->IsTemp()); |
| 247 value_ = value; |
| 248 } |
| 246 | 249 |
| 247 // Specify a computation as the final result. Adds a Bind instruction to | 250 // Specify a computation as the final result. Adds a Bind instruction to |
| 248 // the graph and returns its temporary value (i.e., set the output | 251 // the graph and returns its temporary value (i.e., set the output |
| 249 // parameters). | 252 // parameters). |
| 250 virtual void ReturnComputation(Computation* computation) { | 253 virtual void ReturnComputation(Computation* computation) { |
| 251 BindInstr* defn = new BindInstr(temp_index(), computation); | 254 BindInstr* defn = new BindInstr(temp_index(), computation); |
| 252 AddInstruction(defn); | 255 AddInstruction(defn); |
| 253 AllocateTempIndex(); | 256 AllocateTempIndex(); |
| 254 value_ = new UseVal(defn); | 257 value_ = new UseVal(defn); |
| 255 } | 258 } |
| 256 | 259 |
| 257 virtual void CompiletimeStringInterpolation(const Function& interpol_func, | 260 virtual void CompiletimeStringInterpolation(const Function& interpol_func, |
| 258 const Array& literals); | 261 const Array& literals); |
| 259 | 262 |
| 260 virtual void BuildInstanceOf(ComparisonNode* node); | 263 virtual void BuildInstanceOf(ComparisonNode* node); |
| 261 }; | 264 }; |
| 262 | 265 |
| 263 | 266 |
| 264 // Translate an AstNode to a control-flow graph fragment for both its effects | |
| 265 // and value as an outgoing argument. Implements a function from an AstNode | |
| 266 // and next temporary index to a graph fragment (as in the | |
| 267 // EffectGraphBuilder), an updated temporary index, and an intermediate | |
| 268 // language Value. | |
| 269 class ArgumentGraphVisitor : public ValueGraphVisitor { | |
| 270 public: | |
| 271 ArgumentGraphVisitor(FlowGraphBuilder* owner, intptr_t temp_index) | |
| 272 : ValueGraphVisitor(owner, temp_index) { } | |
| 273 | |
| 274 private: | |
| 275 // Override the returning of constants to ensure they are materialized. | |
| 276 virtual void ReturnValue(Value* value); | |
| 277 }; | |
| 278 | |
| 279 | |
| 280 // Translate an AstNode to a control-flow graph fragment for both its | 267 // Translate an AstNode to a control-flow graph fragment for both its |
| 281 // effects and true/false control flow (e.g., for an expression in a test | 268 // effects and true/false control flow (e.g., for an expression in a test |
| 282 // context). The resulting graph is always closed (even if it is empty) | 269 // context). The resulting graph is always closed (even if it is empty) |
| 283 // Successor control flow is explicitly set by a pair of pointers to | 270 // Successor control flow is explicitly set by a pair of pointers to |
| 284 // TargetEntryInstr*. | 271 // TargetEntryInstr*. |
| 285 // | 272 // |
| 286 // To distinguish between the graphs with only nonlocal exits and graphs | 273 // To distinguish between the graphs with only nonlocal exits and graphs |
| 287 // with both true and false exits, there are a pair of TargetEntryInstr**: | 274 // with both true and false exits, there are a pair of TargetEntryInstr**: |
| 288 // | 275 // |
| 289 // - Both NULL: only non-local exits, truly closed | 276 // - Both NULL: only non-local exits, truly closed |
| (...skipping 10 matching lines...) Expand all Loading... |
| 300 intptr_t temp_index, | 287 intptr_t temp_index, |
| 301 intptr_t condition_node_id, | 288 intptr_t condition_node_id, |
| 302 intptr_t condition_token_index) | 289 intptr_t condition_token_index) |
| 303 : ValueGraphVisitor(owner, temp_index), | 290 : ValueGraphVisitor(owner, temp_index), |
| 304 true_successor_address_(NULL), | 291 true_successor_address_(NULL), |
| 305 false_successor_address_(NULL), | 292 false_successor_address_(NULL), |
| 306 condition_node_id_(condition_node_id), | 293 condition_node_id_(condition_node_id), |
| 307 condition_token_index_(condition_token_index) { | 294 condition_token_index_(condition_token_index) { |
| 308 } | 295 } |
| 309 | 296 |
| 310 // Visit functions overridden by this class. | |
| 311 virtual void VisitLiteralNode(LiteralNode* node); | |
| 312 virtual void VisitLoadLocalNode(LoadLocalNode* node); | |
| 313 | |
| 314 TargetEntryInstr** true_successor_address() const { | 297 TargetEntryInstr** true_successor_address() const { |
| 315 ASSERT(true_successor_address_ != NULL); | 298 ASSERT(true_successor_address_ != NULL); |
| 316 return true_successor_address_; | 299 return true_successor_address_; |
| 317 } | 300 } |
| 318 TargetEntryInstr** false_successor_address() const { | 301 TargetEntryInstr** false_successor_address() const { |
| 319 ASSERT(false_successor_address_ != NULL); | 302 ASSERT(false_successor_address_ != NULL); |
| 320 return false_successor_address_; | 303 return false_successor_address_; |
| 321 } | 304 } |
| 322 | 305 |
| 323 intptr_t condition_node_id() const { return condition_node_id_; } | 306 intptr_t condition_node_id() const { return condition_node_id_; } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 340 TargetEntryInstr** true_successor_address_; | 323 TargetEntryInstr** true_successor_address_; |
| 341 TargetEntryInstr** false_successor_address_; | 324 TargetEntryInstr** false_successor_address_; |
| 342 | 325 |
| 343 intptr_t condition_node_id_; | 326 intptr_t condition_node_id_; |
| 344 intptr_t condition_token_index_; | 327 intptr_t condition_token_index_; |
| 345 }; | 328 }; |
| 346 | 329 |
| 347 } // namespace dart | 330 } // namespace dart |
| 348 | 331 |
| 349 #endif // VM_FLOW_GRAPH_BUILDER_H_ | 332 #endif // VM_FLOW_GRAPH_BUILDER_H_ |
| OLD | NEW |