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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/codegen.h" | 7 #include "src/codegen.h" |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/debug.h" | 9 #include "src/debug.h" |
10 #include "src/full-codegen.h" | 10 #include "src/full-codegen.h" |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 Scope* scope = module->body()->scope(); | 591 Scope* scope = module->body()->scope(); |
592 Interface* interface = scope->interface(); | 592 Interface* interface = scope->interface(); |
593 ASSERT(interface->IsModule() && interface->IsFrozen()); | 593 ASSERT(interface->IsModule() && interface->IsFrozen()); |
594 | 594 |
595 interface->Allocate(scope->module_var()->index()); | 595 interface->Allocate(scope->module_var()->index()); |
596 | 596 |
597 // Set up module context. | 597 // Set up module context. |
598 ASSERT(scope->interface()->Index() >= 0); | 598 ASSERT(scope->interface()->Index() >= 0); |
599 __ Push(Smi::FromInt(scope->interface()->Index())); | 599 __ Push(Smi::FromInt(scope->interface()->Index())); |
600 __ Push(scope->GetScopeInfo()); | 600 __ Push(scope->GetScopeInfo()); |
601 __ CallRuntime(Runtime::kHiddenPushModuleContext, 2); | 601 __ CallRuntime(Runtime::kPushModuleContext, 2); |
602 StoreToFrameField(StandardFrameConstants::kContextOffset, | 602 StoreToFrameField(StandardFrameConstants::kContextOffset, |
603 context_register()); | 603 context_register()); |
604 | 604 |
605 AllocateModules(scope->declarations()); | 605 AllocateModules(scope->declarations()); |
606 | 606 |
607 // Pop module context. | 607 // Pop module context. |
608 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 608 LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
609 // Update local stack frame context field. | 609 // Update local stack frame context field. |
610 StoreToFrameField(StandardFrameConstants::kContextOffset, | 610 StoreToFrameField(StandardFrameConstants::kContextOffset, |
611 context_register()); | 611 context_register()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 SetStatementPosition(block); | 731 SetStatementPosition(block); |
732 | 732 |
733 ASSERT(!modules_.is_null()); | 733 ASSERT(!modules_.is_null()); |
734 ASSERT(module_index_ < modules_->length()); | 734 ASSERT(module_index_ < modules_->length()); |
735 int index = module_index_++; | 735 int index = module_index_++; |
736 | 736 |
737 // Set up module context. | 737 // Set up module context. |
738 ASSERT(interface->Index() >= 0); | 738 ASSERT(interface->Index() >= 0); |
739 __ Push(Smi::FromInt(interface->Index())); | 739 __ Push(Smi::FromInt(interface->Index())); |
740 __ Push(Smi::FromInt(0)); | 740 __ Push(Smi::FromInt(0)); |
741 __ CallRuntime(Runtime::kHiddenPushModuleContext, 2); | 741 __ CallRuntime(Runtime::kPushModuleContext, 2); |
742 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); | 742 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
743 | 743 |
744 { | 744 { |
745 Comment cmnt(masm_, "[ Declarations"); | 745 Comment cmnt(masm_, "[ Declarations"); |
746 VisitDeclarations(scope_->declarations()); | 746 VisitDeclarations(scope_->declarations()); |
747 } | 747 } |
748 | 748 |
749 // Populate the module description. | 749 // Populate the module description. |
750 Handle<ModuleInfo> description = | 750 Handle<ModuleInfo> description = |
751 ModuleInfo::Create(isolate(), interface, scope_); | 751 ModuleInfo::Create(isolate(), interface, scope_); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 Scope* saved_scope = scope(); | 1052 Scope* saved_scope = scope(); |
1053 // Push a block context when entering a block with block scoped variables. | 1053 // Push a block context when entering a block with block scoped variables. |
1054 if (stmt->scope() == NULL) { | 1054 if (stmt->scope() == NULL) { |
1055 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); | 1055 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
1056 } else { | 1056 } else { |
1057 scope_ = stmt->scope(); | 1057 scope_ = stmt->scope(); |
1058 ASSERT(!scope_->is_module_scope()); | 1058 ASSERT(!scope_->is_module_scope()); |
1059 { Comment cmnt(masm_, "[ Extend block context"); | 1059 { Comment cmnt(masm_, "[ Extend block context"); |
1060 __ Push(scope_->GetScopeInfo()); | 1060 __ Push(scope_->GetScopeInfo()); |
1061 PushFunctionArgumentForContextAllocation(); | 1061 PushFunctionArgumentForContextAllocation(); |
1062 __ CallRuntime(Runtime::kHiddenPushBlockContext, 2); | 1062 __ CallRuntime(Runtime::kPushBlockContext, 2); |
1063 | 1063 |
1064 // Replace the context stored in the frame. | 1064 // Replace the context stored in the frame. |
1065 StoreToFrameField(StandardFrameConstants::kContextOffset, | 1065 StoreToFrameField(StandardFrameConstants::kContextOffset, |
1066 context_register()); | 1066 context_register()); |
1067 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); | 1067 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
1068 } | 1068 } |
1069 { Comment cmnt(masm_, "[ Declarations"); | 1069 { Comment cmnt(masm_, "[ Declarations"); |
1070 VisitDeclarations(scope_->declarations()); | 1070 VisitDeclarations(scope_->declarations()); |
1071 PrepareForBailoutForId(stmt->DeclsId(), NO_REGISTERS); | 1071 PrepareForBailoutForId(stmt->DeclsId(), NO_REGISTERS); |
1072 } | 1072 } |
(...skipping 12 matching lines...) Expand all Loading... |
1085 } | 1085 } |
1086 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); | 1086 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
1087 } | 1087 } |
1088 | 1088 |
1089 | 1089 |
1090 void FullCodeGenerator::VisitModuleStatement(ModuleStatement* stmt) { | 1090 void FullCodeGenerator::VisitModuleStatement(ModuleStatement* stmt) { |
1091 Comment cmnt(masm_, "[ Module context"); | 1091 Comment cmnt(masm_, "[ Module context"); |
1092 | 1092 |
1093 __ Push(Smi::FromInt(stmt->proxy()->interface()->Index())); | 1093 __ Push(Smi::FromInt(stmt->proxy()->interface()->Index())); |
1094 __ Push(Smi::FromInt(0)); | 1094 __ Push(Smi::FromInt(0)); |
1095 __ CallRuntime(Runtime::kHiddenPushModuleContext, 2); | 1095 __ CallRuntime(Runtime::kPushModuleContext, 2); |
1096 StoreToFrameField( | 1096 StoreToFrameField( |
1097 StandardFrameConstants::kContextOffset, context_register()); | 1097 StandardFrameConstants::kContextOffset, context_register()); |
1098 | 1098 |
1099 Scope* saved_scope = scope_; | 1099 Scope* saved_scope = scope_; |
1100 scope_ = stmt->body()->scope(); | 1100 scope_ = stmt->body()->scope(); |
1101 VisitStatements(stmt->body()->statements()); | 1101 VisitStatements(stmt->body()->statements()); |
1102 scope_ = saved_scope; | 1102 scope_ = saved_scope; |
1103 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 1103 LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
1104 // Update local stack frame context field. | 1104 // Update local stack frame context field. |
1105 StoreToFrameField(StandardFrameConstants::kContextOffset, | 1105 StoreToFrameField(StandardFrameConstants::kContextOffset, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 EmitReturnSequence(); | 1224 EmitReturnSequence(); |
1225 } | 1225 } |
1226 | 1226 |
1227 | 1227 |
1228 void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) { | 1228 void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) { |
1229 Comment cmnt(masm_, "[ WithStatement"); | 1229 Comment cmnt(masm_, "[ WithStatement"); |
1230 SetStatementPosition(stmt); | 1230 SetStatementPosition(stmt); |
1231 | 1231 |
1232 VisitForStackValue(stmt->expression()); | 1232 VisitForStackValue(stmt->expression()); |
1233 PushFunctionArgumentForContextAllocation(); | 1233 PushFunctionArgumentForContextAllocation(); |
1234 __ CallRuntime(Runtime::kHiddenPushWithContext, 2); | 1234 __ CallRuntime(Runtime::kPushWithContext, 2); |
1235 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); | 1235 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
1236 | 1236 |
1237 Scope* saved_scope = scope(); | 1237 Scope* saved_scope = scope(); |
1238 scope_ = stmt->scope(); | 1238 scope_ = stmt->scope(); |
1239 { WithOrCatch body(this); | 1239 { WithOrCatch body(this); |
1240 Visit(stmt->statement()); | 1240 Visit(stmt->statement()); |
1241 } | 1241 } |
1242 scope_ = saved_scope; | 1242 scope_ = saved_scope; |
1243 | 1243 |
1244 // Pop context. | 1244 // Pop context. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 Label try_entry, handler_entry, exit; | 1377 Label try_entry, handler_entry, exit; |
1378 __ jmp(&try_entry); | 1378 __ jmp(&try_entry); |
1379 __ bind(&handler_entry); | 1379 __ bind(&handler_entry); |
1380 handler_table()->set(stmt->index(), Smi::FromInt(handler_entry.pos())); | 1380 handler_table()->set(stmt->index(), Smi::FromInt(handler_entry.pos())); |
1381 // Exception handler code, the exception is in the result register. | 1381 // Exception handler code, the exception is in the result register. |
1382 // Extend the context before executing the catch block. | 1382 // Extend the context before executing the catch block. |
1383 { Comment cmnt(masm_, "[ Extend catch context"); | 1383 { Comment cmnt(masm_, "[ Extend catch context"); |
1384 __ Push(stmt->variable()->name()); | 1384 __ Push(stmt->variable()->name()); |
1385 __ Push(result_register()); | 1385 __ Push(result_register()); |
1386 PushFunctionArgumentForContextAllocation(); | 1386 PushFunctionArgumentForContextAllocation(); |
1387 __ CallRuntime(Runtime::kHiddenPushCatchContext, 3); | 1387 __ CallRuntime(Runtime::kPushCatchContext, 3); |
1388 StoreToFrameField(StandardFrameConstants::kContextOffset, | 1388 StoreToFrameField(StandardFrameConstants::kContextOffset, |
1389 context_register()); | 1389 context_register()); |
1390 } | 1390 } |
1391 | 1391 |
1392 Scope* saved_scope = scope(); | 1392 Scope* saved_scope = scope(); |
1393 scope_ = stmt->scope(); | 1393 scope_ = stmt->scope(); |
1394 ASSERT(scope_->declarations()->is_empty()); | 1394 ASSERT(scope_->declarations()->is_empty()); |
1395 { WithOrCatch catch_body(this); | 1395 { WithOrCatch catch_body(this); |
1396 Visit(stmt->catch_block()); | 1396 Visit(stmt->catch_block()); |
1397 } | 1397 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 // Jump to try-handler setup and try-block code. | 1441 // Jump to try-handler setup and try-block code. |
1442 __ jmp(&try_entry); | 1442 __ jmp(&try_entry); |
1443 __ bind(&handler_entry); | 1443 __ bind(&handler_entry); |
1444 handler_table()->set(stmt->index(), Smi::FromInt(handler_entry.pos())); | 1444 handler_table()->set(stmt->index(), Smi::FromInt(handler_entry.pos())); |
1445 // Exception handler code. This code is only executed when an exception | 1445 // Exception handler code. This code is only executed when an exception |
1446 // is thrown. The exception is in the result register, and must be | 1446 // is thrown. The exception is in the result register, and must be |
1447 // preserved by the finally block. Call the finally block and then | 1447 // preserved by the finally block. Call the finally block and then |
1448 // rethrow the exception if it returns. | 1448 // rethrow the exception if it returns. |
1449 __ Call(&finally_entry); | 1449 __ Call(&finally_entry); |
1450 __ Push(result_register()); | 1450 __ Push(result_register()); |
1451 __ CallRuntime(Runtime::kHiddenReThrow, 1); | 1451 __ CallRuntime(Runtime::kReThrow, 1); |
1452 | 1452 |
1453 // Finally block implementation. | 1453 // Finally block implementation. |
1454 __ bind(&finally_entry); | 1454 __ bind(&finally_entry); |
1455 EnterFinallyBlock(); | 1455 EnterFinallyBlock(); |
1456 { Finally finally_body(this); | 1456 { Finally finally_body(this); |
1457 Visit(stmt->finally_block()); | 1457 Visit(stmt->finally_block()); |
1458 } | 1458 } |
1459 ExitFinallyBlock(); // Return to the calling code. | 1459 ExitFinallyBlock(); // Return to the calling code. |
1460 | 1460 |
1461 // Set up try handler. | 1461 // Set up try handler. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 int parameters = fun->shared()->formal_parameter_count(); | 1567 int parameters = fun->shared()->formal_parameter_count(); |
1568 shared->set_formal_parameter_count(parameters); | 1568 shared->set_formal_parameter_count(parameters); |
1569 | 1569 |
1570 EmitNewClosure(shared, false); | 1570 EmitNewClosure(shared, false); |
1571 } | 1571 } |
1572 | 1572 |
1573 | 1573 |
1574 void FullCodeGenerator::VisitThrow(Throw* expr) { | 1574 void FullCodeGenerator::VisitThrow(Throw* expr) { |
1575 Comment cmnt(masm_, "[ Throw"); | 1575 Comment cmnt(masm_, "[ Throw"); |
1576 VisitForStackValue(expr->exception()); | 1576 VisitForStackValue(expr->exception()); |
1577 __ CallRuntime(Runtime::kHiddenThrow, 1); | 1577 __ CallRuntime(Runtime::kThrow, 1); |
1578 // Never returns here. | 1578 // Never returns here. |
1579 } | 1579 } |
1580 | 1580 |
1581 | 1581 |
1582 FullCodeGenerator::NestedStatement* FullCodeGenerator::TryCatch::Exit( | 1582 FullCodeGenerator::NestedStatement* FullCodeGenerator::TryCatch::Exit( |
1583 int* stack_depth, | 1583 int* stack_depth, |
1584 int* context_length) { | 1584 int* context_length) { |
1585 // The macros used here must preserve the result register. | 1585 // The macros used here must preserve the result register. |
1586 __ Drop(*stack_depth); | 1586 __ Drop(*stack_depth); |
1587 __ PopTryHandler(); | 1587 __ PopTryHandler(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1698 } | 1698 } |
1699 return true; | 1699 return true; |
1700 } | 1700 } |
1701 #endif // DEBUG | 1701 #endif // DEBUG |
1702 | 1702 |
1703 | 1703 |
1704 #undef __ | 1704 #undef __ |
1705 | 1705 |
1706 | 1706 |
1707 } } // namespace v8::internal | 1707 } } // namespace v8::internal |
OLD | NEW |