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