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::kWide: |
| 154 expected_operand = Bytecodes::WideOperandFromBytes( |
| 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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 Handle<BytecodeArray> bytecode_array = | 886 Handle<BytecodeArray> bytecode_array = |
872 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 887 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
873 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 888 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
874 } | 889 } |
875 } | 890 } |
876 | 891 |
877 | 892 |
878 } // namespace interpreter | 893 } // namespace interpreter |
879 } // namespace internal | 894 } // namespace internal |
880 } // namespance v8 | 895 } // namespance v8 |
OLD | NEW |