| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_AST_GRAPH_BUILDER_H_ | 5 #ifndef V8_COMPILER_AST_GRAPH_BUILDER_H_ |
| 6 #define V8_COMPILER_AST_GRAPH_BUILDER_H_ | 6 #define V8_COMPILER_AST_GRAPH_BUILDER_H_ |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/ast.h" | 10 #include "src/ast.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // Get the node that represents the outer function context. | 56 // Get the node that represents the outer function context. |
| 57 Node* GetFunctionContext(); | 57 Node* GetFunctionContext(); |
| 58 // Get the node that represents the outer function closure. | 58 // Get the node that represents the outer function closure. |
| 59 Node* GetFunctionClosure(); | 59 Node* GetFunctionClosure(); |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 class AstContext; | 62 class AstContext; |
| 63 class AstEffectContext; | 63 class AstEffectContext; |
| 64 class AstValueContext; | 64 class AstValueContext; |
| 65 class AstTestContext; | 65 class AstTestContext; |
| 66 class BreakableScope; | |
| 67 class ContextScope; | 66 class ContextScope; |
| 67 class ControlScope; |
| 68 class ControlScopeForBreakable; |
| 69 class ControlScopeForIteration; |
| 70 class ControlScopeForCatch; |
| 71 class ControlScopeForFinally; |
| 68 class Environment; | 72 class Environment; |
| 69 friend class ControlBuilder; | 73 friend class ControlBuilder; |
| 70 | 74 |
| 71 Zone* local_zone_; | 75 Zone* local_zone_; |
| 72 CompilationInfo* info_; | 76 CompilationInfo* info_; |
| 73 JSGraph* jsgraph_; | 77 JSGraph* jsgraph_; |
| 74 Environment* environment_; | 78 Environment* environment_; |
| 75 AstContext* ast_context_; | 79 AstContext* ast_context_; |
| 76 | 80 |
| 77 // List of global declarations for functions and variables. | 81 // List of global declarations for functions and variables. |
| 78 ZoneVector<Handle<Object>> globals_; | 82 ZoneVector<Handle<Object>> globals_; |
| 79 | 83 |
| 80 // Stack of breakable statements entered by the visitor. | 84 // Stack of control scopes currently entered by the visitor. |
| 81 BreakableScope* breakable_; | 85 ControlScope* execution_control_; |
| 82 | 86 |
| 83 // Stack of context objects pushed onto the chain by the visitor. | 87 // Stack of context objects pushed onto the chain by the visitor. |
| 84 ContextScope* execution_context_; | 88 ContextScope* execution_context_; |
| 85 | 89 |
| 86 // Nodes representing values in the activation record. | 90 // Nodes representing values in the activation record. |
| 87 SetOncePointer<Node> function_closure_; | 91 SetOncePointer<Node> function_closure_; |
| 88 SetOncePointer<Node> function_context_; | 92 SetOncePointer<Node> function_context_; |
| 89 | 93 |
| 90 // Temporary storage for building node input lists. | 94 // Temporary storage for building node input lists. |
| 91 int input_buffer_size_; | 95 int input_buffer_size_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 103 // Result of loop assignment analysis performed before graph creation. | 107 // Result of loop assignment analysis performed before graph creation. |
| 104 LoopAssignmentAnalysis* loop_assignment_analysis_; | 108 LoopAssignmentAnalysis* loop_assignment_analysis_; |
| 105 | 109 |
| 106 // Growth increment for the temporary buffer used to construct input lists to | 110 // Growth increment for the temporary buffer used to construct input lists to |
| 107 // new nodes. | 111 // new nodes. |
| 108 static const int kInputBufferSizeIncrement = 64; | 112 static const int kInputBufferSizeIncrement = 64; |
| 109 | 113 |
| 110 Zone* local_zone() const { return local_zone_; } | 114 Zone* local_zone() const { return local_zone_; } |
| 111 Environment* environment() { return environment_; } | 115 Environment* environment() { return environment_; } |
| 112 AstContext* ast_context() const { return ast_context_; } | 116 AstContext* ast_context() const { return ast_context_; } |
| 113 BreakableScope* breakable() const { return breakable_; } | 117 ControlScope* execution_control() const { return execution_control_; } |
| 114 ContextScope* execution_context() const { return execution_context_; } | 118 ContextScope* execution_context() const { return execution_context_; } |
| 115 CommonOperatorBuilder* common() const { return jsgraph_->common(); } | 119 CommonOperatorBuilder* common() const { return jsgraph_->common(); } |
| 116 CompilationInfo* info() const { return info_; } | 120 CompilationInfo* info() const { return info_; } |
| 117 StrictMode strict_mode() const; | 121 StrictMode strict_mode() const; |
| 118 JSGraph* jsgraph() { return jsgraph_; } | 122 JSGraph* jsgraph() { return jsgraph_; } |
| 119 Graph* graph() { return jsgraph_->graph(); } | 123 Graph* graph() { return jsgraph_->graph(); } |
| 120 Zone* graph_zone() { return graph()->zone(); } | 124 Zone* graph_zone() { return graph()->zone(); } |
| 121 JSOperatorBuilder* javascript() { return jsgraph_->javascript(); } | 125 JSOperatorBuilder* javascript() { return jsgraph_->javascript(); } |
| 122 ZoneVector<Handle<Object>>* globals() { return &globals_; } | 126 ZoneVector<Handle<Object>>* globals() { return &globals_; } |
| 123 inline Scope* current_scope() const; | 127 inline Scope* current_scope() const; |
| 124 Node* current_context() const { return current_context_; } | 128 Node* current_context() const { return current_context_; } |
| 125 Node* dead_control(); | 129 Node* dead_control(); |
| 126 Node* exit_control() const { return exit_control_; } | 130 Node* exit_control() const { return exit_control_; } |
| 127 | 131 |
| 128 void set_ast_context(AstContext* ctx) { ast_context_ = ctx; } | 132 void set_ast_context(AstContext* ctx) { ast_context_ = ctx; } |
| 129 void set_breakable(BreakableScope* brk) { breakable_ = brk; } | 133 void set_execution_control(ControlScope* ctrl) { execution_control_ = ctrl; } |
| 130 void set_execution_context(ContextScope* ctx) { execution_context_ = ctx; } | 134 void set_execution_context(ContextScope* ctx) { execution_context_ = ctx; } |
| 131 void set_exit_control(Node* exit) { exit_control_ = exit; } | 135 void set_exit_control(Node* exit) { exit_control_ = exit; } |
| 132 void set_current_context(Node* ctx) { current_context_ = ctx; } | 136 void set_current_context(Node* ctx) { current_context_ = ctx; } |
| 133 void set_environment(Environment* env) { environment_ = env; } | 137 void set_environment(Environment* env) { environment_ = env; } |
| 134 | 138 |
| 135 // Node creation helpers. | 139 // Node creation helpers. |
| 136 Node* NewNode(const Operator* op, bool incomplete = false) { | 140 Node* NewNode(const Operator* op, bool incomplete = false) { |
| 137 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); | 141 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); |
| 138 } | 142 } |
| 139 | 143 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 234 |
| 231 // Builders for error reporting at runtime. | 235 // Builders for error reporting at runtime. |
| 232 Node* BuildThrowReferenceError(Variable* var, BailoutId bailout_id); | 236 Node* BuildThrowReferenceError(Variable* var, BailoutId bailout_id); |
| 233 Node* BuildThrowConstAssignError(BailoutId bailout_id); | 237 Node* BuildThrowConstAssignError(BailoutId bailout_id); |
| 234 | 238 |
| 235 // Builders for dynamic hole-checks at runtime. | 239 // Builders for dynamic hole-checks at runtime. |
| 236 Node* BuildHoleCheckSilent(Node* value, Node* for_hole, Node* not_hole); | 240 Node* BuildHoleCheckSilent(Node* value, Node* for_hole, Node* not_hole); |
| 237 Node* BuildHoleCheckThrow(Node* value, Variable* var, Node* not_hole, | 241 Node* BuildHoleCheckThrow(Node* value, Variable* var, Node* not_hole, |
| 238 BailoutId bailout_id); | 242 BailoutId bailout_id); |
| 239 | 243 |
| 244 // Builders for non-local control flow. |
| 245 Node* BuildReturn(Node* return_value); |
| 246 Node* BuildThrow(Node* exception_value); |
| 247 |
| 240 // Builders for binary operations. | 248 // Builders for binary operations. |
| 241 Node* BuildBinaryOp(Node* left, Node* right, Token::Value op); | 249 Node* BuildBinaryOp(Node* left, Node* right, Token::Value op); |
| 242 | 250 |
| 243 // Builder for stack-check guards. | 251 // Builder for stack-check guards. |
| 244 Node* BuildStackCheck(); | 252 Node* BuildStackCheck(); |
| 245 | 253 |
| 246 // Check if the given statement is an OSR entry. | 254 // Check if the given statement is an OSR entry. |
| 247 // If so, record the stack height into the compilation and return {true}. | 255 // If so, record the stack height into the compilation and return {true}. |
| 248 bool CheckOsrEntry(IterationStatement* stmt); | 256 bool CheckOsrEntry(IterationStatement* stmt); |
| 249 | 257 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 class AstGraphBuilder::AstTestContext FINAL : public AstContext { | 530 class AstGraphBuilder::AstTestContext FINAL : public AstContext { |
| 523 public: | 531 public: |
| 524 explicit AstTestContext(AstGraphBuilder* owner) | 532 explicit AstTestContext(AstGraphBuilder* owner) |
| 525 : AstContext(owner, Expression::kTest) {} | 533 : AstContext(owner, Expression::kTest) {} |
| 526 ~AstTestContext() FINAL; | 534 ~AstTestContext() FINAL; |
| 527 void ProduceValue(Node* value) FINAL; | 535 void ProduceValue(Node* value) FINAL; |
| 528 Node* ConsumeValue() FINAL; | 536 Node* ConsumeValue() FINAL; |
| 529 }; | 537 }; |
| 530 | 538 |
| 531 | 539 |
| 532 // Scoped class tracking breakable statements entered by the visitor. Allows to | |
| 533 // properly 'break' and 'continue' iteration statements as well as to 'break' | |
| 534 // from blocks within switch statements. | |
| 535 class AstGraphBuilder::BreakableScope BASE_EMBEDDED { | |
| 536 public: | |
| 537 BreakableScope(AstGraphBuilder* owner, BreakableStatement* target, | |
| 538 ControlBuilder* control, int drop_extra) | |
| 539 : owner_(owner), | |
| 540 target_(target), | |
| 541 next_(owner->breakable()), | |
| 542 control_(control), | |
| 543 drop_extra_(drop_extra) { | |
| 544 owner_->set_breakable(this); // Push. | |
| 545 } | |
| 546 | |
| 547 ~BreakableScope() { | |
| 548 owner_->set_breakable(next_); // Pop. | |
| 549 } | |
| 550 | |
| 551 // Either 'break' or 'continue' the target statement. | |
| 552 void BreakTarget(BreakableStatement* target); | |
| 553 void ContinueTarget(BreakableStatement* target); | |
| 554 | |
| 555 private: | |
| 556 AstGraphBuilder* owner_; | |
| 557 BreakableStatement* target_; | |
| 558 BreakableScope* next_; | |
| 559 ControlBuilder* control_; | |
| 560 int drop_extra_; | |
| 561 | |
| 562 // Find the correct scope for the target statement. Note that this also drops | |
| 563 // extra operands from the environment for each scope skipped along the way. | |
| 564 BreakableScope* FindBreakable(BreakableStatement* target); | |
| 565 }; | |
| 566 | |
| 567 | |
| 568 // Scoped class tracking context objects created by the visitor. Represents | 540 // Scoped class tracking context objects created by the visitor. Represents |
| 569 // mutations of the context chain within the function body and allows to | 541 // mutations of the context chain within the function body and allows to |
| 570 // change the current {scope} and {context} during visitation. | 542 // change the current {scope} and {context} during visitation. |
| 571 class AstGraphBuilder::ContextScope BASE_EMBEDDED { | 543 class AstGraphBuilder::ContextScope BASE_EMBEDDED { |
| 572 public: | 544 public: |
| 573 ContextScope(AstGraphBuilder* owner, Scope* scope, Node* context) | 545 ContextScope(AstGraphBuilder* owner, Scope* scope, Node* context) |
| 574 : owner_(owner), | 546 : owner_(owner), |
| 575 next_(owner->execution_context()), | 547 next_(owner->execution_context()), |
| 576 outer_(owner->current_context()), | 548 outer_(owner->current_context()), |
| 577 scope_(scope) { | 549 scope_(scope) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 596 | 568 |
| 597 Scope* AstGraphBuilder::current_scope() const { | 569 Scope* AstGraphBuilder::current_scope() const { |
| 598 return execution_context_->scope(); | 570 return execution_context_->scope(); |
| 599 } | 571 } |
| 600 | 572 |
| 601 } // namespace compiler | 573 } // namespace compiler |
| 602 } // namespace internal | 574 } // namespace internal |
| 603 } // namespace v8 | 575 } // namespace v8 |
| 604 | 576 |
| 605 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ | 577 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ |
| OLD | NEW |