| 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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 // operations, instead of calling builtins directly. | 712 // operations, instead of calling builtins directly. |
| 713 Node* reg_index = __ BytecodeOperandReg(0); | 713 Node* reg_index = __ BytecodeOperandReg(0); |
| 714 Node* lhs = __ LoadRegister(reg_index); | 714 Node* lhs = __ LoadRegister(reg_index); |
| 715 Node* rhs = __ GetAccumulator(); | 715 Node* rhs = __ GetAccumulator(); |
| 716 Node* context = __ GetContext(); | 716 Node* context = __ GetContext(); |
| 717 Node* result = __ CallRuntime(function_id, context, lhs, rhs); | 717 Node* result = __ CallRuntime(function_id, context, lhs, rhs); |
| 718 __ SetAccumulator(result); | 718 __ SetAccumulator(result); |
| 719 __ Dispatch(); | 719 __ Dispatch(); |
| 720 } | 720 } |
| 721 | 721 |
| 722 template <class Generator> | |
| 723 void Interpreter::DoBinaryOp(InterpreterAssembler* assembler) { | |
| 724 Node* reg_index = __ BytecodeOperandReg(0); | |
| 725 Node* lhs = __ LoadRegister(reg_index); | |
| 726 Node* rhs = __ GetAccumulator(); | |
| 727 Node* context = __ GetContext(); | |
| 728 Node* result = Generator::Generate(assembler, lhs, rhs, context); | |
| 729 __ SetAccumulator(result); | |
| 730 __ Dispatch(); | |
| 731 } | |
| 732 | 722 |
| 733 // Add <src> | 723 // Add <src> |
| 734 // | 724 // |
| 735 // Add register <src> to accumulator. | 725 // Add register <src> to accumulator. |
| 736 void Interpreter::DoAdd(InterpreterAssembler* assembler) { | 726 void Interpreter::DoAdd(InterpreterAssembler* assembler) { |
| 737 DoBinaryOp<AddStub>(assembler); | 727 DoBinaryOp(CodeFactory::Add(isolate_), assembler); |
| 738 } | 728 } |
| 739 | 729 |
| 740 | 730 |
| 741 // Sub <src> | 731 // Sub <src> |
| 742 // | 732 // |
| 743 // Subtract register <src> from accumulator. | 733 // Subtract register <src> from accumulator. |
| 744 void Interpreter::DoSub(InterpreterAssembler* assembler) { | 734 void Interpreter::DoSub(InterpreterAssembler* assembler) { |
| 745 DoBinaryOp<SubtractStub>(assembler); | 735 DoBinaryOp(CodeFactory::Subtract(isolate_), assembler); |
| 746 } | 736 } |
| 747 | 737 |
| 748 | 738 |
| 749 // Mul <src> | 739 // Mul <src> |
| 750 // | 740 // |
| 751 // Multiply accumulator by register <src>. | 741 // Multiply accumulator by register <src>. |
| 752 void Interpreter::DoMul(InterpreterAssembler* assembler) { | 742 void Interpreter::DoMul(InterpreterAssembler* assembler) { |
| 753 DoBinaryOp<MultiplyStub>(assembler); | 743 DoBinaryOp(CodeFactory::Multiply(isolate_), assembler); |
| 754 } | 744 } |
| 755 | 745 |
| 756 | 746 |
| 757 // Div <src> | 747 // Div <src> |
| 758 // | 748 // |
| 759 // Divide register <src> by accumulator. | 749 // Divide register <src> by accumulator. |
| 760 void Interpreter::DoDiv(InterpreterAssembler* assembler) { | 750 void Interpreter::DoDiv(InterpreterAssembler* assembler) { |
| 761 DoBinaryOp<DivideStub>(assembler); | 751 DoBinaryOp(CodeFactory::Divide(isolate_), assembler); |
| 762 } | 752 } |
| 763 | 753 |
| 764 | 754 |
| 765 // Mod <src> | 755 // Mod <src> |
| 766 // | 756 // |
| 767 // Modulo register <src> by accumulator. | 757 // Modulo register <src> by accumulator. |
| 768 void Interpreter::DoMod(InterpreterAssembler* assembler) { | 758 void Interpreter::DoMod(InterpreterAssembler* assembler) { |
| 769 DoBinaryOp<ModulusStub>(assembler); | 759 DoBinaryOp(CodeFactory::Modulus(isolate_), assembler); |
| 770 } | 760 } |
| 771 | 761 |
| 772 | 762 |
| 773 // BitwiseOr <src> | 763 // BitwiseOr <src> |
| 774 // | 764 // |
| 775 // BitwiseOr register <src> to accumulator. | 765 // BitwiseOr register <src> to accumulator. |
| 776 void Interpreter::DoBitwiseOr(InterpreterAssembler* assembler) { | 766 void Interpreter::DoBitwiseOr(InterpreterAssembler* assembler) { |
| 777 DoBinaryOp<BitwiseOrStub>(assembler); | 767 DoBinaryOp(CodeFactory::BitwiseOr(isolate_), assembler); |
| 778 } | 768 } |
| 779 | 769 |
| 780 | 770 |
| 781 // BitwiseXor <src> | 771 // BitwiseXor <src> |
| 782 // | 772 // |
| 783 // BitwiseXor register <src> to accumulator. | 773 // BitwiseXor register <src> to accumulator. |
| 784 void Interpreter::DoBitwiseXor(InterpreterAssembler* assembler) { | 774 void Interpreter::DoBitwiseXor(InterpreterAssembler* assembler) { |
| 785 DoBinaryOp<BitwiseXorStub>(assembler); | 775 DoBinaryOp(CodeFactory::BitwiseXor(isolate_), assembler); |
| 786 } | 776 } |
| 787 | 777 |
| 788 | 778 |
| 789 // BitwiseAnd <src> | 779 // BitwiseAnd <src> |
| 790 // | 780 // |
| 791 // BitwiseAnd register <src> to accumulator. | 781 // BitwiseAnd register <src> to accumulator. |
| 792 void Interpreter::DoBitwiseAnd(InterpreterAssembler* assembler) { | 782 void Interpreter::DoBitwiseAnd(InterpreterAssembler* assembler) { |
| 793 DoBinaryOp<BitwiseAndStub>(assembler); | 783 DoBinaryOp(CodeFactory::BitwiseAnd(isolate_), assembler); |
| 794 } | 784 } |
| 795 | 785 |
| 796 | 786 |
| 797 // ShiftLeft <src> | 787 // ShiftLeft <src> |
| 798 // | 788 // |
| 799 // Left shifts register <src> by the count specified in the accumulator. | 789 // Left shifts register <src> by the count specified in the accumulator. |
| 800 // Register <src> is converted to an int32 and the accumulator to uint32 | 790 // Register <src> is converted to an int32 and the accumulator to uint32 |
| 801 // before the operation. 5 lsb bits from the accumulator are used as count | 791 // before the operation. 5 lsb bits from the accumulator are used as count |
| 802 // i.e. <src> << (accumulator & 0x1F). | 792 // i.e. <src> << (accumulator & 0x1F). |
| 803 void Interpreter::DoShiftLeft(InterpreterAssembler* assembler) { | 793 void Interpreter::DoShiftLeft(InterpreterAssembler* assembler) { |
| 804 DoBinaryOp<ShiftLeftStub>(assembler); | 794 DoBinaryOp(CodeFactory::ShiftLeft(isolate_), assembler); |
| 805 } | 795 } |
| 806 | 796 |
| 807 | 797 |
| 808 // ShiftRight <src> | 798 // ShiftRight <src> |
| 809 // | 799 // |
| 810 // Right shifts register <src> by the count specified in the accumulator. | 800 // Right shifts register <src> by the count specified in the accumulator. |
| 811 // Result is sign extended. Register <src> is converted to an int32 and the | 801 // Result is sign extended. Register <src> is converted to an int32 and the |
| 812 // accumulator to uint32 before the operation. 5 lsb bits from the accumulator | 802 // accumulator to uint32 before the operation. 5 lsb bits from the accumulator |
| 813 // are used as count i.e. <src> >> (accumulator & 0x1F). | 803 // are used as count i.e. <src> >> (accumulator & 0x1F). |
| 814 void Interpreter::DoShiftRight(InterpreterAssembler* assembler) { | 804 void Interpreter::DoShiftRight(InterpreterAssembler* assembler) { |
| 815 DoBinaryOp<ShiftRightStub>(assembler); | 805 DoBinaryOp(CodeFactory::ShiftRight(isolate_), assembler); |
| 816 } | 806 } |
| 817 | 807 |
| 818 | 808 |
| 819 // ShiftRightLogical <src> | 809 // ShiftRightLogical <src> |
| 820 // | 810 // |
| 821 // Right Shifts register <src> by the count specified in the accumulator. | 811 // Right Shifts register <src> by the count specified in the accumulator. |
| 822 // Result is zero-filled. The accumulator and register <src> are converted to | 812 // Result is zero-filled. The accumulator and register <src> are converted to |
| 823 // uint32 before the operation 5 lsb bits from the accumulator are used as | 813 // uint32 before the operation 5 lsb bits from the accumulator are used as |
| 824 // count i.e. <src> << (accumulator & 0x1F). | 814 // count i.e. <src> << (accumulator & 0x1F). |
| 825 void Interpreter::DoShiftRightLogical(InterpreterAssembler* assembler) { | 815 void Interpreter::DoShiftRightLogical(InterpreterAssembler* assembler) { |
| 826 DoBinaryOp<ShiftRightLogicalStub>(assembler); | 816 DoBinaryOp(CodeFactory::ShiftRightLogical(isolate_), assembler); |
| 827 } | 817 } |
| 828 | 818 |
| 829 void Interpreter::DoCountOp(Callable callable, | 819 void Interpreter::DoCountOp(Callable callable, |
| 830 InterpreterAssembler* assembler) { | 820 InterpreterAssembler* assembler) { |
| 831 Node* target = __ HeapConstant(callable.code()); | 821 Node* target = __ HeapConstant(callable.code()); |
| 832 Node* value = __ GetAccumulator(); | 822 Node* value = __ GetAccumulator(); |
| 833 Node* context = __ GetContext(); | 823 Node* context = __ GetContext(); |
| 834 Node* result = __ CallStub(callable.descriptor(), target, context, value); | 824 Node* result = __ CallStub(callable.descriptor(), target, context, value); |
| 835 __ SetAccumulator(result); | 825 __ SetAccumulator(result); |
| 836 __ Dispatch(); | 826 __ Dispatch(); |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1777 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, | 1767 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, |
| 1778 __ SmiTag(new_state)); | 1768 __ SmiTag(new_state)); |
| 1779 __ SetAccumulator(old_state); | 1769 __ SetAccumulator(old_state); |
| 1780 | 1770 |
| 1781 __ Dispatch(); | 1771 __ Dispatch(); |
| 1782 } | 1772 } |
| 1783 | 1773 |
| 1784 } // namespace interpreter | 1774 } // namespace interpreter |
| 1785 } // namespace internal | 1775 } // namespace internal |
| 1786 } // namespace v8 | 1776 } // namespace v8 |
| OLD | NEW |