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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 if (scope()->NeedsContext()) { | 567 if (scope()->NeedsContext()) { |
568 // Push a new inner context scope for the function. | 568 // Push a new inner context scope for the function. |
569 VisitNewLocalFunctionContext(); | 569 VisitNewLocalFunctionContext(); |
570 ContextScope local_function_context(this, scope(), false); | 570 ContextScope local_function_context(this, scope(), false); |
571 VisitBuildLocalActivationContext(); | 571 VisitBuildLocalActivationContext(); |
572 MakeBytecodeBody(); | 572 MakeBytecodeBody(); |
573 } else { | 573 } else { |
574 MakeBytecodeBody(); | 574 MakeBytecodeBody(); |
575 } | 575 } |
576 | 576 |
| 577 builder()->EnsureReturn(info->literal()); |
577 set_scope(nullptr); | 578 set_scope(nullptr); |
578 set_info(nullptr); | 579 set_info(nullptr); |
579 return builder()->ToBytecodeArray(); | 580 return builder()->ToBytecodeArray(); |
580 } | 581 } |
581 | 582 |
582 | 583 |
583 void BytecodeGenerator::MakeBytecodeBody() { | 584 void BytecodeGenerator::MakeBytecodeBody() { |
584 // Build the arguments object if it is used. | 585 // Build the arguments object if it is used. |
585 VisitArgumentsObject(scope()->arguments()); | 586 VisitArgumentsObject(scope()->arguments()); |
586 | 587 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 // Allocate an outer register allocations scope for the statement. | 799 // Allocate an outer register allocations scope for the statement. |
799 RegisterAllocationScope allocation_scope(this); | 800 RegisterAllocationScope allocation_scope(this); |
800 Statement* stmt = statements->at(i); | 801 Statement* stmt = statements->at(i); |
801 Visit(stmt); | 802 Visit(stmt); |
802 if (stmt->IsJump()) break; | 803 if (stmt->IsJump()) break; |
803 } | 804 } |
804 } | 805 } |
805 | 806 |
806 | 807 |
807 void BytecodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { | 808 void BytecodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
| 809 builder()->SetStatementPosition(stmt); |
808 VisitForEffect(stmt->expression()); | 810 VisitForEffect(stmt->expression()); |
809 } | 811 } |
810 | 812 |
811 | 813 |
812 void BytecodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { | 814 void BytecodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { |
813 } | 815 } |
814 | 816 |
815 | 817 |
816 void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { | 818 void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { |
817 BytecodeLabel else_label, end_label; | 819 BytecodeLabel else_label, end_label; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 } | 855 } |
854 | 856 |
855 | 857 |
856 void BytecodeGenerator::VisitBreakStatement(BreakStatement* stmt) { | 858 void BytecodeGenerator::VisitBreakStatement(BreakStatement* stmt) { |
857 execution_control()->Break(stmt->target()); | 859 execution_control()->Break(stmt->target()); |
858 } | 860 } |
859 | 861 |
860 | 862 |
861 void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 863 void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
862 VisitForAccumulatorValue(stmt->expression()); | 864 VisitForAccumulatorValue(stmt->expression()); |
| 865 builder()->SetReturnPosition(info_->literal()); |
863 execution_control()->ReturnAccumulator(); | 866 execution_control()->ReturnAccumulator(); |
864 } | 867 } |
865 | 868 |
866 | 869 |
867 void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { | 870 void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { |
868 VisitForAccumulatorValue(stmt->expression()); | 871 VisitForAccumulatorValue(stmt->expression()); |
869 builder()->CastAccumulatorToJSObject(); | 872 builder()->CastAccumulatorToJSObject(); |
870 VisitNewLocalWithContext(); | 873 VisitNewLocalWithContext(); |
871 VisitInScope(stmt->statement(), stmt->scope()); | 874 VisitInScope(stmt->statement(), stmt->scope()); |
872 } | 875 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 | 1211 |
1209 // Pending message object is restored on exit. | 1212 // Pending message object is restored on exit. |
1210 builder()->CallRuntime(Runtime::kInterpreterSetPendingMessage, message, 1); | 1213 builder()->CallRuntime(Runtime::kInterpreterSetPendingMessage, message, 1); |
1211 | 1214 |
1212 // Dynamic dispatch after the finally-block. | 1215 // Dynamic dispatch after the finally-block. |
1213 commands.ApplyDeferredCommands(); | 1216 commands.ApplyDeferredCommands(); |
1214 } | 1217 } |
1215 | 1218 |
1216 | 1219 |
1217 void BytecodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { | 1220 void BytecodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { |
| 1221 builder()->SetStatementPosition(stmt); |
1218 builder()->Debugger(); | 1222 builder()->Debugger(); |
1219 } | 1223 } |
1220 | 1224 |
1221 | 1225 |
1222 void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { | 1226 void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
1223 // Find or build a shared function info. | 1227 // Find or build a shared function info. |
1224 Handle<SharedFunctionInfo> shared_info = | 1228 Handle<SharedFunctionInfo> shared_info = |
1225 Compiler::GetSharedFunctionInfo(expr, info()->script(), info()); | 1229 Compiler::GetSharedFunctionInfo(expr, info()->script(), info()); |
1226 CHECK(!shared_info.is_null()); // TODO(rmcilroy): Set stack overflow? | 1230 CHECK(!shared_info.is_null()); // TODO(rmcilroy): Set stack overflow? |
1227 builder()->CreateClosure(shared_info, | 1231 builder()->CreateClosure(shared_info, |
(...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2871 } | 2875 } |
2872 | 2876 |
2873 | 2877 |
2874 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 2878 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
2875 return info()->feedback_vector()->GetIndex(slot); | 2879 return info()->feedback_vector()->GetIndex(slot); |
2876 } | 2880 } |
2877 | 2881 |
2878 } // namespace interpreter | 2882 } // namespace interpreter |
2879 } // namespace internal | 2883 } // namespace internal |
2880 } // namespace v8 | 2884 } // namespace v8 |
OLD | NEW |