| 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" |
| 11 #include "vm/intermediate_language.h" | 11 #include "vm/intermediate_language.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 class Instruction; | 15 class Instruction; |
| 16 class ParsedFunction; | 16 class ParsedFunction; |
| 17 | 17 |
| 18 // Build a flow graph from a parsed function's AST. | 18 // Build a flow graph from a parsed function's AST. |
| 19 class FlowGraphBuilder: public ValueObject { | 19 class FlowGraphBuilder: public ValueObject { |
| 20 public: | 20 public: |
| 21 explicit FlowGraphBuilder(const ParsedFunction& parsed_function) | 21 explicit FlowGraphBuilder(const ParsedFunction& parsed_function) |
| 22 : parsed_function_(parsed_function), | 22 : parsed_function_(parsed_function), |
| 23 bailout_reason_(NULL), | |
| 24 postorder_block_entries_() { } | 23 postorder_block_entries_() { } |
| 25 | 24 |
| 26 void BuildGraph(); | 25 void BuildGraph(); |
| 27 | 26 |
| 28 const ParsedFunction& parsed_function() const { return parsed_function_; } | 27 const ParsedFunction& parsed_function() const { return parsed_function_; } |
| 29 | 28 |
| 30 bool HasBailedOut() const { return bailout_reason_ != NULL; } | 29 void Bailout(const char* reason); |
| 31 void Bailout(const char* reason) { | |
| 32 // Cannot give a NULL reason because we use it to detect bailout. | |
| 33 ASSERT(!HasBailedOut() && (reason != NULL)); | |
| 34 bailout_reason_ = reason; | |
| 35 } | |
| 36 void TraceBailout() const; | |
| 37 void PrintGraph() const; | 30 void PrintGraph() const; |
| 38 | 31 |
| 39 private: | 32 private: |
| 40 const ParsedFunction& parsed_function_; | 33 const ParsedFunction& parsed_function_; |
| 41 const char* bailout_reason_; | |
| 42 GrowableArray<Instruction*> postorder_block_entries_; | 34 GrowableArray<Instruction*> postorder_block_entries_; |
| 43 }; | 35 }; |
| 44 | 36 |
| 45 | 37 |
| 46 #define DEFINE_VISIT(type, name) virtual void Visit##type(type* node); | 38 #define DEFINE_VISIT(type, name) virtual void Visit##type(type* node); |
| 47 | 39 |
| 48 class TestGraphVisitor; | 40 class TestGraphVisitor; |
| 49 | 41 |
| 50 // Translate an AstNode to a control-flow graph fragment for its effects | 42 // Translate an AstNode to a control-flow graph fragment for its effects |
| 51 // (e.g., a statement or an expression in an effect context). Implements a | 43 // (e.g., a statement or an expression in an effect context). Implements a |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // Append a 'while loop' test and back edge to this graph, depending on | 82 // Append a 'while loop' test and back edge to this graph, depending on |
| 91 // which parts are reachable. Afterward, the graph exit is the false | 83 // which parts are reachable. Afterward, the graph exit is the false |
| 92 // successor of the loop condition. | 84 // successor of the loop condition. |
| 93 void TieLoop(const TestGraphVisitor& test_fragment, | 85 void TieLoop(const TestGraphVisitor& test_fragment, |
| 94 const EffectGraphVisitor& body_fragment); | 86 const EffectGraphVisitor& body_fragment); |
| 95 | 87 |
| 96 protected: | 88 protected: |
| 97 // Implement the core part of the translation of expression node types. | 89 // Implement the core part of the translation of expression node types. |
| 98 AssertAssignableComp* TranslateAssignable(const AssignableNode& node); | 90 AssertAssignableComp* TranslateAssignable(const AssignableNode& node); |
| 99 InstanceCallComp* TranslateBinaryOp(const BinaryOpNode& node); | 91 InstanceCallComp* TranslateBinaryOp(const BinaryOpNode& node); |
| 92 InstanceCallComp* TranslateUnaryOp(const UnaryOpNode& node); |
| 100 InstanceCallComp* TranslateComparison(const ComparisonNode& node); | 93 InstanceCallComp* TranslateComparison(const ComparisonNode& node); |
| 101 StoreLocalComp* TranslateStoreLocal(const StoreLocalNode& node); | 94 StoreLocalComp* TranslateStoreLocal(const StoreLocalNode& node); |
| 102 StaticCallComp* TranslateStaticCall(const StaticCallNode& node); | 95 StaticCallComp* TranslateStaticCall(const StaticCallNode& node); |
| 103 | 96 |
| 104 void CloseFragment() { exit_ = NULL; } | 97 void CloseFragment() { exit_ = NULL; } |
| 105 intptr_t AllocateTempIndex() { return temp_index_++; } | 98 intptr_t AllocateTempIndex() { return temp_index_++; } |
| 106 | 99 |
| 107 private: | 100 private: |
| 108 // Helper to append a Do instruction to the graph. | 101 // Helper to append a Do instruction to the graph. |
| 109 void DoComputation(Computation* computation) { | 102 void DoComputation(Computation* computation) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 TargetEntryInstr** true_successor_address_; | 206 TargetEntryInstr** true_successor_address_; |
| 214 TargetEntryInstr** false_successor_address_; | 207 TargetEntryInstr** false_successor_address_; |
| 215 }; | 208 }; |
| 216 | 209 |
| 217 #undef DEFINE_VISIT | 210 #undef DEFINE_VISIT |
| 218 | 211 |
| 219 | 212 |
| 220 } // namespace dart | 213 } // namespace dart |
| 221 | 214 |
| 222 #endif // VM_FLOW_GRAPH_BUILDER_H_ | 215 #endif // VM_FLOW_GRAPH_BUILDER_H_ |
| OLD | NEW |