OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/interpreter/bytecode-register-allocator.h" | 9 #include "src/interpreter/bytecode-register-allocator.h" |
10 #include "src/interpreter/control-flow-builders.h" | 10 #include "src/interpreter/control-flow-builders.h" |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 if (generator()->HasStackOverflow() && !result_identified()) { | 547 if (generator()->HasStackOverflow() && !result_identified()) { |
548 SetResultInAccumulator(); | 548 SetResultInAccumulator(); |
549 } | 549 } |
550 return result_register_; | 550 return result_register_; |
551 } | 551 } |
552 | 552 |
553 private: | 553 private: |
554 Register result_register_; | 554 Register result_register_; |
555 }; | 555 }; |
556 | 556 |
557 BytecodeGenerator::BytecodeGenerator(Isolate* isolate, Zone* zone) | 557 BytecodeGenerator::BytecodeGenerator(CompilationInfo* info) |
558 : isolate_(isolate), | 558 : isolate_(info->isolate()), |
559 zone_(zone), | 559 zone_(info->zone()), |
560 builder_(nullptr), | 560 builder_(new (zone()) BytecodeArrayBuilder( |
561 info_(nullptr), | 561 info->isolate(), info->zone(), info->num_parameters_including_this(), |
562 scope_(nullptr), | 562 info->scope()->MaxNestedContextChainLength(), |
563 globals_(0, zone), | 563 info->scope()->num_stack_slots(), info->literal())), |
| 564 info_(info), |
| 565 scope_(info->scope()), |
| 566 globals_(0, info->zone()), |
564 execution_control_(nullptr), | 567 execution_control_(nullptr), |
565 execution_context_(nullptr), | 568 execution_context_(nullptr), |
566 execution_result_(nullptr), | 569 execution_result_(nullptr), |
567 register_allocator_(nullptr), | 570 register_allocator_(nullptr), |
568 generator_resume_points_(0, zone), | 571 generator_resume_points_(info->literal()->yield_count(), info->zone()), |
569 try_catch_nesting_level_(0), | 572 try_catch_nesting_level_(0), |
570 try_finally_nesting_level_(0), | 573 try_finally_nesting_level_(0), |
571 generator_yields_seen_(0) { | 574 generator_yields_seen_(0) { |
572 InitializeAstVisitor(isolate); | 575 InitializeAstVisitor(isolate()); |
573 } | 576 } |
574 | 577 |
575 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) { | 578 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode() { |
576 set_info(info); | |
577 set_scope(info->scope()); | |
578 | |
579 // Initialize bytecode array builder. | |
580 set_builder(new (zone()) BytecodeArrayBuilder( | |
581 isolate(), zone(), info->num_parameters_including_this(), | |
582 scope()->MaxNestedContextChainLength(), scope()->num_stack_slots(), | |
583 info->literal())); | |
584 | |
585 // Initialize the incoming context. | 579 // Initialize the incoming context. |
586 ContextScope incoming_context(this, scope(), false); | 580 ContextScope incoming_context(this, scope(), false); |
587 | 581 |
588 // Initialize control scope. | 582 // Initialize control scope. |
589 ControlScopeForTopLevel control(this); | 583 ControlScopeForTopLevel control(this); |
590 | 584 |
591 if (IsGeneratorFunction(info->literal()->kind())) { | 585 if (IsGeneratorFunction(info()->literal()->kind())) { |
592 VisitGeneratorPrologue(); | 586 VisitGeneratorPrologue(); |
593 } | 587 } |
594 | 588 |
595 // Build function context only if there are context allocated variables. | 589 // Build function context only if there are context allocated variables. |
596 if (scope()->NeedsContext()) { | 590 if (scope()->NeedsContext()) { |
597 // Push a new inner context scope for the function. | 591 // Push a new inner context scope for the function. |
598 VisitNewLocalFunctionContext(); | 592 VisitNewLocalFunctionContext(); |
599 ContextScope local_function_context(this, scope(), false); | 593 ContextScope local_function_context(this, scope(), false); |
600 VisitBuildLocalActivationContext(); | 594 VisitBuildLocalActivationContext(); |
601 MakeBytecodeBody(); | 595 MakeBytecodeBody(); |
602 } else { | 596 } else { |
603 MakeBytecodeBody(); | 597 MakeBytecodeBody(); |
604 } | 598 } |
605 | 599 |
606 builder()->EnsureReturn(); | 600 builder()->EnsureReturn(); |
607 set_scope(nullptr); | |
608 set_info(nullptr); | |
609 return builder()->ToBytecodeArray(); | 601 return builder()->ToBytecodeArray(); |
610 } | 602 } |
611 | 603 |
612 | 604 |
613 void BytecodeGenerator::MakeBytecodeBody() { | 605 void BytecodeGenerator::MakeBytecodeBody() { |
614 // Build the arguments object if it is used. | 606 // Build the arguments object if it is used. |
615 VisitArgumentsObject(scope()->arguments()); | 607 VisitArgumentsObject(scope()->arguments()); |
616 | 608 |
617 // Build rest arguments array if it is used. | 609 // Build rest arguments array if it is used. |
618 int rest_index; | 610 int rest_index; |
(...skipping 15 matching lines...) Expand all Loading... |
634 VisitDeclarations(scope()->declarations()); | 626 VisitDeclarations(scope()->declarations()); |
635 | 627 |
636 // Perform a stack-check before the body. | 628 // Perform a stack-check before the body. |
637 builder()->StackCheck(); | 629 builder()->StackCheck(); |
638 | 630 |
639 // Visit statements in the function body. | 631 // Visit statements in the function body. |
640 VisitStatements(info()->literal()->body()); | 632 VisitStatements(info()->literal()->body()); |
641 } | 633 } |
642 | 634 |
643 void BytecodeGenerator::VisitGeneratorPrologue() { | 635 void BytecodeGenerator::VisitGeneratorPrologue() { |
644 generator_resume_points_.clear(); | |
645 generator_resume_points_.resize(info()->literal()->yield_count()); | |
646 | |
647 BytecodeLabel regular_call; | 636 BytecodeLabel regular_call; |
648 builder() | 637 builder() |
649 ->LoadAccumulatorWithRegister(Register::new_target()) | 638 ->LoadAccumulatorWithRegister(Register::new_target()) |
650 .JumpIfUndefined(®ular_call); | 639 .JumpIfUndefined(®ular_call); |
651 | 640 |
652 // This is a resume call. Restore registers and perform state dispatch. | 641 // This is a resume call. Restore registers and perform state dispatch. |
653 // (The current context has already been restored by the trampoline.) | 642 // (The current context has already been restored by the trampoline.) |
654 { | 643 { |
655 RegisterAllocationScope register_scope(this); | 644 RegisterAllocationScope register_scope(this); |
656 Register state = register_allocator()->NewRegister(); | 645 Register state = register_allocator()->NewRegister(); |
(...skipping 2617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3274 } | 3263 } |
3275 | 3264 |
3276 | 3265 |
3277 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3266 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3278 return info()->shared_info()->feedback_vector()->GetIndex(slot); | 3267 return info()->shared_info()->feedback_vector()->GetIndex(slot); |
3279 } | 3268 } |
3280 | 3269 |
3281 } // namespace interpreter | 3270 } // namespace interpreter |
3282 } // namespace internal | 3271 } // namespace internal |
3283 } // namespace v8 | 3272 } // namespace v8 |
OLD | NEW |