| 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-array-builder.h" | 5 #include "src/interpreter/bytecode-array-builder.h" |
| 6 | 6 |
| 7 #include "src/globals.h" | 7 #include "src/globals.h" |
| 8 #include "src/interpreter/bytecode-array-writer.h" | 8 #include "src/interpreter/bytecode-array-writer.h" |
| 9 #include "src/interpreter/bytecode-dead-code-optimizer.h" | 9 #include "src/interpreter/bytecode-dead-code-optimizer.h" |
| 10 #include "src/interpreter/bytecode-label.h" | 10 #include "src/interpreter/bytecode-label.h" |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 if (Bytecodes::NumberOfOperands(bytecode) != operand_count) { | 850 if (Bytecodes::NumberOfOperands(bytecode) != operand_count) { |
| 851 return false; | 851 return false; |
| 852 } | 852 } |
| 853 | 853 |
| 854 uint32_t operands[] = {operand0, operand1, operand2, operand3}; | 854 uint32_t operands[] = {operand0, operand1, operand2, operand3}; |
| 855 const OperandType* operand_types = Bytecodes::GetOperandTypes(bytecode); | 855 const OperandType* operand_types = Bytecodes::GetOperandTypes(bytecode); |
| 856 for (int i = 0; i < operand_count; ++i) { | 856 for (int i = 0; i < operand_count; ++i) { |
| 857 switch (operand_types[i]) { | 857 switch (operand_types[i]) { |
| 858 case OperandType::kNone: | 858 case OperandType::kNone: |
| 859 return false; | 859 return false; |
| 860 case OperandType::kRegCount: { | |
| 861 CHECK_NE(i, 0); | |
| 862 CHECK(operand_types[i - 1] == OperandType::kMaybeReg || | |
| 863 operand_types[i - 1] == OperandType::kReg); | |
| 864 if (i > 0 && operands[i] > 0) { | |
| 865 Register start = Register::FromOperand(operands[i - 1]); | |
| 866 Register end(start.index() + static_cast<int>(operands[i]) - 1); | |
| 867 if (!RegisterIsValid(start) || !RegisterIsValid(end) || start > end) { | |
| 868 return false; | |
| 869 } | |
| 870 } | |
| 871 break; | |
| 872 } | |
| 873 case OperandType::kFlag8: | 860 case OperandType::kFlag8: |
| 874 case OperandType::kIntrinsicId: | 861 case OperandType::kIntrinsicId: |
| 875 if (Bytecodes::SizeForUnsignedOperand(operands[i]) > | 862 if (Bytecodes::SizeForUnsignedOperand(operands[i]) > |
| 876 OperandSize::kByte) { | 863 OperandSize::kByte) { |
| 877 return false; | 864 return false; |
| 878 } | 865 } |
| 879 break; | 866 break; |
| 880 case OperandType::kRuntimeId: | 867 case OperandType::kRuntimeId: |
| 881 if (Bytecodes::SizeForUnsignedOperand(operands[i]) > | 868 if (Bytecodes::SizeForUnsignedOperand(operands[i]) > |
| 882 OperandSize::kShort) { | 869 OperandSize::kShort) { |
| 883 return false; | 870 return false; |
| 884 } | 871 } |
| 885 break; | 872 break; |
| 886 case OperandType::kIdx: | 873 case OperandType::kIdx: |
| 887 // TODO(leszeks): Possibly split this up into constant pool indices and | 874 // TODO(leszeks): Possibly split this up into constant pool indices and |
| 888 // other indices, for checking. | 875 // other indices, for checking. |
| 889 break; | 876 break; |
| 890 case OperandType::kUImm: | 877 case OperandType::kUImm: |
| 891 case OperandType::kImm: | 878 case OperandType::kImm: |
| 892 break; | 879 break; |
| 893 case OperandType::kMaybeReg: | 880 case OperandType::kRegList: { |
| 894 if (Register::FromOperand(operands[i]) == Register(0)) { | 881 CHECK_LT(i, operand_count - 1); |
| 895 break; | 882 CHECK(operand_types[i + 1] == OperandType::kRegCount); |
| 883 int reg_count = static_cast<int>(operands[i + 1]); |
| 884 if (reg_count == 0) { |
| 885 return Register::FromOperand(operands[i]) == Register(0); |
| 886 } else { |
| 887 Register start = Register::FromOperand(operands[i]); |
| 888 Register end(start.index() + reg_count - 1); |
| 889 if (!RegisterIsValid(start) || !RegisterIsValid(end) || start > end) { |
| 890 return false; |
| 891 } |
| 896 } | 892 } |
| 897 // Fall-through to kReg case. | 893 i++; // Skip past kRegCount operand. |
| 894 break; |
| 895 } |
| 898 case OperandType::kReg: | 896 case OperandType::kReg: |
| 899 case OperandType::kRegOut: { | 897 case OperandType::kRegOut: { |
| 900 Register reg = Register::FromOperand(operands[i]); | 898 Register reg = Register::FromOperand(operands[i]); |
| 901 if (!RegisterIsValid(reg)) { | 899 if (!RegisterIsValid(reg)) { |
| 902 return false; | 900 return false; |
| 903 } | 901 } |
| 904 break; | 902 break; |
| 905 } | 903 } |
| 906 case OperandType::kRegOutPair: | 904 case OperandType::kRegOutPair: |
| 907 case OperandType::kRegPair: { | 905 case OperandType::kRegPair: { |
| 908 Register reg0 = Register::FromOperand(operands[i]); | 906 Register reg0 = Register::FromOperand(operands[i]); |
| 909 Register reg1 = Register(reg0.index() + 1); | 907 Register reg1 = Register(reg0.index() + 1); |
| 910 if (!RegisterIsValid(reg0) || !RegisterIsValid(reg1)) { | 908 if (!RegisterIsValid(reg0) || !RegisterIsValid(reg1)) { |
| 911 return false; | 909 return false; |
| 912 } | 910 } |
| 913 break; | 911 break; |
| 914 } | 912 } |
| 915 case OperandType::kRegOutTriple: { | 913 case OperandType::kRegOutTriple: { |
| 916 Register reg0 = Register::FromOperand(operands[i]); | 914 Register reg0 = Register::FromOperand(operands[i]); |
| 917 Register reg1 = Register(reg0.index() + 1); | 915 Register reg1 = Register(reg0.index() + 1); |
| 918 Register reg2 = Register(reg0.index() + 2); | 916 Register reg2 = Register(reg0.index() + 2); |
| 919 if (!RegisterIsValid(reg0) || !RegisterIsValid(reg1) || | 917 if (!RegisterIsValid(reg0) || !RegisterIsValid(reg1) || |
| 920 !RegisterIsValid(reg2)) { | 918 !RegisterIsValid(reg2)) { |
| 921 return false; | 919 return false; |
| 922 } | 920 } |
| 923 break; | 921 break; |
| 924 } | 922 } |
| 923 case OperandType::kRegCount: |
| 924 UNREACHABLE(); // Dealt with in kRegList above. |
| 925 } | 925 } |
| 926 } | 926 } |
| 927 | 927 |
| 928 return true; | 928 return true; |
| 929 } | 929 } |
| 930 | 930 |
| 931 } // namespace interpreter | 931 } // namespace interpreter |
| 932 } // namespace internal | 932 } // namespace internal |
| 933 } // namespace v8 | 933 } // namespace v8 |
| OLD | NEW |