OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 NO_REGISTERS, | 76 NO_REGISTERS, |
77 TOS_REG | 77 TOS_REG |
78 }; | 78 }; |
79 | 79 |
80 explicit FullCodeGenerator(MacroAssembler* masm) | 80 explicit FullCodeGenerator(MacroAssembler* masm) |
81 : masm_(masm), | 81 : masm_(masm), |
82 info_(NULL), | 82 info_(NULL), |
83 scope_(NULL), | 83 scope_(NULL), |
84 nesting_stack_(NULL), | 84 nesting_stack_(NULL), |
85 loop_depth_(0), | 85 loop_depth_(0), |
| 86 stack_height_(0), |
86 context_(NULL), | 87 context_(NULL), |
87 bailout_entries_(0), | 88 bailout_entries_(0), |
88 stack_checks_(2), // There's always at least one. | 89 stack_checks_(2), // There's always at least one. |
89 forward_bailout_stack_(NULL), | 90 forward_bailout_stack_(NULL), |
90 forward_bailout_pending_(NULL) { | 91 forward_bailout_pending_(NULL) { |
91 } | 92 } |
92 | 93 |
93 static bool MakeCode(CompilationInfo* info); | 94 static bool MakeCode(CompilationInfo* info); |
94 | 95 |
95 void Generate(CompilationInfo* info); | 96 void Generate(CompilationInfo* info); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 void ExitFinallyBlock(); | 513 void ExitFinallyBlock(); |
513 | 514 |
514 // Loop nesting counter. | 515 // Loop nesting counter. |
515 int loop_depth() { return loop_depth_; } | 516 int loop_depth() { return loop_depth_; } |
516 void increment_loop_depth() { loop_depth_++; } | 517 void increment_loop_depth() { loop_depth_++; } |
517 void decrement_loop_depth() { | 518 void decrement_loop_depth() { |
518 ASSERT(loop_depth_ > 0); | 519 ASSERT(loop_depth_ > 0); |
519 loop_depth_--; | 520 loop_depth_--; |
520 } | 521 } |
521 | 522 |
| 523 #if defined(V8_TARGET_ARCH_IA32) |
| 524 int stack_height() { return stack_height_; } |
| 525 void set_stack_height(int depth) { stack_height_ = depth; } |
| 526 void increment_stack_height() { stack_height_++; } |
| 527 void increment_stack_height(int delta) { stack_height_ += delta; } |
| 528 void decrement_stack_height() { |
| 529 if (FLAG_verify_stack_height) { |
| 530 ASSERT(stack_height_ > 0); |
| 531 } |
| 532 stack_height_--; |
| 533 } |
| 534 void decrement_stack_height(int delta) { |
| 535 stack_height_-= delta; |
| 536 if (FLAG_verify_stack_height) { |
| 537 ASSERT(stack_height_ >= 0); |
| 538 } |
| 539 } |
| 540 // Call this function only if FLAG_verify_stack_height is true. |
| 541 void verify_stack_height(); // Generates a runtime check of esp - ebp. |
| 542 #else |
| 543 int stack_height() { return 0; } |
| 544 void set_stack_height(int depth) {} |
| 545 void increment_stack_height() {} |
| 546 void increment_stack_height(int delta) {} |
| 547 void decrement_stack_height() {} |
| 548 void decrement_stack_height(int delta) {} |
| 549 void verify_stack_height() {} |
| 550 #endif // V8_TARGET_ARCH_IA32 |
| 551 |
522 MacroAssembler* masm() { return masm_; } | 552 MacroAssembler* masm() { return masm_; } |
523 | 553 |
524 class ExpressionContext; | 554 class ExpressionContext; |
525 const ExpressionContext* context() { return context_; } | 555 const ExpressionContext* context() { return context_; } |
526 void set_new_context(const ExpressionContext* context) { context_ = context; } | 556 void set_new_context(const ExpressionContext* context) { context_ = context; } |
527 | 557 |
528 Handle<Script> script() { return info_->script(); } | 558 Handle<Script> script() { return info_->script(); } |
529 bool is_eval() { return info_->is_eval(); } | 559 bool is_eval() { return info_->is_eval(); } |
530 bool is_strict_mode() { return function()->strict_mode(); } | 560 bool is_strict_mode() { return function()->strict_mode(); } |
531 StrictModeFlag strict_mode_flag() { | 561 StrictModeFlag strict_mode_flag() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 601 |
572 class ExpressionContext BASE_EMBEDDED { | 602 class ExpressionContext BASE_EMBEDDED { |
573 public: | 603 public: |
574 explicit ExpressionContext(FullCodeGenerator* codegen) | 604 explicit ExpressionContext(FullCodeGenerator* codegen) |
575 : masm_(codegen->masm()), old_(codegen->context()), codegen_(codegen) { | 605 : masm_(codegen->masm()), old_(codegen->context()), codegen_(codegen) { |
576 codegen->set_new_context(this); | 606 codegen->set_new_context(this); |
577 } | 607 } |
578 | 608 |
579 virtual ~ExpressionContext() { | 609 virtual ~ExpressionContext() { |
580 codegen_->set_new_context(old_); | 610 codegen_->set_new_context(old_); |
| 611 if (FLAG_verify_stack_height) { |
| 612 ASSERT_EQ(expected_stack_height_, codegen()->stack_height()); |
| 613 codegen()->verify_stack_height(); |
| 614 } |
581 } | 615 } |
582 | 616 |
583 Isolate* isolate() const { return codegen_->isolate(); } | 617 Isolate* isolate() const { return codegen_->isolate(); } |
584 | 618 |
585 // Convert constant control flow (true or false) to the result expected for | 619 // Convert constant control flow (true or false) to the result expected for |
586 // this expression context. | 620 // this expression context. |
587 virtual void Plug(bool flag) const = 0; | 621 virtual void Plug(bool flag) const = 0; |
588 | 622 |
589 // Emit code to convert a pure value (in a register, slot, as a literal, | 623 // Emit code to convert a pure value (in a register, slot, as a literal, |
590 // or on top of the stack) into the result expected according to this | 624 // or on top of the stack) into the result expected according to this |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 virtual bool IsStackValue() const { return false; } | 658 virtual bool IsStackValue() const { return false; } |
625 | 659 |
626 // Returns true if we are branching on the value rather than materializing | 660 // Returns true if we are branching on the value rather than materializing |
627 // it. Only used for asserts. | 661 // it. Only used for asserts. |
628 virtual bool IsTest() const { return false; } | 662 virtual bool IsTest() const { return false; } |
629 | 663 |
630 protected: | 664 protected: |
631 FullCodeGenerator* codegen() const { return codegen_; } | 665 FullCodeGenerator* codegen() const { return codegen_; } |
632 MacroAssembler* masm() const { return masm_; } | 666 MacroAssembler* masm() const { return masm_; } |
633 MacroAssembler* masm_; | 667 MacroAssembler* masm_; |
| 668 int expected_stack_height_; // The expected stack height esp - ebp on exit. |
634 | 669 |
635 private: | 670 private: |
636 const ExpressionContext* old_; | 671 const ExpressionContext* old_; |
637 FullCodeGenerator* codegen_; | 672 FullCodeGenerator* codegen_; |
638 }; | 673 }; |
639 | 674 |
640 class AccumulatorValueContext : public ExpressionContext { | 675 class AccumulatorValueContext : public ExpressionContext { |
641 public: | 676 public: |
642 explicit AccumulatorValueContext(FullCodeGenerator* codegen) | 677 explicit AccumulatorValueContext(FullCodeGenerator* codegen) |
643 : ExpressionContext(codegen) { } | 678 : ExpressionContext(codegen) { |
| 679 expected_stack_height_ = codegen->stack_height(); |
| 680 } |
644 | 681 |
645 virtual void Plug(bool flag) const; | 682 virtual void Plug(bool flag) const; |
646 virtual void Plug(Register reg) const; | 683 virtual void Plug(Register reg) const; |
647 virtual void Plug(Label* materialize_true, Label* materialize_false) const; | 684 virtual void Plug(Label* materialize_true, Label* materialize_false) const; |
648 virtual void Plug(Slot* slot) const; | 685 virtual void Plug(Slot* slot) const; |
649 virtual void Plug(Handle<Object> lit) const; | 686 virtual void Plug(Handle<Object> lit) const; |
650 virtual void Plug(Heap::RootListIndex) const; | 687 virtual void Plug(Heap::RootListIndex) const; |
651 virtual void PlugTOS() const; | 688 virtual void PlugTOS() const; |
652 virtual void DropAndPlug(int count, Register reg) const; | 689 virtual void DropAndPlug(int count, Register reg) const; |
653 virtual void PrepareTest(Label* materialize_true, | 690 virtual void PrepareTest(Label* materialize_true, |
654 Label* materialize_false, | 691 Label* materialize_false, |
655 Label** if_true, | 692 Label** if_true, |
656 Label** if_false, | 693 Label** if_false, |
657 Label** fall_through) const; | 694 Label** fall_through) const; |
658 virtual bool IsAccumulatorValue() const { return true; } | 695 virtual bool IsAccumulatorValue() const { return true; } |
659 }; | 696 }; |
660 | 697 |
661 class StackValueContext : public ExpressionContext { | 698 class StackValueContext : public ExpressionContext { |
662 public: | 699 public: |
663 explicit StackValueContext(FullCodeGenerator* codegen) | 700 explicit StackValueContext(FullCodeGenerator* codegen) |
664 : ExpressionContext(codegen) { } | 701 : ExpressionContext(codegen) { |
| 702 expected_stack_height_ = codegen->stack_height() + 1; |
| 703 } |
665 | 704 |
666 virtual void Plug(bool flag) const; | 705 virtual void Plug(bool flag) const; |
667 virtual void Plug(Register reg) const; | 706 virtual void Plug(Register reg) const; |
668 virtual void Plug(Label* materialize_true, Label* materialize_false) const; | 707 virtual void Plug(Label* materialize_true, Label* materialize_false) const; |
669 virtual void Plug(Slot* slot) const; | 708 virtual void Plug(Slot* slot) const; |
670 virtual void Plug(Handle<Object> lit) const; | 709 virtual void Plug(Handle<Object> lit) const; |
671 virtual void Plug(Heap::RootListIndex) const; | 710 virtual void Plug(Heap::RootListIndex) const; |
672 virtual void PlugTOS() const; | 711 virtual void PlugTOS() const; |
673 virtual void DropAndPlug(int count, Register reg) const; | 712 virtual void DropAndPlug(int count, Register reg) const; |
674 virtual void PrepareTest(Label* materialize_true, | 713 virtual void PrepareTest(Label* materialize_true, |
675 Label* materialize_false, | 714 Label* materialize_false, |
676 Label** if_true, | 715 Label** if_true, |
677 Label** if_false, | 716 Label** if_false, |
678 Label** fall_through) const; | 717 Label** fall_through) const; |
679 virtual bool IsStackValue() const { return true; } | 718 virtual bool IsStackValue() const { return true; } |
680 }; | 719 }; |
681 | 720 |
682 class TestContext : public ExpressionContext { | 721 class TestContext : public ExpressionContext { |
683 public: | 722 public: |
684 TestContext(FullCodeGenerator* codegen, | 723 TestContext(FullCodeGenerator* codegen, |
685 Expression* condition, | 724 Expression* condition, |
686 Label* true_label, | 725 Label* true_label, |
687 Label* false_label, | 726 Label* false_label, |
688 Label* fall_through) | 727 Label* fall_through) |
689 : ExpressionContext(codegen), | 728 : ExpressionContext(codegen), |
690 condition_(condition), | 729 condition_(condition), |
691 true_label_(true_label), | 730 true_label_(true_label), |
692 false_label_(false_label), | 731 false_label_(false_label), |
693 fall_through_(fall_through) { } | 732 fall_through_(fall_through) { |
| 733 expected_stack_height_ = codegen->stack_height(); |
| 734 } |
694 | 735 |
695 static const TestContext* cast(const ExpressionContext* context) { | 736 static const TestContext* cast(const ExpressionContext* context) { |
696 ASSERT(context->IsTest()); | 737 ASSERT(context->IsTest()); |
697 return reinterpret_cast<const TestContext*>(context); | 738 return reinterpret_cast<const TestContext*>(context); |
698 } | 739 } |
699 | 740 |
700 Expression* condition() const { return condition_; } | 741 Expression* condition() const { return condition_; } |
701 Label* true_label() const { return true_label_; } | 742 Label* true_label() const { return true_label_; } |
702 Label* false_label() const { return false_label_; } | 743 Label* false_label() const { return false_label_; } |
703 Label* fall_through() const { return fall_through_; } | 744 Label* fall_through() const { return fall_through_; } |
(...skipping 16 matching lines...) Expand all Loading... |
720 private: | 761 private: |
721 Expression* condition_; | 762 Expression* condition_; |
722 Label* true_label_; | 763 Label* true_label_; |
723 Label* false_label_; | 764 Label* false_label_; |
724 Label* fall_through_; | 765 Label* fall_through_; |
725 }; | 766 }; |
726 | 767 |
727 class EffectContext : public ExpressionContext { | 768 class EffectContext : public ExpressionContext { |
728 public: | 769 public: |
729 explicit EffectContext(FullCodeGenerator* codegen) | 770 explicit EffectContext(FullCodeGenerator* codegen) |
730 : ExpressionContext(codegen) { } | 771 : ExpressionContext(codegen) { |
| 772 expected_stack_height_ = codegen->stack_height(); |
| 773 } |
| 774 |
731 | 775 |
732 virtual void Plug(bool flag) const; | 776 virtual void Plug(bool flag) const; |
733 virtual void Plug(Register reg) const; | 777 virtual void Plug(Register reg) const; |
734 virtual void Plug(Label* materialize_true, Label* materialize_false) const; | 778 virtual void Plug(Label* materialize_true, Label* materialize_false) const; |
735 virtual void Plug(Slot* slot) const; | 779 virtual void Plug(Slot* slot) const; |
736 virtual void Plug(Handle<Object> lit) const; | 780 virtual void Plug(Handle<Object> lit) const; |
737 virtual void Plug(Heap::RootListIndex) const; | 781 virtual void Plug(Heap::RootListIndex) const; |
738 virtual void PlugTOS() const; | 782 virtual void PlugTOS() const; |
739 virtual void DropAndPlug(int count, Register reg) const; | 783 virtual void DropAndPlug(int count, Register reg) const; |
740 virtual void PrepareTest(Label* materialize_true, | 784 virtual void PrepareTest(Label* materialize_true, |
741 Label* materialize_false, | 785 Label* materialize_false, |
742 Label** if_true, | 786 Label** if_true, |
743 Label** if_false, | 787 Label** if_false, |
744 Label** fall_through) const; | 788 Label** fall_through) const; |
745 virtual bool IsEffect() const { return true; } | 789 virtual bool IsEffect() const { return true; } |
746 }; | 790 }; |
747 | 791 |
748 MacroAssembler* masm_; | 792 MacroAssembler* masm_; |
749 CompilationInfo* info_; | 793 CompilationInfo* info_; |
750 Scope* scope_; | 794 Scope* scope_; |
751 Label return_label_; | 795 Label return_label_; |
752 NestedStatement* nesting_stack_; | 796 NestedStatement* nesting_stack_; |
753 int loop_depth_; | 797 int loop_depth_; |
| 798 int stack_height_; |
754 const ExpressionContext* context_; | 799 const ExpressionContext* context_; |
755 ZoneList<BailoutEntry> bailout_entries_; | 800 ZoneList<BailoutEntry> bailout_entries_; |
756 ZoneList<BailoutEntry> stack_checks_; | 801 ZoneList<BailoutEntry> stack_checks_; |
757 ForwardBailoutStack* forward_bailout_stack_; | 802 ForwardBailoutStack* forward_bailout_stack_; |
758 ForwardBailoutStack* forward_bailout_pending_; | 803 ForwardBailoutStack* forward_bailout_pending_; |
759 | 804 |
760 friend class NestedStatement; | 805 friend class NestedStatement; |
761 | 806 |
762 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator); | 807 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator); |
763 }; | 808 }; |
764 | 809 |
765 | 810 |
766 } } // namespace v8::internal | 811 } } // namespace v8::internal |
767 | 812 |
768 #endif // V8_FULL_CODEGEN_H_ | 813 #endif // V8_FULL_CODEGEN_H_ |
OLD | NEW |