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/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/interpreter/control-flow-builders.h" | 10 #include "src/interpreter/control-flow-builders.h" |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 | 770 |
771 | 771 |
772 void BytecodeGenerator::VisitCountOperation(CountOperation* expr) { | 772 void BytecodeGenerator::VisitCountOperation(CountOperation* expr) { |
773 UNIMPLEMENTED(); | 773 UNIMPLEMENTED(); |
774 } | 774 } |
775 | 775 |
776 | 776 |
777 void BytecodeGenerator::VisitBinaryOperation(BinaryOperation* binop) { | 777 void BytecodeGenerator::VisitBinaryOperation(BinaryOperation* binop) { |
778 switch (binop->op()) { | 778 switch (binop->op()) { |
779 case Token::COMMA: | 779 case Token::COMMA: |
780 VisitCommaExpression(binop); | |
781 break; | |
780 case Token::OR: | 782 case Token::OR: |
783 VisitLogicalOrExpression(binop); | |
784 break; | |
781 case Token::AND: | 785 case Token::AND: |
782 UNIMPLEMENTED(); | 786 VisitLogicalAndExpression(binop); |
783 break; | 787 break; |
784 default: | 788 default: |
785 VisitArithmeticExpression(binop); | 789 VisitArithmeticExpression(binop); |
786 break; | 790 break; |
787 } | 791 } |
788 } | 792 } |
789 | 793 |
790 | 794 |
791 void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) { | 795 void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
792 Token::Value op = expr->op(); | 796 Token::Value op = expr->op(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 TemporaryRegisterScope temporary_register_scope(&builder_); | 839 TemporaryRegisterScope temporary_register_scope(&builder_); |
836 Register temporary = temporary_register_scope.NewRegister(); | 840 Register temporary = temporary_register_scope.NewRegister(); |
837 | 841 |
838 Visit(left); | 842 Visit(left); |
839 builder()->StoreAccumulatorInRegister(temporary); | 843 builder()->StoreAccumulatorInRegister(temporary); |
840 Visit(right); | 844 Visit(right); |
841 builder()->BinaryOperation(op, temporary, language_mode_strength()); | 845 builder()->BinaryOperation(op, temporary, language_mode_strength()); |
842 } | 846 } |
843 | 847 |
844 | 848 |
849 void BytecodeGenerator::VisitCommaExpression(BinaryOperation* binop) { | |
850 Expression* left = binop->left(); | |
851 Expression* right = binop->right(); | |
852 | |
853 TemporaryRegisterScope temporary_register_scope(&builder_); | |
854 Register temporary = temporary_register_scope.NewRegister(); | |
855 | |
856 Visit(left); | |
857 builder()->StoreAccumulatorInRegister(temporary); | |
858 Visit(right); | |
859 } | |
860 | |
861 | |
862 void BytecodeGenerator::VisitLogicalOrExpression(BinaryOperation* binop) { | |
863 Expression* left = binop->left(); | |
864 Expression* right = binop->right(); | |
865 | |
866 TemporaryRegisterScope temporary_register_scope(&builder_); | |
867 Register temporary = temporary_register_scope.NewRegister(); | |
868 | |
869 // Short-circuit evaluation- If it is known that left is always true, | |
870 // no need to visit right | |
871 if (left->ToBooleanIsTrue()) { | |
872 Visit(left); | |
873 } else { | |
874 BytecodeLabel else_label, end_label; | |
875 | |
876 Visit(left); | |
877 builder()->StoreAccumulatorInRegister(temporary); | |
878 builder()->CastAccumulatorToBoolean(); | |
879 builder()->JumpIfFalse(&else_label); | |
880 builder()->LoadAccumulatorWithRegister(temporary); | |
881 builder()->Jump(&end_label); | |
882 builder()->Bind(&else_label); | |
rmcilroy
2015/10/12 07:24:13
I think we should add a pair of bytecodes which pe
mythria
2015/10/13 15:00:00
Done.
| |
883 Visit(right); | |
884 builder()->Bind(&end_label); | |
885 } | |
886 } | |
887 | |
888 | |
889 void BytecodeGenerator::VisitLogicalAndExpression(BinaryOperation* binop) { | |
890 Expression* left = binop->left(); | |
891 Expression* right = binop->right(); | |
892 | |
893 TemporaryRegisterScope temporary_register_scope(&builder_); | |
894 Register temporary = temporary_register_scope.NewRegister(); | |
895 | |
896 // Short-circuit evaluation- If it is known that left is always false, | |
897 // no need to visit right | |
898 if (left->ToBooleanIsFalse()) { | |
899 Visit(left); | |
900 } else { | |
901 BytecodeLabel else_label, end_label; | |
902 | |
903 Visit(left); | |
904 builder()->StoreAccumulatorInRegister(temporary); | |
905 builder()->CastAccumulatorToBoolean(); | |
906 builder()->JumpIfTrue(&else_label); | |
907 builder()->LoadAccumulatorWithRegister(temporary); | |
908 builder()->Jump(&end_label); | |
909 builder()->Bind(&else_label); | |
910 Visit(right); | |
911 builder()->Bind(&end_label); | |
912 } | |
913 } | |
914 | |
915 | |
845 LanguageMode BytecodeGenerator::language_mode() const { | 916 LanguageMode BytecodeGenerator::language_mode() const { |
846 return info()->language_mode(); | 917 return info()->language_mode(); |
847 } | 918 } |
848 | 919 |
849 | 920 |
850 Strength BytecodeGenerator::language_mode_strength() const { | 921 Strength BytecodeGenerator::language_mode_strength() const { |
851 return strength(language_mode()); | 922 return strength(language_mode()); |
852 } | 923 } |
853 | 924 |
854 | 925 |
855 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 926 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
856 return info()->feedback_vector()->GetIndex(slot); | 927 return info()->feedback_vector()->GetIndex(slot); |
857 } | 928 } |
858 | 929 |
859 | 930 |
860 Register BytecodeGenerator::current_context() const { return current_context_; } | 931 Register BytecodeGenerator::current_context() const { return current_context_; } |
861 | 932 |
862 } // namespace interpreter | 933 } // namespace interpreter |
863 } // namespace internal | 934 } // namespace internal |
864 } // namespace v8 | 935 } // namespace v8 |
OLD | NEW |