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/ast-loop-assignment-analyzer.h" | 8 #include "src/compiler/ast-loop-assignment-analyzer.h" |
9 #include "src/compiler/control-builders.h" | 9 #include "src/compiler/control-builders.h" |
10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 388 |
389 void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { | 389 void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { |
390 Variable* variable = decl->proxy()->var(); | 390 Variable* variable = decl->proxy()->var(); |
391 VariableMode mode = decl->mode(); | 391 VariableMode mode = decl->mode(); |
392 bool hole_init = mode == CONST || mode == CONST_LEGACY || mode == LET; | 392 bool hole_init = mode == CONST || mode == CONST_LEGACY || mode == LET; |
393 switch (variable->location()) { | 393 switch (variable->location()) { |
394 case Variable::UNALLOCATED: { | 394 case Variable::UNALLOCATED: { |
395 Handle<Oddball> value = variable->binding_needs_init() | 395 Handle<Oddball> value = variable->binding_needs_init() |
396 ? isolate()->factory()->the_hole_value() | 396 ? isolate()->factory()->the_hole_value() |
397 : isolate()->factory()->undefined_value(); | 397 : isolate()->factory()->undefined_value(); |
398 globals()->Add(variable->name(), zone()); | 398 globals()->push_back(variable->name()); |
399 globals()->Add(value, zone()); | 399 globals()->push_back(value); |
400 break; | 400 break; |
401 } | 401 } |
402 case Variable::PARAMETER: | 402 case Variable::PARAMETER: |
403 case Variable::LOCAL: | 403 case Variable::LOCAL: |
404 if (hole_init) { | 404 if (hole_init) { |
405 Node* value = jsgraph()->TheHoleConstant(); | 405 Node* value = jsgraph()->TheHoleConstant(); |
406 environment()->Bind(variable, value); | 406 environment()->Bind(variable, value); |
407 } | 407 } |
408 break; | 408 break; |
409 case Variable::CONTEXT: | 409 case Variable::CONTEXT: |
(...skipping 10 matching lines...) Expand all Loading... |
420 | 420 |
421 | 421 |
422 void AstGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { | 422 void AstGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { |
423 Variable* variable = decl->proxy()->var(); | 423 Variable* variable = decl->proxy()->var(); |
424 switch (variable->location()) { | 424 switch (variable->location()) { |
425 case Variable::UNALLOCATED: { | 425 case Variable::UNALLOCATED: { |
426 Handle<SharedFunctionInfo> function = | 426 Handle<SharedFunctionInfo> function = |
427 Compiler::BuildFunctionInfo(decl->fun(), info()->script(), info()); | 427 Compiler::BuildFunctionInfo(decl->fun(), info()->script(), info()); |
428 // Check for stack-overflow exception. | 428 // Check for stack-overflow exception. |
429 if (function.is_null()) return SetStackOverflow(); | 429 if (function.is_null()) return SetStackOverflow(); |
430 globals()->Add(variable->name(), zone()); | 430 globals()->push_back(variable->name()); |
431 globals()->Add(function, zone()); | 431 globals()->push_back(function); |
432 break; | 432 break; |
433 } | 433 } |
434 case Variable::PARAMETER: | 434 case Variable::PARAMETER: |
435 case Variable::LOCAL: { | 435 case Variable::LOCAL: { |
436 VisitForValue(decl->fun()); | 436 VisitForValue(decl->fun()); |
437 Node* value = environment()->Pop(); | 437 Node* value = environment()->Pop(); |
438 environment()->Bind(variable, value); | 438 environment()->Bind(variable, value); |
439 break; | 439 break; |
440 } | 440 } |
441 case Variable::CONTEXT: { | 441 case Variable::CONTEXT: { |
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 | 1632 |
1633 void AstGraphBuilder::VisitSuperReference(SuperReference* expr) { | 1633 void AstGraphBuilder::VisitSuperReference(SuperReference* expr) { |
1634 UNREACHABLE(); | 1634 UNREACHABLE(); |
1635 } | 1635 } |
1636 | 1636 |
1637 | 1637 |
1638 void AstGraphBuilder::VisitCaseClause(CaseClause* expr) { UNREACHABLE(); } | 1638 void AstGraphBuilder::VisitCaseClause(CaseClause* expr) { UNREACHABLE(); } |
1639 | 1639 |
1640 | 1640 |
1641 void AstGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) { | 1641 void AstGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) { |
1642 DCHECK(globals()->is_empty()); | 1642 DCHECK(globals()->empty()); |
1643 AstVisitor::VisitDeclarations(declarations); | 1643 AstVisitor::VisitDeclarations(declarations); |
1644 if (globals()->is_empty()) return; | 1644 if (globals()->empty()) return; |
1645 Handle<FixedArray> data = | 1645 int array_index = 0; |
1646 isolate()->factory()->NewFixedArray(globals()->length(), TENURED); | 1646 Handle<FixedArray> data = isolate()->factory()->NewFixedArray( |
1647 for (int i = 0; i < globals()->length(); ++i) data->set(i, *globals()->at(i)); | 1647 static_cast<int>(globals()->size()), TENURED); |
| 1648 for (Handle<Object> obj : *globals()) data->set(array_index++, *obj); |
1648 int encoded_flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) | | 1649 int encoded_flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) | |
1649 DeclareGlobalsNativeFlag::encode(info()->is_native()) | | 1650 DeclareGlobalsNativeFlag::encode(info()->is_native()) | |
1650 DeclareGlobalsStrictMode::encode(strict_mode()); | 1651 DeclareGlobalsStrictMode::encode(strict_mode()); |
1651 Node* flags = jsgraph()->Constant(encoded_flags); | 1652 Node* flags = jsgraph()->Constant(encoded_flags); |
1652 Node* pairs = jsgraph()->Constant(data); | 1653 Node* pairs = jsgraph()->Constant(data); |
1653 const Operator* op = javascript()->CallRuntime(Runtime::kDeclareGlobals, 3); | 1654 const Operator* op = javascript()->CallRuntime(Runtime::kDeclareGlobals, 3); |
1654 NewNode(op, current_context(), pairs, flags); | 1655 NewNode(op, current_context(), pairs, flags); |
1655 globals()->Rewind(0); | 1656 globals()->clear(); |
1656 } | 1657 } |
1657 | 1658 |
1658 | 1659 |
1659 void AstGraphBuilder::VisitIfNotNull(Statement* stmt) { | 1660 void AstGraphBuilder::VisitIfNotNull(Statement* stmt) { |
1660 if (stmt == NULL) return; | 1661 if (stmt == NULL) return; |
1661 Visit(stmt); | 1662 Visit(stmt); |
1662 } | 1663 } |
1663 | 1664 |
1664 | 1665 |
1665 void AstGraphBuilder::VisitIterationBody(IterationStatement* stmt, | 1666 void AstGraphBuilder::VisitIterationBody(IterationStatement* stmt, |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2227 | 2228 |
2228 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop( | 2229 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop( |
2229 IterationStatement* stmt) { | 2230 IterationStatement* stmt) { |
2230 if (loop_assignment_analysis_ == NULL) return NULL; | 2231 if (loop_assignment_analysis_ == NULL) return NULL; |
2231 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt); | 2232 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt); |
2232 } | 2233 } |
2233 | 2234 |
2234 } // namespace compiler | 2235 } // namespace compiler |
2235 } // namespace internal | 2236 } // namespace internal |
2236 } // namespace v8 | 2237 } // namespace v8 |
OLD | NEW |