| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
| 9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
| 10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 int bytecode_index = i++; | 122 int bytecode_index = i++; |
| 123 Bytecode bytecode = iterator.current_bytecode(); | 123 Bytecode bytecode = iterator.current_bytecode(); |
| 124 if (Bytecodes::ToByte(bytecode) != expected.bytecode[bytecode_index]) { | 124 if (Bytecodes::ToByte(bytecode) != expected.bytecode[bytecode_index]) { |
| 125 std::ostringstream stream; | 125 std::ostringstream stream; |
| 126 stream << "Check failed: expected bytecode [" << bytecode_index | 126 stream << "Check failed: expected bytecode [" << bytecode_index |
| 127 << "] to be " << Bytecodes::ToString(static_cast<Bytecode>( | 127 << "] to be " << Bytecodes::ToString(static_cast<Bytecode>( |
| 128 expected.bytecode[bytecode_index])) | 128 expected.bytecode[bytecode_index])) |
| 129 << " but got " << Bytecodes::ToString(bytecode); | 129 << " but got " << Bytecodes::ToString(bytecode); |
| 130 FATAL(stream.str().c_str()); | 130 FATAL(stream.str().c_str()); |
| 131 } | 131 } |
| 132 for (int j = 0; j < Bytecodes::NumberOfOperands(bytecode); ++j, ++i) { | 132 for (int j = 0; j < Bytecodes::NumberOfOperands(bytecode); ++j) { |
| 133 uint8_t raw_operand = | 133 OperandType operand_type = Bytecodes::GetOperandType(bytecode, j); |
| 134 iterator.GetRawOperand(j, Bytecodes::GetOperandType(bytecode, j)); | 134 int operand_index = i; |
| 135 i += static_cast<int>(Bytecodes::SizeOfOperand(operand_type)); |
| 136 uint32_t raw_operand = iterator.GetRawOperand(j, operand_type); |
| 135 if (has_unknown) { | 137 if (has_unknown) { |
| 136 // Check actual bytecode array doesn't have the same byte as the | 138 // Check actual bytecode array doesn't have the same byte as the |
| 137 // one we use to specify an unknown byte. | 139 // one we use to specify an unknown byte. |
| 138 CHECK_NE(raw_operand, _); | 140 CHECK_NE(raw_operand, _); |
| 139 if (expected.bytecode[i] == _) { | 141 if (expected.bytecode[operand_index] == _) { |
| 140 continue; | 142 continue; |
| 141 } | 143 } |
| 142 } | 144 } |
| 143 if (raw_operand != expected.bytecode[i]) { | 145 uint32_t expected_operand; |
| 146 switch (Bytecodes::SizeOfOperand(operand_type)) { |
| 147 case OperandSize::kNone: |
| 148 UNREACHABLE(); |
| 149 case OperandSize::kByte: |
| 150 expected_operand = |
| 151 static_cast<uint32_t>(expected.bytecode[operand_index]); |
| 152 break; |
| 153 case OperandSize::kShort: |
| 154 expected_operand = Bytecodes::ShortOperandFromBytes( |
| 155 &expected.bytecode[operand_index]); |
| 156 break; |
| 157 } |
| 158 if (raw_operand != expected_operand) { |
| 144 std::ostringstream stream; | 159 std::ostringstream stream; |
| 145 stream << "Check failed: expected operand [" << j << "] for bytecode [" | 160 stream << "Check failed: expected operand [" << j << "] for bytecode [" |
| 146 << bytecode_index << "] to be " | 161 << bytecode_index << "] to be " |
| 147 << static_cast<unsigned int>(expected.bytecode[i]) << " but got " | 162 << static_cast<unsigned int>(expected_operand) << " but got " |
| 148 << static_cast<unsigned int>(raw_operand); | 163 << static_cast<unsigned int>(raw_operand); |
| 149 FATAL(stream.str().c_str()); | 164 FATAL(stream.str().c_str()); |
| 150 } | 165 } |
| 151 } | 166 } |
| 152 iterator.Advance(); | 167 iterator.Advance(); |
| 153 } | 168 } |
| 154 } | 169 } |
| 155 | 170 |
| 156 | 171 |
| 157 TEST(PrimitiveReturnStatements) { | 172 TEST(PrimitiveReturnStatements) { |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 { | 686 { |
| 672 B(LdaGlobal), _, | 687 B(LdaGlobal), _, |
| 673 B(Return) | 688 B(Return) |
| 674 }, | 689 }, |
| 675 }, | 690 }, |
| 676 }; | 691 }; |
| 677 | 692 |
| 678 for (size_t i = 0; i < arraysize(snippets); i++) { | 693 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 679 Handle<BytecodeArray> bytecode_array = | 694 Handle<BytecodeArray> bytecode_array = |
| 680 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 695 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
| 681 bytecode_array->Print(); | |
| 682 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | 696 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); |
| 683 } | 697 } |
| 684 } | 698 } |
| 685 | 699 |
| 686 | 700 |
| 687 TEST(CallGlobal) { | 701 TEST(CallGlobal) { |
| 688 InitializedHandleScope handle_scope; | 702 InitializedHandleScope handle_scope; |
| 689 BytecodeGeneratorHelper helper; | 703 BytecodeGeneratorHelper helper; |
| 690 | 704 |
| 691 ExpectedSnippet<const char*> snippets[] = { | 705 ExpectedSnippet<const char*> snippets[] = { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 Handle<BytecodeArray> bytecode_array = | 885 Handle<BytecodeArray> bytecode_array = |
| 872 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 886 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
| 873 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 887 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 874 } | 888 } |
| 875 } | 889 } |
| 876 | 890 |
| 877 | 891 |
| 878 } // namespace interpreter | 892 } // namespace interpreter |
| 879 } // namespace internal | 893 } // namespace internal |
| 880 } // namespance v8 | 894 } // namespance v8 |
| OLD | NEW |