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/interpreter.h" | 5 #include "src/interpreter/interpreter.h" |
6 | 6 |
7 #include <fstream> | 7 #include <fstream> |
8 | 8 |
9 #include "src/ast/prettyprinter.h" | 9 #include "src/ast/prettyprinter.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 // operations, instead of calling builtins directly. | 720 // operations, instead of calling builtins directly. |
721 Node* reg_index = __ BytecodeOperandReg(0); | 721 Node* reg_index = __ BytecodeOperandReg(0); |
722 Node* lhs = __ LoadRegister(reg_index); | 722 Node* lhs = __ LoadRegister(reg_index); |
723 Node* rhs = __ GetAccumulator(); | 723 Node* rhs = __ GetAccumulator(); |
724 Node* context = __ GetContext(); | 724 Node* context = __ GetContext(); |
725 Node* result = __ CallRuntime(function_id, context, lhs, rhs); | 725 Node* result = __ CallRuntime(function_id, context, lhs, rhs); |
726 __ SetAccumulator(result); | 726 __ SetAccumulator(result); |
727 __ Dispatch(); | 727 __ Dispatch(); |
728 } | 728 } |
729 | 729 |
| 730 template <class Generator> |
| 731 void Interpreter::DoBinaryOp(InterpreterAssembler* assembler) { |
| 732 Node* reg_index = __ BytecodeOperandReg(0); |
| 733 Node* lhs = __ LoadRegister(reg_index); |
| 734 Node* rhs = __ GetAccumulator(); |
| 735 Node* context = __ GetContext(); |
| 736 Node* result = Generator::Generate(assembler, lhs, rhs, context); |
| 737 __ SetAccumulator(result); |
| 738 __ Dispatch(); |
| 739 } |
730 | 740 |
731 // Add <src> | 741 // Add <src> |
732 // | 742 // |
733 // Add register <src> to accumulator. | 743 // Add register <src> to accumulator. |
734 void Interpreter::DoAdd(InterpreterAssembler* assembler) { | 744 void Interpreter::DoAdd(InterpreterAssembler* assembler) { |
735 DoBinaryOp(CodeFactory::Add(isolate_), assembler); | 745 DoBinaryOp<AddStub>(assembler); |
736 } | 746 } |
737 | 747 |
738 | 748 |
739 // Sub <src> | 749 // Sub <src> |
740 // | 750 // |
741 // Subtract register <src> from accumulator. | 751 // Subtract register <src> from accumulator. |
742 void Interpreter::DoSub(InterpreterAssembler* assembler) { | 752 void Interpreter::DoSub(InterpreterAssembler* assembler) { |
743 DoBinaryOp(CodeFactory::Subtract(isolate_), assembler); | 753 DoBinaryOp<SubtractStub>(assembler); |
744 } | 754 } |
745 | 755 |
746 | 756 |
747 // Mul <src> | 757 // Mul <src> |
748 // | 758 // |
749 // Multiply accumulator by register <src>. | 759 // Multiply accumulator by register <src>. |
750 void Interpreter::DoMul(InterpreterAssembler* assembler) { | 760 void Interpreter::DoMul(InterpreterAssembler* assembler) { |
751 DoBinaryOp(CodeFactory::Multiply(isolate_), assembler); | 761 DoBinaryOp<MultiplyStub>(assembler); |
752 } | 762 } |
753 | 763 |
754 | 764 |
755 // Div <src> | 765 // Div <src> |
756 // | 766 // |
757 // Divide register <src> by accumulator. | 767 // Divide register <src> by accumulator. |
758 void Interpreter::DoDiv(InterpreterAssembler* assembler) { | 768 void Interpreter::DoDiv(InterpreterAssembler* assembler) { |
759 DoBinaryOp(CodeFactory::Divide(isolate_), assembler); | 769 DoBinaryOp<DivideStub>(assembler); |
760 } | 770 } |
761 | 771 |
762 | 772 |
763 // Mod <src> | 773 // Mod <src> |
764 // | 774 // |
765 // Modulo register <src> by accumulator. | 775 // Modulo register <src> by accumulator. |
766 void Interpreter::DoMod(InterpreterAssembler* assembler) { | 776 void Interpreter::DoMod(InterpreterAssembler* assembler) { |
767 DoBinaryOp(CodeFactory::Modulus(isolate_), assembler); | 777 DoBinaryOp<ModulusStub>(assembler); |
768 } | 778 } |
769 | 779 |
770 | 780 |
771 // BitwiseOr <src> | 781 // BitwiseOr <src> |
772 // | 782 // |
773 // BitwiseOr register <src> to accumulator. | 783 // BitwiseOr register <src> to accumulator. |
774 void Interpreter::DoBitwiseOr(InterpreterAssembler* assembler) { | 784 void Interpreter::DoBitwiseOr(InterpreterAssembler* assembler) { |
775 DoBinaryOp(CodeFactory::BitwiseOr(isolate_), assembler); | 785 DoBinaryOp<BitwiseOrStub>(assembler); |
776 } | 786 } |
777 | 787 |
778 | 788 |
779 // BitwiseXor <src> | 789 // BitwiseXor <src> |
780 // | 790 // |
781 // BitwiseXor register <src> to accumulator. | 791 // BitwiseXor register <src> to accumulator. |
782 void Interpreter::DoBitwiseXor(InterpreterAssembler* assembler) { | 792 void Interpreter::DoBitwiseXor(InterpreterAssembler* assembler) { |
783 DoBinaryOp(CodeFactory::BitwiseXor(isolate_), assembler); | 793 DoBinaryOp<BitwiseXorStub>(assembler); |
784 } | 794 } |
785 | 795 |
786 | 796 |
787 // BitwiseAnd <src> | 797 // BitwiseAnd <src> |
788 // | 798 // |
789 // BitwiseAnd register <src> to accumulator. | 799 // BitwiseAnd register <src> to accumulator. |
790 void Interpreter::DoBitwiseAnd(InterpreterAssembler* assembler) { | 800 void Interpreter::DoBitwiseAnd(InterpreterAssembler* assembler) { |
791 DoBinaryOp(CodeFactory::BitwiseAnd(isolate_), assembler); | 801 DoBinaryOp<BitwiseAndStub>(assembler); |
792 } | 802 } |
793 | 803 |
794 | 804 |
795 // ShiftLeft <src> | 805 // ShiftLeft <src> |
796 // | 806 // |
797 // Left shifts register <src> by the count specified in the accumulator. | 807 // Left shifts register <src> by the count specified in the accumulator. |
798 // Register <src> is converted to an int32 and the accumulator to uint32 | 808 // Register <src> is converted to an int32 and the accumulator to uint32 |
799 // before the operation. 5 lsb bits from the accumulator are used as count | 809 // before the operation. 5 lsb bits from the accumulator are used as count |
800 // i.e. <src> << (accumulator & 0x1F). | 810 // i.e. <src> << (accumulator & 0x1F). |
801 void Interpreter::DoShiftLeft(InterpreterAssembler* assembler) { | 811 void Interpreter::DoShiftLeft(InterpreterAssembler* assembler) { |
802 DoBinaryOp(CodeFactory::ShiftLeft(isolate_), assembler); | 812 DoBinaryOp<ShiftLeftStub>(assembler); |
803 } | 813 } |
804 | 814 |
805 | 815 |
806 // ShiftRight <src> | 816 // ShiftRight <src> |
807 // | 817 // |
808 // Right shifts register <src> by the count specified in the accumulator. | 818 // Right shifts register <src> by the count specified in the accumulator. |
809 // Result is sign extended. Register <src> is converted to an int32 and the | 819 // Result is sign extended. Register <src> is converted to an int32 and the |
810 // accumulator to uint32 before the operation. 5 lsb bits from the accumulator | 820 // accumulator to uint32 before the operation. 5 lsb bits from the accumulator |
811 // are used as count i.e. <src> >> (accumulator & 0x1F). | 821 // are used as count i.e. <src> >> (accumulator & 0x1F). |
812 void Interpreter::DoShiftRight(InterpreterAssembler* assembler) { | 822 void Interpreter::DoShiftRight(InterpreterAssembler* assembler) { |
813 DoBinaryOp(CodeFactory::ShiftRight(isolate_), assembler); | 823 DoBinaryOp<ShiftRightStub>(assembler); |
814 } | 824 } |
815 | 825 |
816 | 826 |
817 // ShiftRightLogical <src> | 827 // ShiftRightLogical <src> |
818 // | 828 // |
819 // Right Shifts register <src> by the count specified in the accumulator. | 829 // Right Shifts register <src> by the count specified in the accumulator. |
820 // Result is zero-filled. The accumulator and register <src> are converted to | 830 // Result is zero-filled. The accumulator and register <src> are converted to |
821 // uint32 before the operation 5 lsb bits from the accumulator are used as | 831 // uint32 before the operation 5 lsb bits from the accumulator are used as |
822 // count i.e. <src> << (accumulator & 0x1F). | 832 // count i.e. <src> << (accumulator & 0x1F). |
823 void Interpreter::DoShiftRightLogical(InterpreterAssembler* assembler) { | 833 void Interpreter::DoShiftRightLogical(InterpreterAssembler* assembler) { |
824 DoBinaryOp(CodeFactory::ShiftRightLogical(isolate_), assembler); | 834 DoBinaryOp<ShiftRightLogicalStub>(assembler); |
825 } | 835 } |
826 | 836 |
827 void Interpreter::DoCountOp(Callable callable, | 837 void Interpreter::DoCountOp(Callable callable, |
828 InterpreterAssembler* assembler) { | 838 InterpreterAssembler* assembler) { |
829 Node* target = __ HeapConstant(callable.code()); | 839 Node* target = __ HeapConstant(callable.code()); |
830 Node* value = __ GetAccumulator(); | 840 Node* value = __ GetAccumulator(); |
831 Node* context = __ GetContext(); | 841 Node* context = __ GetContext(); |
832 Node* result = __ CallStub(callable.descriptor(), target, context, value); | 842 Node* result = __ CallStub(callable.descriptor(), target, context, value); |
833 __ SetAccumulator(result); | 843 __ SetAccumulator(result); |
834 __ Dispatch(); | 844 __ Dispatch(); |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1827 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, | 1837 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, |
1828 __ SmiTag(new_state)); | 1838 __ SmiTag(new_state)); |
1829 __ SetAccumulator(old_state); | 1839 __ SetAccumulator(old_state); |
1830 | 1840 |
1831 __ Dispatch(); | 1841 __ Dispatch(); |
1832 } | 1842 } |
1833 | 1843 |
1834 } // namespace interpreter | 1844 } // namespace interpreter |
1835 } // namespace internal | 1845 } // namespace internal |
1836 } // namespace v8 | 1846 } // namespace v8 |
OLD | NEW |