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