| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/full-codegen/full-codegen.h" | 5 #include "src/full-codegen/full-codegen.h" |
| 6 | 6 |
| 7 #include "src/ast/ast.h" | 7 #include "src/ast/ast.h" |
| 8 #include "src/ast/ast-numbering.h" | 8 #include "src/ast/ast-numbering.h" |
| 9 #include "src/ast/prettyprinter.h" | 9 #include "src/ast/prettyprinter.h" |
| 10 #include "src/ast/scopeinfo.h" | 10 #include "src/ast/scopeinfo.h" |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 RecordPosition(masm_, expr->position()); | 607 RecordPosition(masm_, expr->position()); |
| 608 if (info_->is_debug()) { | 608 if (info_->is_debug()) { |
| 609 // Always emit a debug break slot before a call. | 609 // Always emit a debug break slot before a call. |
| 610 DebugCodegen::GenerateSlot(masm_, RelocInfo::DEBUG_BREAK_SLOT_AT_CALL); | 610 DebugCodegen::GenerateSlot(masm_, RelocInfo::DEBUG_BREAK_SLOT_AT_CALL); |
| 611 } | 611 } |
| 612 } | 612 } |
| 613 | 613 |
| 614 | 614 |
| 615 void FullCodeGenerator::VisitSuperPropertyReference( | 615 void FullCodeGenerator::VisitSuperPropertyReference( |
| 616 SuperPropertyReference* super) { | 616 SuperPropertyReference* super) { |
| 617 __ CallRuntime(Runtime::kThrowUnsupportedSuperError, 0); | 617 __ CallRuntime(Runtime::kThrowUnsupportedSuperError); |
| 618 } | 618 } |
| 619 | 619 |
| 620 | 620 |
| 621 void FullCodeGenerator::VisitSuperCallReference(SuperCallReference* super) { | 621 void FullCodeGenerator::VisitSuperCallReference(SuperCallReference* super) { |
| 622 __ CallRuntime(Runtime::kThrowUnsupportedSuperError, 0); | 622 __ CallRuntime(Runtime::kThrowUnsupportedSuperError); |
| 623 } | 623 } |
| 624 | 624 |
| 625 | 625 |
| 626 void FullCodeGenerator::EmitGeneratorNext(CallRuntime* expr) { | 626 void FullCodeGenerator::EmitGeneratorNext(CallRuntime* expr) { |
| 627 ZoneList<Expression*>* args = expr->arguments(); | 627 ZoneList<Expression*>* args = expr->arguments(); |
| 628 DCHECK(args->length() == 2); | 628 DCHECK(args->length() == 2); |
| 629 EmitGeneratorResume(args->at(0), args->at(1), JSGeneratorObject::NEXT); | 629 EmitGeneratorResume(args->at(0), args->at(1), JSGeneratorObject::NEXT); |
| 630 } | 630 } |
| 631 | 631 |
| 632 | 632 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 while (current != NULL) { | 907 while (current != NULL) { |
| 908 current = current->Exit(&stack_depth, &context_length); | 908 current = current->Exit(&stack_depth, &context_length); |
| 909 } | 909 } |
| 910 __ Drop(stack_depth); | 910 __ Drop(stack_depth); |
| 911 } | 911 } |
| 912 | 912 |
| 913 | 913 |
| 914 void FullCodeGenerator::EmitPropertyKey(ObjectLiteralProperty* property, | 914 void FullCodeGenerator::EmitPropertyKey(ObjectLiteralProperty* property, |
| 915 BailoutId bailout_id) { | 915 BailoutId bailout_id) { |
| 916 VisitForStackValue(property->key()); | 916 VisitForStackValue(property->key()); |
| 917 __ CallRuntime(Runtime::kToName, 1); | 917 __ CallRuntime(Runtime::kToName); |
| 918 PrepareForBailoutForId(bailout_id, NO_REGISTERS); | 918 PrepareForBailoutForId(bailout_id, NO_REGISTERS); |
| 919 __ Push(result_register()); | 919 __ Push(result_register()); |
| 920 } | 920 } |
| 921 | 921 |
| 922 | 922 |
| 923 void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 923 void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
| 924 Comment cmnt(masm_, "[ ReturnStatement"); | 924 Comment cmnt(masm_, "[ ReturnStatement"); |
| 925 SetStatementPosition(stmt); | 925 SetStatementPosition(stmt); |
| 926 Expression* expr = stmt->expression(); | 926 Expression* expr = stmt->expression(); |
| 927 VisitForAccumulatorValue(expr); | 927 VisitForAccumulatorValue(expr); |
| 928 EmitUnwindBeforeReturn(); | 928 EmitUnwindBeforeReturn(); |
| 929 EmitReturnSequence(); | 929 EmitReturnSequence(); |
| 930 } | 930 } |
| 931 | 931 |
| 932 | 932 |
| 933 void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) { | 933 void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) { |
| 934 Comment cmnt(masm_, "[ WithStatement"); | 934 Comment cmnt(masm_, "[ WithStatement"); |
| 935 SetStatementPosition(stmt); | 935 SetStatementPosition(stmt); |
| 936 | 936 |
| 937 VisitForAccumulatorValue(stmt->expression()); | 937 VisitForAccumulatorValue(stmt->expression()); |
| 938 Callable callable = CodeFactory::ToObject(isolate()); | 938 Callable callable = CodeFactory::ToObject(isolate()); |
| 939 __ Move(callable.descriptor().GetRegisterParameter(0), result_register()); | 939 __ Move(callable.descriptor().GetRegisterParameter(0), result_register()); |
| 940 __ Call(callable.code(), RelocInfo::CODE_TARGET); | 940 __ Call(callable.code(), RelocInfo::CODE_TARGET); |
| 941 PrepareForBailoutForId(stmt->ToObjectId(), NO_REGISTERS); | 941 PrepareForBailoutForId(stmt->ToObjectId(), NO_REGISTERS); |
| 942 __ Push(result_register()); | 942 __ Push(result_register()); |
| 943 PushFunctionArgumentForContextAllocation(); | 943 PushFunctionArgumentForContextAllocation(); |
| 944 __ CallRuntime(Runtime::kPushWithContext, 2); | 944 __ CallRuntime(Runtime::kPushWithContext); |
| 945 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); | 945 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
| 946 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); | 946 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 947 | 947 |
| 948 Scope* saved_scope = scope(); | 948 Scope* saved_scope = scope(); |
| 949 scope_ = stmt->scope(); | 949 scope_ = stmt->scope(); |
| 950 { WithOrCatch body(this); | 950 { WithOrCatch body(this); |
| 951 Visit(stmt->statement()); | 951 Visit(stmt->statement()); |
| 952 } | 952 } |
| 953 scope_ = saved_scope; | 953 scope_ = saved_scope; |
| 954 | 954 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1131 __ bind(&handler_entry); | 1131 __ bind(&handler_entry); |
| 1132 PrepareForBailoutForId(stmt->HandlerId(), NO_REGISTERS); | 1132 PrepareForBailoutForId(stmt->HandlerId(), NO_REGISTERS); |
| 1133 ClearPendingMessage(); | 1133 ClearPendingMessage(); |
| 1134 | 1134 |
| 1135 // Exception handler code, the exception is in the result register. | 1135 // Exception handler code, the exception is in the result register. |
| 1136 // Extend the context before executing the catch block. | 1136 // Extend the context before executing the catch block. |
| 1137 { Comment cmnt(masm_, "[ Extend catch context"); | 1137 { Comment cmnt(masm_, "[ Extend catch context"); |
| 1138 __ Push(stmt->variable()->name()); | 1138 __ Push(stmt->variable()->name()); |
| 1139 __ Push(result_register()); | 1139 __ Push(result_register()); |
| 1140 PushFunctionArgumentForContextAllocation(); | 1140 PushFunctionArgumentForContextAllocation(); |
| 1141 __ CallRuntime(Runtime::kPushCatchContext, 3); | 1141 __ CallRuntime(Runtime::kPushCatchContext); |
| 1142 StoreToFrameField(StandardFrameConstants::kContextOffset, | 1142 StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1143 context_register()); | 1143 context_register()); |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 Scope* saved_scope = scope(); | 1146 Scope* saved_scope = scope(); |
| 1147 scope_ = stmt->scope(); | 1147 scope_ = stmt->scope(); |
| 1148 DCHECK(scope_->declarations()->is_empty()); | 1148 DCHECK(scope_->declarations()->is_empty()); |
| 1149 { WithOrCatch catch_body(this); | 1149 { WithOrCatch catch_body(this); |
| 1150 Visit(stmt->catch_block()); | 1150 Visit(stmt->catch_block()); |
| 1151 } | 1151 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1201 __ jmp(&try_entry); | 1201 __ jmp(&try_entry); |
| 1202 __ bind(&handler_entry); | 1202 __ bind(&handler_entry); |
| 1203 PrepareForBailoutForId(stmt->HandlerId(), NO_REGISTERS); | 1203 PrepareForBailoutForId(stmt->HandlerId(), NO_REGISTERS); |
| 1204 | 1204 |
| 1205 // Exception handler code. This code is only executed when an exception | 1205 // Exception handler code. This code is only executed when an exception |
| 1206 // is thrown. The exception is in the result register, and must be | 1206 // is thrown. The exception is in the result register, and must be |
| 1207 // preserved by the finally block. Call the finally block and then | 1207 // preserved by the finally block. Call the finally block and then |
| 1208 // rethrow the exception if it returns. | 1208 // rethrow the exception if it returns. |
| 1209 __ Call(&finally_entry); | 1209 __ Call(&finally_entry); |
| 1210 __ Push(result_register()); | 1210 __ Push(result_register()); |
| 1211 __ CallRuntime(Runtime::kReThrow, 1); | 1211 __ CallRuntime(Runtime::kReThrow); |
| 1212 | 1212 |
| 1213 // Finally block implementation. | 1213 // Finally block implementation. |
| 1214 __ bind(&finally_entry); | 1214 __ bind(&finally_entry); |
| 1215 EnterFinallyBlock(); | 1215 EnterFinallyBlock(); |
| 1216 { Finally finally_body(this); | 1216 { Finally finally_body(this); |
| 1217 Visit(stmt->finally_block()); | 1217 Visit(stmt->finally_block()); |
| 1218 } | 1218 } |
| 1219 ExitFinallyBlock(); // Return to the calling code. | 1219 ExitFinallyBlock(); // Return to the calling code. |
| 1220 | 1220 |
| 1221 // Set up try handler. | 1221 // Set up try handler. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 VisitForStackValue(lit->extends()); | 1318 VisitForStackValue(lit->extends()); |
| 1319 } else { | 1319 } else { |
| 1320 __ Push(isolate()->factory()->the_hole_value()); | 1320 __ Push(isolate()->factory()->the_hole_value()); |
| 1321 } | 1321 } |
| 1322 | 1322 |
| 1323 VisitForStackValue(lit->constructor()); | 1323 VisitForStackValue(lit->constructor()); |
| 1324 | 1324 |
| 1325 __ Push(Smi::FromInt(lit->start_position())); | 1325 __ Push(Smi::FromInt(lit->start_position())); |
| 1326 __ Push(Smi::FromInt(lit->end_position())); | 1326 __ Push(Smi::FromInt(lit->end_position())); |
| 1327 | 1327 |
| 1328 __ CallRuntime(Runtime::kDefineClass, 5); | 1328 __ CallRuntime(Runtime::kDefineClass); |
| 1329 PrepareForBailoutForId(lit->CreateLiteralId(), TOS_REG); | 1329 PrepareForBailoutForId(lit->CreateLiteralId(), TOS_REG); |
| 1330 | 1330 |
| 1331 EmitClassDefineProperties(lit); | 1331 EmitClassDefineProperties(lit); |
| 1332 | 1332 |
| 1333 if (lit->class_variable_proxy() != nullptr) { | 1333 if (lit->class_variable_proxy() != nullptr) { |
| 1334 EmitVariableAssignment(lit->class_variable_proxy()->var(), Token::INIT, | 1334 EmitVariableAssignment(lit->class_variable_proxy()->var(), Token::INIT, |
| 1335 lit->ProxySlot()); | 1335 lit->ProxySlot()); |
| 1336 } | 1336 } |
| 1337 } | 1337 } |
| 1338 | 1338 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 shared->set_internal_formal_parameter_count(parameters); | 1373 shared->set_internal_formal_parameter_count(parameters); |
| 1374 | 1374 |
| 1375 EmitNewClosure(shared, false); | 1375 EmitNewClosure(shared, false); |
| 1376 } | 1376 } |
| 1377 | 1377 |
| 1378 | 1378 |
| 1379 void FullCodeGenerator::VisitThrow(Throw* expr) { | 1379 void FullCodeGenerator::VisitThrow(Throw* expr) { |
| 1380 Comment cmnt(masm_, "[ Throw"); | 1380 Comment cmnt(masm_, "[ Throw"); |
| 1381 VisitForStackValue(expr->exception()); | 1381 VisitForStackValue(expr->exception()); |
| 1382 SetExpressionPosition(expr); | 1382 SetExpressionPosition(expr); |
| 1383 __ CallRuntime(Runtime::kThrow, 1); | 1383 __ CallRuntime(Runtime::kThrow); |
| 1384 // Never returns here. | 1384 // Never returns here. |
| 1385 } | 1385 } |
| 1386 | 1386 |
| 1387 | 1387 |
| 1388 void FullCodeGenerator::EnterTryBlock(int handler_index, Label* handler) { | 1388 void FullCodeGenerator::EnterTryBlock(int handler_index, Label* handler) { |
| 1389 HandlerTableEntry* entry = &handler_table_[handler_index]; | 1389 HandlerTableEntry* entry = &handler_table_[handler_index]; |
| 1390 entry->range_start = masm()->pc_offset(); | 1390 entry->range_start = masm()->pc_offset(); |
| 1391 entry->handler_offset = handler->pos(); | 1391 entry->handler_offset = handler->pos(); |
| 1392 entry->try_catch_depth = try_catch_depth_; | 1392 entry->try_catch_depth = try_catch_depth_; |
| 1393 | 1393 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1635 codegen_->PrepareForBailoutForId(entry_id, NO_REGISTERS); | 1635 codegen_->PrepareForBailoutForId(entry_id, NO_REGISTERS); |
| 1636 needs_block_context_ = false; | 1636 needs_block_context_ = false; |
| 1637 } else { | 1637 } else { |
| 1638 needs_block_context_ = scope->NeedsContext(); | 1638 needs_block_context_ = scope->NeedsContext(); |
| 1639 codegen_->scope_ = scope; | 1639 codegen_->scope_ = scope; |
| 1640 { | 1640 { |
| 1641 if (needs_block_context_) { | 1641 if (needs_block_context_) { |
| 1642 Comment cmnt(masm(), "[ Extend block context"); | 1642 Comment cmnt(masm(), "[ Extend block context"); |
| 1643 __ Push(scope->GetScopeInfo(codegen->isolate())); | 1643 __ Push(scope->GetScopeInfo(codegen->isolate())); |
| 1644 codegen_->PushFunctionArgumentForContextAllocation(); | 1644 codegen_->PushFunctionArgumentForContextAllocation(); |
| 1645 __ CallRuntime(Runtime::kPushBlockContext, 2); | 1645 __ CallRuntime(Runtime::kPushBlockContext); |
| 1646 | 1646 |
| 1647 // Replace the context stored in the frame. | 1647 // Replace the context stored in the frame. |
| 1648 codegen_->StoreToFrameField(StandardFrameConstants::kContextOffset, | 1648 codegen_->StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1649 codegen_->context_register()); | 1649 codegen_->context_register()); |
| 1650 } | 1650 } |
| 1651 CHECK_EQ(0, scope->num_stack_slots()); | 1651 CHECK_EQ(0, scope->num_stack_slots()); |
| 1652 codegen_->PrepareForBailoutForId(entry_id, NO_REGISTERS); | 1652 codegen_->PrepareForBailoutForId(entry_id, NO_REGISTERS); |
| 1653 } | 1653 } |
| 1654 { | 1654 { |
| 1655 Comment cmnt(masm(), "[ Declarations"); | 1655 Comment cmnt(masm(), "[ Declarations"); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 return var->mode() == CONST_LEGACY || var->scope()->is_nonlinear() || | 1730 return var->mode() == CONST_LEGACY || var->scope()->is_nonlinear() || |
| 1731 var->initializer_position() >= proxy->position(); | 1731 var->initializer_position() >= proxy->position(); |
| 1732 } | 1732 } |
| 1733 | 1733 |
| 1734 | 1734 |
| 1735 #undef __ | 1735 #undef __ |
| 1736 | 1736 |
| 1737 | 1737 |
| 1738 } // namespace internal | 1738 } // namespace internal |
| 1739 } // namespace v8 | 1739 } // namespace v8 |
| OLD | NEW |