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/compile-time-value.h" | 7 #include "src/ast/compile-time-value.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-info.h" | 10 #include "src/compilation-info.h" |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 BytecodeLabels* else_labels_; | 484 BytecodeLabels* else_labels_; |
485 TestFallthrough fallthrough_; | 485 TestFallthrough fallthrough_; |
486 bool result_consumed_by_test_; | 486 bool result_consumed_by_test_; |
487 | 487 |
488 DISALLOW_COPY_AND_ASSIGN(TestResultScope); | 488 DISALLOW_COPY_AND_ASSIGN(TestResultScope); |
489 }; | 489 }; |
490 | 490 |
491 // Used to build a list of global declaration initial value pairs. | 491 // Used to build a list of global declaration initial value pairs. |
492 class BytecodeGenerator::GlobalDeclarationsBuilder final : public ZoneObject { | 492 class BytecodeGenerator::GlobalDeclarationsBuilder final : public ZoneObject { |
493 public: | 493 public: |
494 explicit GlobalDeclarationsBuilder(Zone* zone) | 494 GlobalDeclarationsBuilder(Zone* zone, LazyCompilationMode mode) |
495 : declarations_(0, zone), | 495 : declarations_(0, zone), |
496 constant_pool_entry_(0), | 496 constant_pool_entry_(0), |
497 has_constant_pool_entry_(false) {} | 497 has_constant_pool_entry_(false), |
| 498 compilation_mode_(mode) {} |
498 | 499 |
499 void AddFunctionDeclaration(Handle<String> name, FeedbackVectorSlot slot, | 500 void AddFunctionDeclaration(Handle<String> name, FeedbackVectorSlot slot, |
500 FunctionLiteral* func) { | 501 FunctionLiteral* func) { |
501 DCHECK(!slot.IsInvalid()); | 502 DCHECK(!slot.IsInvalid()); |
502 declarations_.push_back(Declaration(name, slot, func)); | 503 declarations_.push_back(Declaration(name, slot, func)); |
503 } | 504 } |
504 | 505 |
505 void AddUndefinedDeclaration(Handle<String> name, FeedbackVectorSlot slot) { | 506 void AddUndefinedDeclaration(Handle<String> name, FeedbackVectorSlot slot) { |
506 DCHECK(!slot.IsInvalid()); | 507 DCHECK(!slot.IsInvalid()); |
507 declarations_.push_back(Declaration(name, slot, nullptr)); | 508 declarations_.push_back(Declaration(name, slot, nullptr)); |
508 } | 509 } |
509 | 510 |
510 Handle<FixedArray> AllocateDeclarations(CompilationInfo* info) { | 511 Handle<FixedArray> AllocateDeclarations(CompilationInfo* info) { |
511 DCHECK(has_constant_pool_entry_); | 512 DCHECK(has_constant_pool_entry_); |
512 int array_index = 0; | 513 int array_index = 0; |
513 Handle<FixedArray> data = info->isolate()->factory()->NewFixedArray( | 514 Handle<FixedArray> data = info->isolate()->factory()->NewFixedArray( |
514 static_cast<int>(declarations_.size() * 3), TENURED); | 515 static_cast<int>(declarations_.size() * 3), TENURED); |
515 for (const Declaration& declaration : declarations_) { | 516 for (const Declaration& declaration : declarations_) { |
516 FunctionLiteral* func = declaration.func; | 517 FunctionLiteral* func = declaration.func; |
517 Handle<Object> initial_value; | 518 Handle<Object> initial_value; |
518 if (func == nullptr) { | 519 if (func == nullptr) { |
519 initial_value = info->isolate()->factory()->undefined_value(); | 520 initial_value = info->isolate()->factory()->undefined_value(); |
520 } else { | 521 } else { |
521 initial_value = | 522 initial_value = Compiler::GetSharedFunctionInfo( |
522 Compiler::GetSharedFunctionInfo(func, info->script(), info); | 523 func, info->script(), info, compilation_mode_); |
523 } | 524 } |
524 | 525 |
525 // Return a null handle if any initial values can't be created. Caller | 526 // Return a null handle if any initial values can't be created. Caller |
526 // will set stack overflow. | 527 // will set stack overflow. |
527 if (initial_value.is_null()) return Handle<FixedArray>(); | 528 if (initial_value.is_null()) return Handle<FixedArray>(); |
528 | 529 |
529 data->set(array_index++, *declaration.name); | 530 data->set(array_index++, *declaration.name); |
530 data->set(array_index++, Smi::FromInt(declaration.slot.ToInt())); | 531 data->set(array_index++, Smi::FromInt(declaration.slot.ToInt())); |
531 data->set(array_index++, *initial_value); | 532 data->set(array_index++, *initial_value); |
532 } | 533 } |
(...skipping 21 matching lines...) Expand all Loading... |
554 FunctionLiteral* func) | 555 FunctionLiteral* func) |
555 : name(name), slot(slot), func(func) {} | 556 : name(name), slot(slot), func(func) {} |
556 | 557 |
557 Handle<String> name; | 558 Handle<String> name; |
558 FeedbackVectorSlot slot; | 559 FeedbackVectorSlot slot; |
559 FunctionLiteral* func; | 560 FunctionLiteral* func; |
560 }; | 561 }; |
561 ZoneVector<Declaration> declarations_; | 562 ZoneVector<Declaration> declarations_; |
562 size_t constant_pool_entry_; | 563 size_t constant_pool_entry_; |
563 bool has_constant_pool_entry_; | 564 bool has_constant_pool_entry_; |
| 565 LazyCompilationMode compilation_mode_; |
564 }; | 566 }; |
565 | 567 |
566 BytecodeGenerator::BytecodeGenerator(CompilationInfo* info) | 568 BytecodeGenerator::BytecodeGenerator(CompilationInfo* info, |
| 569 LazyCompilationMode mode) |
567 : zone_(info->zone()), | 570 : zone_(info->zone()), |
568 builder_(new (zone()) BytecodeArrayBuilder( | 571 builder_(new (zone()) BytecodeArrayBuilder( |
569 info->isolate(), info->zone(), info->num_parameters_including_this(), | 572 info->isolate(), info->zone(), info->num_parameters_including_this(), |
570 info->scope()->MaxNestedContextChainLength(), | 573 info->scope()->MaxNestedContextChainLength(), |
571 info->scope()->num_stack_slots(), info->literal(), | 574 info->scope()->num_stack_slots(), info->literal(), |
572 info->SourcePositionRecordingMode())), | 575 info->SourcePositionRecordingMode())), |
573 info_(info), | 576 info_(info), |
574 scope_(info->scope()), | 577 scope_(info->scope()), |
575 globals_builder_(new (zone()) GlobalDeclarationsBuilder(info->zone())), | 578 compilation_mode_(mode), |
| 579 globals_builder_(new (zone()) |
| 580 GlobalDeclarationsBuilder(info->zone(), mode)), |
576 global_declarations_(0, info->zone()), | 581 global_declarations_(0, info->zone()), |
577 function_literals_(0, info->zone()), | 582 function_literals_(0, info->zone()), |
578 native_function_literals_(0, info->zone()), | 583 native_function_literals_(0, info->zone()), |
579 execution_control_(nullptr), | 584 execution_control_(nullptr), |
580 execution_context_(nullptr), | 585 execution_context_(nullptr), |
581 execution_result_(nullptr), | 586 execution_result_(nullptr), |
582 generator_resume_points_(info->literal()->yield_count(), info->zone()), | 587 generator_resume_points_(info->literal()->yield_count(), info->zone()), |
583 generator_state_(), | 588 generator_state_(), |
584 loop_depth_(0), | 589 loop_depth_(0), |
585 home_object_symbol_(info->isolate()->factory()->home_object_symbol()), | 590 home_object_symbol_(info->isolate()->factory()->home_object_symbol()), |
(...skipping 18 matching lines...) Expand all Loading... |
604 Handle<FixedArray> declarations = | 609 Handle<FixedArray> declarations = |
605 globals_builder->AllocateDeclarations(info()); | 610 globals_builder->AllocateDeclarations(info()); |
606 if (declarations.is_null()) return SetStackOverflow(); | 611 if (declarations.is_null()) return SetStackOverflow(); |
607 builder()->InsertConstantPoolEntryAt(globals_builder->constant_pool_entry(), | 612 builder()->InsertConstantPoolEntryAt(globals_builder->constant_pool_entry(), |
608 declarations); | 613 declarations); |
609 } | 614 } |
610 | 615 |
611 // Find or build shared function infos. | 616 // Find or build shared function infos. |
612 for (std::pair<FunctionLiteral*, size_t> literal : function_literals_) { | 617 for (std::pair<FunctionLiteral*, size_t> literal : function_literals_) { |
613 FunctionLiteral* expr = literal.first; | 618 FunctionLiteral* expr = literal.first; |
614 Handle<SharedFunctionInfo> shared_info = | 619 Handle<SharedFunctionInfo> shared_info = Compiler::GetSharedFunctionInfo( |
615 Compiler::GetSharedFunctionInfo(expr, info()->script(), info()); | 620 expr, info()->script(), info(), compilation_mode_); |
616 if (shared_info.is_null()) return SetStackOverflow(); | 621 if (shared_info.is_null()) return SetStackOverflow(); |
617 builder()->InsertConstantPoolEntryAt(literal.second, shared_info); | 622 builder()->InsertConstantPoolEntryAt(literal.second, shared_info); |
618 } | 623 } |
619 | 624 |
620 // Find or build shared function infos for the native function templates. | 625 // Find or build shared function infos for the native function templates. |
621 for (std::pair<NativeFunctionLiteral*, size_t> literal : | 626 for (std::pair<NativeFunctionLiteral*, size_t> literal : |
622 native_function_literals_) { | 627 native_function_literals_) { |
623 NativeFunctionLiteral* expr = literal.first; | 628 NativeFunctionLiteral* expr = literal.first; |
624 Handle<SharedFunctionInfo> shared_info = | 629 Handle<SharedFunctionInfo> shared_info = |
625 Compiler::GetSharedFunctionInfoForNative(expr->extension(), | 630 Compiler::GetSharedFunctionInfoForNative(expr->extension(), |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 builder() | 947 builder() |
943 ->LoadConstantPoolEntry(globals_builder()->constant_pool_entry()) | 948 ->LoadConstantPoolEntry(globals_builder()->constant_pool_entry()) |
944 .StoreAccumulatorInRegister(args[0]) | 949 .StoreAccumulatorInRegister(args[0]) |
945 .LoadLiteral(Smi::FromInt(encoded_flags)) | 950 .LoadLiteral(Smi::FromInt(encoded_flags)) |
946 .StoreAccumulatorInRegister(args[1]) | 951 .StoreAccumulatorInRegister(args[1]) |
947 .MoveRegister(Register::function_closure(), args[2]) | 952 .MoveRegister(Register::function_closure(), args[2]) |
948 .CallRuntime(Runtime::kDeclareGlobalsForInterpreter, args); | 953 .CallRuntime(Runtime::kDeclareGlobalsForInterpreter, args); |
949 | 954 |
950 // Push and reset globals builder. | 955 // Push and reset globals builder. |
951 global_declarations_.push_back(globals_builder()); | 956 global_declarations_.push_back(globals_builder()); |
952 globals_builder_ = new (zone()) GlobalDeclarationsBuilder(zone()); | 957 globals_builder_ = |
| 958 new (zone()) GlobalDeclarationsBuilder(zone(), compilation_mode_); |
953 } | 959 } |
954 | 960 |
955 void BytecodeGenerator::VisitStatements(ZoneList<Statement*>* statements) { | 961 void BytecodeGenerator::VisitStatements(ZoneList<Statement*>* statements) { |
956 for (int i = 0; i < statements->length(); i++) { | 962 for (int i = 0; i < statements->length(); i++) { |
957 // Allocate an outer register allocations scope for the statement. | 963 // Allocate an outer register allocations scope for the statement. |
958 RegisterAllocationScope allocation_scope(this); | 964 RegisterAllocationScope allocation_scope(this); |
959 Statement* stmt = statements->at(i); | 965 Statement* stmt = statements->at(i); |
960 Visit(stmt); | 966 Visit(stmt); |
961 if (stmt->IsJump()) break; | 967 if (stmt->IsJump()) break; |
962 } | 968 } |
(...skipping 2322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3285 } | 3291 } |
3286 | 3292 |
3287 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { | 3293 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { |
3288 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | 3294 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict |
3289 : Runtime::kStoreKeyedToSuper_Sloppy; | 3295 : Runtime::kStoreKeyedToSuper_Sloppy; |
3290 } | 3296 } |
3291 | 3297 |
3292 } // namespace interpreter | 3298 } // namespace interpreter |
3293 } // namespace internal | 3299 } // namespace internal |
3294 } // namespace v8 | 3300 } // namespace v8 |
OLD | NEW |