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 #include "src/compiler/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/compiler/control-builders.h" | 8 #include "src/compiler/control-builders.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 breakable_(NULL), | 26 breakable_(NULL), |
27 execution_context_(NULL) { | 27 execution_context_(NULL) { |
28 InitializeAstVisitor(info->zone()); | 28 InitializeAstVisitor(info->zone()); |
29 } | 29 } |
30 | 30 |
31 | 31 |
32 Node* AstGraphBuilder::GetFunctionClosure() { | 32 Node* AstGraphBuilder::GetFunctionClosure() { |
33 if (!function_closure_.is_set()) { | 33 if (!function_closure_.is_set()) { |
34 // Parameter -1 is special for the function closure | 34 // Parameter -1 is special for the function closure |
35 Operator* op = common()->Parameter(-1); | 35 Operator* op = common()->Parameter(-1); |
36 Node* node = NewNode(op); | 36 Node* node = NewNode(op, graph()->start()); |
37 function_closure_.set(node); | 37 function_closure_.set(node); |
38 } | 38 } |
39 return function_closure_.get(); | 39 return function_closure_.get(); |
40 } | 40 } |
41 | 41 |
42 | 42 |
43 Node* AstGraphBuilder::GetFunctionContext() { | 43 Node* AstGraphBuilder::GetFunctionContext() { |
44 if (!function_context_.is_set()) { | 44 if (!function_context_.is_set()) { |
45 // Parameter (arity + 1) is special for the outer context of the function | 45 // Parameter (arity + 1) is special for the outer context of the function |
46 Operator* op = common()->Parameter(info()->num_parameters() + 1); | 46 Operator* op = common()->Parameter(info()->num_parameters() + 1); |
47 Node* node = NewNode(op); | 47 Node* node = NewNode(op, graph()->start()); |
48 function_context_.set(node); | 48 function_context_.set(node); |
49 } | 49 } |
50 return function_context_.get(); | 50 return function_context_.get(); |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 bool AstGraphBuilder::CreateGraph() { | 54 bool AstGraphBuilder::CreateGraph() { |
55 Scope* scope = info()->scope(); | 55 Scope* scope = info()->scope(); |
56 DCHECK(graph() != NULL); | 56 DCHECK(graph() != NULL); |
57 | 57 |
58 SourcePositionTable::Scope start_pos( | 58 SourcePositionTable::Scope start_pos( |
59 source_positions(), | 59 source_positions(), |
60 SourcePosition(info()->shared_info()->start_position())); | 60 SourcePosition(info()->shared_info()->start_position())); |
61 | 61 |
62 // Set up the basic structure of the graph. | 62 // Set up the basic structure of the graph. |
63 graph()->SetStart(graph()->NewNode(common()->Start())); | 63 graph()->SetStart( |
| 64 graph()->NewNode(common()->Start(info()->num_parameters()))); |
64 | 65 |
65 // Initialize the top-level environment. | 66 // Initialize the top-level environment. |
66 Environment env(this, scope, graph()->start()); | 67 Environment env(this, scope, graph()->start()); |
67 set_environment(&env); | 68 set_environment(&env); |
68 | 69 |
69 // Build node to initialize local function context. | 70 // Build node to initialize local function context. |
70 Node* closure = GetFunctionClosure(); | 71 Node* closure = GetFunctionClosure(); |
71 Node* outer = GetFunctionContext(); | 72 Node* outer = GetFunctionContext(); |
72 Node* inner = BuildLocalFunctionContext(outer, closure); | 73 Node* inner = BuildLocalFunctionContext(outer, closure); |
73 | 74 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 locals_count_(scope->num_stack_slots()), | 171 locals_count_(scope->num_stack_slots()), |
171 parameters_node_(NULL), | 172 parameters_node_(NULL), |
172 locals_node_(NULL), | 173 locals_node_(NULL), |
173 stack_node_(NULL), | 174 stack_node_(NULL), |
174 parameters_dirty_(false), | 175 parameters_dirty_(false), |
175 locals_dirty_(false), | 176 locals_dirty_(false), |
176 stack_dirty_(false) { | 177 stack_dirty_(false) { |
177 DCHECK_EQ(scope->num_parameters() + 1, parameters_count()); | 178 DCHECK_EQ(scope->num_parameters() + 1, parameters_count()); |
178 | 179 |
179 // Bind the receiver variable. | 180 // Bind the receiver variable. |
180 Node* receiver = builder->graph()->NewNode(common()->Parameter(0)); | 181 Node* receiver = builder->graph()->NewNode(common()->Parameter(0), |
| 182 builder->graph()->start()); |
181 values()->push_back(receiver); | 183 values()->push_back(receiver); |
182 | 184 |
183 // Bind all parameter variables. The parameter indices are shifted by 1 | 185 // Bind all parameter variables. The parameter indices are shifted by 1 |
184 // (receiver is parameter index -1 but environment index 0). | 186 // (receiver is parameter index -1 but environment index 0). |
185 for (int i = 0; i < scope->num_parameters(); ++i) { | 187 for (int i = 0; i < scope->num_parameters(); ++i) { |
186 Node* parameter = builder->graph()->NewNode(common()->Parameter(i + 1)); | 188 Node* parameter = builder->graph()->NewNode(common()->Parameter(i + 1), |
| 189 builder->graph()->start()); |
187 values()->push_back(parameter); | 190 values()->push_back(parameter); |
188 } | 191 } |
189 | 192 |
190 // Bind all local variables to undefined. | 193 // Bind all local variables to undefined. |
191 Node* undefined_constant = builder->jsgraph()->UndefinedConstant(); | 194 Node* undefined_constant = builder->jsgraph()->UndefinedConstant(); |
192 values()->insert(values()->end(), locals_count(), undefined_constant); | 195 values()->insert(values()->end(), locals_count(), undefined_constant); |
193 } | 196 } |
194 | 197 |
195 | 198 |
196 AstGraphBuilder::Environment::Environment(const Environment& copy) | 199 AstGraphBuilder::Environment::Environment(const Environment& copy) |
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 Node* local_context = NewNode(op, closure); | 1614 Node* local_context = NewNode(op, closure); |
1612 set_current_context(local_context); | 1615 set_current_context(local_context); |
1613 | 1616 |
1614 // Copy parameters into context if necessary. | 1617 // Copy parameters into context if necessary. |
1615 int num_parameters = info()->scope()->num_parameters(); | 1618 int num_parameters = info()->scope()->num_parameters(); |
1616 for (int i = 0; i < num_parameters; i++) { | 1619 for (int i = 0; i < num_parameters; i++) { |
1617 Variable* variable = info()->scope()->parameter(i); | 1620 Variable* variable = info()->scope()->parameter(i); |
1618 if (!variable->IsContextSlot()) continue; | 1621 if (!variable->IsContextSlot()) continue; |
1619 // Temporary parameter node. The parameter indices are shifted by 1 | 1622 // Temporary parameter node. The parameter indices are shifted by 1 |
1620 // (receiver is parameter index -1 but environment index 0). | 1623 // (receiver is parameter index -1 but environment index 0). |
1621 Node* parameter = NewNode(common()->Parameter(i + 1)); | 1624 Node* parameter = NewNode(common()->Parameter(i + 1), graph()->start()); |
1622 // Context variable (at bottom of the context chain). | 1625 // Context variable (at bottom of the context chain). |
1623 DCHECK_EQ(0, info()->scope()->ContextChainLength(variable->scope())); | 1626 DCHECK_EQ(0, info()->scope()->ContextChainLength(variable->scope())); |
1624 Operator* op = javascript()->StoreContext(0, variable->index()); | 1627 Operator* op = javascript()->StoreContext(0, variable->index()); |
1625 NewNode(op, local_context, parameter); | 1628 NewNode(op, local_context, parameter); |
1626 } | 1629 } |
1627 | 1630 |
1628 return local_context; | 1631 return local_context; |
1629 } | 1632 } |
1630 | 1633 |
1631 | 1634 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 | 1980 |
1978 // Continue with the original environment. | 1981 // Continue with the original environment. |
1979 set_environment(continuation_env); | 1982 set_environment(continuation_env); |
1980 | 1983 |
1981 NewNode(common()->Continuation()); | 1984 NewNode(common()->Continuation()); |
1982 } | 1985 } |
1983 } | 1986 } |
1984 } | 1987 } |
1985 } | 1988 } |
1986 } // namespace v8::internal::compiler | 1989 } // namespace v8::internal::compiler |
OLD | NEW |