Chromium Code Reviews| 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 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 // operations, instead of calling builtins directly. | 700 // operations, instead of calling builtins directly. |
| 701 Node* reg_index = __ BytecodeOperandReg(0); | 701 Node* reg_index = __ BytecodeOperandReg(0); |
| 702 Node* lhs = __ LoadRegister(reg_index); | 702 Node* lhs = __ LoadRegister(reg_index); |
| 703 Node* rhs = __ GetAccumulator(); | 703 Node* rhs = __ GetAccumulator(); |
| 704 Node* context = __ GetContext(); | 704 Node* context = __ GetContext(); |
| 705 Node* result = __ CallRuntime(function_id, context, lhs, rhs); | 705 Node* result = __ CallRuntime(function_id, context, lhs, rhs); |
| 706 __ SetAccumulator(result); | 706 __ SetAccumulator(result); |
| 707 __ Dispatch(); | 707 __ Dispatch(); |
| 708 } | 708 } |
| 709 | 709 |
| 710 void Interpreter::DoBinaryOp(Node* (*generator)(CodeStubAssembler*, Node*, | |
|
Benedikt Meurer
2016/04/20 08:42:33
Please no naked function pointers here, as discuss
epertoso
2016/04/20 08:59:49
Done.
| |
| 711 Node*, Node*), | |
| 712 InterpreterAssembler* assembler) { | |
| 713 Node* reg_index = __ BytecodeOperandReg(0); | |
| 714 Node* lhs = __ LoadRegister(reg_index); | |
| 715 Node* rhs = __ GetAccumulator(); | |
| 716 Node* context = __ GetContext(); | |
| 717 Node* result = generator(assembler, lhs, rhs, context); | |
| 718 __ SetAccumulator(result); | |
| 719 __ Dispatch(); | |
| 720 } | |
| 710 | 721 |
| 711 // Add <src> | 722 // Add <src> |
| 712 // | 723 // |
| 713 // Add register <src> to accumulator. | 724 // Add register <src> to accumulator. |
| 714 void Interpreter::DoAdd(InterpreterAssembler* assembler) { | 725 void Interpreter::DoAdd(InterpreterAssembler* assembler) { |
| 715 DoBinaryOp(CodeFactory::Add(isolate_), assembler); | 726 DoBinaryOp(AddStub::Generate, assembler); |
| 716 } | 727 } |
| 717 | 728 |
| 718 | 729 |
| 719 // Sub <src> | 730 // Sub <src> |
| 720 // | 731 // |
| 721 // Subtract register <src> from accumulator. | 732 // Subtract register <src> from accumulator. |
| 722 void Interpreter::DoSub(InterpreterAssembler* assembler) { | 733 void Interpreter::DoSub(InterpreterAssembler* assembler) { |
| 723 DoBinaryOp(CodeFactory::Subtract(isolate_), assembler); | 734 DoBinaryOp(SubtractStub::Generate, assembler); |
| 724 } | 735 } |
| 725 | 736 |
| 726 | 737 |
| 727 // Mul <src> | 738 // Mul <src> |
| 728 // | 739 // |
| 729 // Multiply accumulator by register <src>. | 740 // Multiply accumulator by register <src>. |
| 730 void Interpreter::DoMul(InterpreterAssembler* assembler) { | 741 void Interpreter::DoMul(InterpreterAssembler* assembler) { |
| 731 DoBinaryOp(CodeFactory::Multiply(isolate_), assembler); | 742 DoBinaryOp(MultiplyStub::Generate, assembler); |
| 732 } | 743 } |
| 733 | 744 |
| 734 | 745 |
| 735 // Div <src> | 746 // Div <src> |
| 736 // | 747 // |
| 737 // Divide register <src> by accumulator. | 748 // Divide register <src> by accumulator. |
| 738 void Interpreter::DoDiv(InterpreterAssembler* assembler) { | 749 void Interpreter::DoDiv(InterpreterAssembler* assembler) { |
| 739 DoBinaryOp(CodeFactory::Divide(isolate_), assembler); | 750 DoBinaryOp(DivideStub::Generate, assembler); |
| 740 } | 751 } |
| 741 | 752 |
| 742 | 753 |
| 743 // Mod <src> | 754 // Mod <src> |
| 744 // | 755 // |
| 745 // Modulo register <src> by accumulator. | 756 // Modulo register <src> by accumulator. |
| 746 void Interpreter::DoMod(InterpreterAssembler* assembler) { | 757 void Interpreter::DoMod(InterpreterAssembler* assembler) { |
| 747 DoBinaryOp(CodeFactory::Modulus(isolate_), assembler); | 758 DoBinaryOp(ModulusStub::Generate, assembler); |
| 748 } | 759 } |
| 749 | 760 |
| 750 | 761 |
| 751 // BitwiseOr <src> | 762 // BitwiseOr <src> |
| 752 // | 763 // |
| 753 // BitwiseOr register <src> to accumulator. | 764 // BitwiseOr register <src> to accumulator. |
| 754 void Interpreter::DoBitwiseOr(InterpreterAssembler* assembler) { | 765 void Interpreter::DoBitwiseOr(InterpreterAssembler* assembler) { |
| 755 DoBinaryOp(CodeFactory::BitwiseOr(isolate_), assembler); | 766 DoBinaryOp(BitwiseOrStub::Generate, assembler); |
| 756 } | 767 } |
| 757 | 768 |
| 758 | 769 |
| 759 // BitwiseXor <src> | 770 // BitwiseXor <src> |
| 760 // | 771 // |
| 761 // BitwiseXor register <src> to accumulator. | 772 // BitwiseXor register <src> to accumulator. |
| 762 void Interpreter::DoBitwiseXor(InterpreterAssembler* assembler) { | 773 void Interpreter::DoBitwiseXor(InterpreterAssembler* assembler) { |
| 763 DoBinaryOp(CodeFactory::BitwiseXor(isolate_), assembler); | 774 DoBinaryOp(BitwiseXorStub::Generate, assembler); |
| 764 } | 775 } |
| 765 | 776 |
| 766 | 777 |
| 767 // BitwiseAnd <src> | 778 // BitwiseAnd <src> |
| 768 // | 779 // |
| 769 // BitwiseAnd register <src> to accumulator. | 780 // BitwiseAnd register <src> to accumulator. |
| 770 void Interpreter::DoBitwiseAnd(InterpreterAssembler* assembler) { | 781 void Interpreter::DoBitwiseAnd(InterpreterAssembler* assembler) { |
| 771 DoBinaryOp(CodeFactory::BitwiseAnd(isolate_), assembler); | 782 DoBinaryOp(BitwiseAndStub::Generate, assembler); |
| 772 } | 783 } |
| 773 | 784 |
| 774 | 785 |
| 775 // ShiftLeft <src> | 786 // ShiftLeft <src> |
| 776 // | 787 // |
| 777 // Left shifts register <src> by the count specified in the accumulator. | 788 // Left shifts register <src> by the count specified in the accumulator. |
| 778 // Register <src> is converted to an int32 and the accumulator to uint32 | 789 // Register <src> is converted to an int32 and the accumulator to uint32 |
| 779 // before the operation. 5 lsb bits from the accumulator are used as count | 790 // before the operation. 5 lsb bits from the accumulator are used as count |
| 780 // i.e. <src> << (accumulator & 0x1F). | 791 // i.e. <src> << (accumulator & 0x1F). |
| 781 void Interpreter::DoShiftLeft(InterpreterAssembler* assembler) { | 792 void Interpreter::DoShiftLeft(InterpreterAssembler* assembler) { |
| 782 DoBinaryOp(CodeFactory::ShiftLeft(isolate_), assembler); | 793 DoBinaryOp(ShiftLeftStub::Generate, assembler); |
| 783 } | 794 } |
| 784 | 795 |
| 785 | 796 |
| 786 // ShiftRight <src> | 797 // ShiftRight <src> |
| 787 // | 798 // |
| 788 // Right shifts register <src> by the count specified in the accumulator. | 799 // Right shifts register <src> by the count specified in the accumulator. |
| 789 // Result is sign extended. Register <src> is converted to an int32 and the | 800 // Result is sign extended. Register <src> is converted to an int32 and the |
| 790 // accumulator to uint32 before the operation. 5 lsb bits from the accumulator | 801 // accumulator to uint32 before the operation. 5 lsb bits from the accumulator |
| 791 // are used as count i.e. <src> >> (accumulator & 0x1F). | 802 // are used as count i.e. <src> >> (accumulator & 0x1F). |
| 792 void Interpreter::DoShiftRight(InterpreterAssembler* assembler) { | 803 void Interpreter::DoShiftRight(InterpreterAssembler* assembler) { |
| 793 DoBinaryOp(CodeFactory::ShiftRight(isolate_), assembler); | 804 DoBinaryOp(ShiftRightStub::Generate, assembler); |
| 794 } | 805 } |
| 795 | 806 |
| 796 | 807 |
| 797 // ShiftRightLogical <src> | 808 // ShiftRightLogical <src> |
| 798 // | 809 // |
| 799 // Right Shifts register <src> by the count specified in the accumulator. | 810 // Right Shifts register <src> by the count specified in the accumulator. |
| 800 // Result is zero-filled. The accumulator and register <src> are converted to | 811 // Result is zero-filled. The accumulator and register <src> are converted to |
| 801 // uint32 before the operation 5 lsb bits from the accumulator are used as | 812 // uint32 before the operation 5 lsb bits from the accumulator are used as |
| 802 // count i.e. <src> << (accumulator & 0x1F). | 813 // count i.e. <src> << (accumulator & 0x1F). |
| 803 void Interpreter::DoShiftRightLogical(InterpreterAssembler* assembler) { | 814 void Interpreter::DoShiftRightLogical(InterpreterAssembler* assembler) { |
| 804 DoBinaryOp(CodeFactory::ShiftRightLogical(isolate_), assembler); | 815 DoBinaryOp(ShiftRightLogicalStub::Generate, assembler); |
| 805 } | 816 } |
| 806 | 817 |
| 807 void Interpreter::DoCountOp(Runtime::FunctionId function_id, | 818 void Interpreter::DoCountOp(Runtime::FunctionId function_id, |
| 808 InterpreterAssembler* assembler) { | 819 InterpreterAssembler* assembler) { |
| 809 Node* value = __ GetAccumulator(); | 820 Node* value = __ GetAccumulator(); |
| 810 Node* one = __ NumberConstant(1); | 821 Node* one = __ NumberConstant(1); |
| 811 Node* context = __ GetContext(); | 822 Node* context = __ GetContext(); |
| 812 Node* result = __ CallRuntime(function_id, context, value, one); | 823 Node* result = __ CallRuntime(function_id, context, value, one); |
| 813 __ SetAccumulator(result); | 824 __ SetAccumulator(result); |
| 814 __ Dispatch(); | 825 __ Dispatch(); |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1681 // Illegal | 1692 // Illegal |
| 1682 // | 1693 // |
| 1683 // An invalid bytecode aborting execution if dispatched. | 1694 // An invalid bytecode aborting execution if dispatched. |
| 1684 void Interpreter::DoIllegal(InterpreterAssembler* assembler) { | 1695 void Interpreter::DoIllegal(InterpreterAssembler* assembler) { |
| 1685 __ Abort(kInvalidBytecode); | 1696 __ Abort(kInvalidBytecode); |
| 1686 } | 1697 } |
| 1687 | 1698 |
| 1688 } // namespace interpreter | 1699 } // namespace interpreter |
| 1689 } // namespace internal | 1700 } // namespace internal |
| 1690 } // namespace v8 | 1701 } // namespace v8 |
| OLD | NEW |