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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 InitializeAstVisitor(isolate); | 564 InitializeAstVisitor(isolate); |
565 } | 565 } |
566 | 566 |
567 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) { | 567 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) { |
568 set_info(info); | 568 set_info(info); |
569 set_scope(info->scope()); | 569 set_scope(info->scope()); |
570 | 570 |
571 // Initialize bytecode array builder. | 571 // Initialize bytecode array builder. |
572 set_builder(new (zone()) BytecodeArrayBuilder( | 572 set_builder(new (zone()) BytecodeArrayBuilder( |
573 isolate(), zone(), info->num_parameters_including_this(), | 573 isolate(), zone(), info->num_parameters_including_this(), |
574 scope()->MaxNestedContextChainLength(), scope()->num_stack_slots())); | 574 scope()->MaxNestedContextChainLength(), scope()->num_stack_slots(), |
| 575 info->literal())); |
575 | 576 |
576 // Initialize the incoming context. | 577 // Initialize the incoming context. |
577 ContextScope incoming_context(this, scope(), false); | 578 ContextScope incoming_context(this, scope(), false); |
578 | 579 |
579 // Initialize control scope. | 580 // Initialize control scope. |
580 ControlScopeForTopLevel control(this); | 581 ControlScopeForTopLevel control(this); |
581 | 582 |
582 // Build function context only if there are context allocated variables. | 583 // Build function context only if there are context allocated variables. |
583 if (scope()->NeedsContext()) { | 584 if (scope()->NeedsContext()) { |
584 // Push a new inner context scope for the function. | 585 // Push a new inner context scope for the function. |
585 VisitNewLocalFunctionContext(); | 586 VisitNewLocalFunctionContext(); |
586 ContextScope local_function_context(this, scope(), false); | 587 ContextScope local_function_context(this, scope(), false); |
587 VisitBuildLocalActivationContext(); | 588 VisitBuildLocalActivationContext(); |
588 MakeBytecodeBody(); | 589 MakeBytecodeBody(); |
589 } else { | 590 } else { |
590 MakeBytecodeBody(); | 591 MakeBytecodeBody(); |
591 } | 592 } |
592 | 593 |
593 builder()->EnsureReturn(info->literal()); | 594 builder()->EnsureReturn(); |
594 set_scope(nullptr); | 595 set_scope(nullptr); |
595 set_info(nullptr); | 596 set_info(nullptr); |
596 return builder()->ToBytecodeArray(); | 597 return builder()->ToBytecodeArray(); |
597 } | 598 } |
598 | 599 |
599 | 600 |
600 void BytecodeGenerator::MakeBytecodeBody() { | 601 void BytecodeGenerator::MakeBytecodeBody() { |
601 // Build the arguments object if it is used. | 602 // Build the arguments object if it is used. |
602 VisitArgumentsObject(scope()->arguments()); | 603 VisitArgumentsObject(scope()->arguments()); |
603 | 604 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 execution_control()->Continue(stmt->target()); | 871 execution_control()->Continue(stmt->target()); |
871 } | 872 } |
872 | 873 |
873 | 874 |
874 void BytecodeGenerator::VisitBreakStatement(BreakStatement* stmt) { | 875 void BytecodeGenerator::VisitBreakStatement(BreakStatement* stmt) { |
875 execution_control()->Break(stmt->target()); | 876 execution_control()->Break(stmt->target()); |
876 } | 877 } |
877 | 878 |
878 | 879 |
879 void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 880 void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
| 881 builder()->SetStatementPosition(stmt); |
880 VisitForAccumulatorValue(stmt->expression()); | 882 VisitForAccumulatorValue(stmt->expression()); |
881 builder()->SetStatementPosition(stmt); | |
882 execution_control()->ReturnAccumulator(); | 883 execution_control()->ReturnAccumulator(); |
883 } | 884 } |
884 | 885 |
885 | 886 |
886 void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { | 887 void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { |
887 VisitForAccumulatorValue(stmt->expression()); | 888 VisitForAccumulatorValue(stmt->expression()); |
888 builder()->CastAccumulatorToJSObject(); | 889 builder()->CastAccumulatorToJSObject(); |
889 VisitNewLocalWithContext(); | 890 VisitNewLocalWithContext(); |
890 VisitInScope(stmt->statement(), stmt->scope()); | 891 VisitInScope(stmt->statement(), stmt->scope()); |
891 } | 892 } |
(...skipping 2245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3137 } | 3138 } |
3138 | 3139 |
3139 | 3140 |
3140 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3141 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3141 return info()->feedback_vector()->GetIndex(slot); | 3142 return info()->feedback_vector()->GetIndex(slot); |
3142 } | 3143 } |
3143 | 3144 |
3144 } // namespace interpreter | 3145 } // namespace interpreter |
3145 } // namespace internal | 3146 } // namespace internal |
3146 } // namespace v8 | 3147 } // namespace v8 |
OLD | NEW |