| 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), | |
| 23 preorder_block_entries_(), | |
| 24 postorder_block_entries_(), | |
| 25 context_level_(0) { } | |
| 26 | 22 |
| 27 void BuildGraph(); | 23 void BuildGraph(); |
| 28 | 24 |
| 29 const ParsedFunction& parsed_function() const { return parsed_function_; } | 25 const ParsedFunction& parsed_function() const { return parsed_function_; } |
| 30 | 26 |
| 31 const GrowableArray<BlockEntryInstr*>& postorder_block_entries() const { | 27 const GrowableArray<BlockEntryInstr*>& postorder_block_entries() const { |
| 32 return postorder_block_entries_; | 28 return postorder_block_entries_; |
| 33 } | 29 } |
| 34 | 30 |
| 35 void Bailout(const char* reason); | 31 void Bailout(const char* reason); |
| 36 | 32 |
| 37 void set_context_level(intptr_t value) { context_level_ = value; } | 33 void set_context_level(intptr_t value) { context_level_ = value; } |
| 38 intptr_t context_level() const { return context_level_; } | 34 intptr_t context_level() const { return context_level_; } |
| 39 | 35 |
| 36 // Each try in this function gets its own try index. |
| 37 intptr_t AllocateTryIndex() { return ++last_used_try_index_; } |
| 38 |
| 39 // Manage the currently active try index. |
| 40 void set_try_index(intptr_t value) { try_index_ = value; } |
| 41 intptr_t try_index() const { return try_index_; } |
| 42 |
| 43 void AddCatchEntry(intptr_t try_index, Instruction* entry); |
| 44 |
| 40 private: | 45 private: |
| 41 void ComputeDominators(GrowableArray<BlockEntryInstr*>* preorder, | 46 void ComputeDominators(GrowableArray<BlockEntryInstr*>* preorder, |
| 42 GrowableArray<intptr_t>* parent); | 47 GrowableArray<intptr_t>* parent); |
| 43 void CompressPath(intptr_t start_index, | 48 void CompressPath(intptr_t start_index, |
| 44 intptr_t current_index, | 49 intptr_t current_index, |
| 45 GrowableArray<intptr_t>* parent, | 50 GrowableArray<intptr_t>* parent, |
| 46 GrowableArray<intptr_t>* label); | 51 GrowableArray<intptr_t>* label); |
| 47 | 52 |
| 48 const ParsedFunction& parsed_function_; | 53 const ParsedFunction& parsed_function_; |
| 49 GrowableArray<BlockEntryInstr*> preorder_block_entries_; | 54 GrowableArray<BlockEntryInstr*> preorder_block_entries_; |
| 50 GrowableArray<BlockEntryInstr*> postorder_block_entries_; | 55 GrowableArray<BlockEntryInstr*> postorder_block_entries_; |
| 51 intptr_t context_level_; | 56 intptr_t context_level_; |
| 57 intptr_t last_used_try_index_; |
| 58 intptr_t try_index_; |
| 59 GrowableArray<Instruction*> catch_entries_; |
| 60 |
| 61 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder); |
| 52 }; | 62 }; |
| 53 | 63 |
| 54 | 64 |
| 55 class TestGraphVisitor; | 65 class TestGraphVisitor; |
| 56 | 66 |
| 57 // Translate an AstNode to a control-flow graph fragment for its effects | 67 // Translate an AstNode to a control-flow graph fragment for its effects |
| 58 // (e.g., a statement or an expression in an effect context). Implements a | 68 // (e.g., a statement or an expression in an effect context). Implements a |
| 59 // function from an AstNode and next temporary index to a graph fragment | 69 // function from an AstNode and next temporary index to a graph fragment |
| 60 // with a single entry and at most one exit. The fragment is represented by | 70 // with a single entry and at most one exit. The fragment is represented by |
| 61 // an (entry, exit) pair of Instruction pointers: | 71 // an (entry, exit) pair of Instruction pointers: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 166 |
| 157 virtual void CompiletimeStringInterpolation(const Function& interpol_func, | 167 virtual void CompiletimeStringInterpolation(const Function& interpol_func, |
| 158 const Array& literals); | 168 const Array& literals); |
| 159 | 169 |
| 160 TempVal* BuildObjectAllocation(ConstructorCallNode* node, | 170 TempVal* BuildObjectAllocation(ConstructorCallNode* node, |
| 161 int start_index); | 171 int start_index); |
| 162 void BuildConstructorCall(ConstructorCallNode* node, | 172 void BuildConstructorCall(ConstructorCallNode* node, |
| 163 int start_index, | 173 int start_index, |
| 164 Value* alloc_value); | 174 Value* alloc_value); |
| 165 | 175 |
| 176 void BuildStoreContext(const LocalVariable& variable, intptr_t start_index); |
| 177 void BuildLoadContext(const LocalVariable& variable, intptr_t start_index); |
| 178 |
| 166 void BuildThrowNode(ThrowNode* node); | 179 void BuildThrowNode(ThrowNode* node); |
| 167 | 180 |
| 168 private: | 181 private: |
| 169 // Specify a computation as the final result. Adds a Do instruction to | 182 // Specify a computation as the final result. Adds a Do instruction to |
| 170 // the graph, but normally overridden in subclasses. | 183 // the graph, but normally overridden in subclasses. |
| 171 virtual void ReturnComputation(Computation* computation) { | 184 virtual void ReturnComputation(Computation* computation) { |
| 172 AddInstruction(new DoInstr(computation)); | 185 AddInstruction(new DoInstr(computation)); |
| 173 } | 186 } |
| 174 | 187 |
| 175 // Shared global state. | 188 // Shared global state. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 305 } |
| 293 | 306 |
| 294 // Output parameters. | 307 // Output parameters. |
| 295 TargetEntryInstr** true_successor_address_; | 308 TargetEntryInstr** true_successor_address_; |
| 296 TargetEntryInstr** false_successor_address_; | 309 TargetEntryInstr** false_successor_address_; |
| 297 }; | 310 }; |
| 298 | 311 |
| 299 } // namespace dart | 312 } // namespace dart |
| 300 | 313 |
| 301 #endif // VM_FLOW_GRAPH_BUILDER_H_ | 314 #endif // VM_FLOW_GRAPH_BUILDER_H_ |
| OLD | NEW |