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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 int bytecode_index = i++; | 123 int bytecode_index = i++; |
124 Bytecode bytecode = iterator.current_bytecode(); | 124 Bytecode bytecode = iterator.current_bytecode(); |
125 if (Bytecodes::ToByte(bytecode) != expected.bytecode[bytecode_index]) { | 125 if (Bytecodes::ToByte(bytecode) != expected.bytecode[bytecode_index]) { |
126 std::ostringstream stream; | 126 std::ostringstream stream; |
127 stream << "Check failed: expected bytecode [" << bytecode_index | 127 stream << "Check failed: expected bytecode [" << bytecode_index |
128 << "] to be " << Bytecodes::ToString(static_cast<Bytecode>( | 128 << "] to be " << Bytecodes::ToString(static_cast<Bytecode>( |
129 expected.bytecode[bytecode_index])) | 129 expected.bytecode[bytecode_index])) |
130 << " but got " << Bytecodes::ToString(bytecode); | 130 << " but got " << Bytecodes::ToString(bytecode); |
131 FATAL(stream.str().c_str()); | 131 FATAL(stream.str().c_str()); |
132 } | 132 } |
133 for (int j = 0; j < Bytecodes::NumberOfOperands(bytecode); ++j, ++i) { | 133 for (int j = 0; j < Bytecodes::NumberOfOperands(bytecode); ++j) { |
134 uint8_t raw_operand = | 134 OperandType operand_type = Bytecodes::GetOperandType(bytecode, j); |
135 iterator.GetRawOperand(j, Bytecodes::GetOperandType(bytecode, j)); | 135 int operand_index = i; |
| 136 i += static_cast<int>(Bytecodes::SizeOfOperand(operand_type)); |
| 137 uint32_t raw_operand = iterator.GetRawOperand(j, operand_type); |
136 if (has_unknown) { | 138 if (has_unknown) { |
137 // Check actual bytecode array doesn't have the same byte as the | 139 // Check actual bytecode array doesn't have the same byte as the |
138 // one we use to specify an unknown byte. | 140 // one we use to specify an unknown byte. |
139 CHECK_NE(raw_operand, _); | 141 CHECK_NE(raw_operand, _); |
140 if (expected.bytecode[i] == _) { | 142 if (expected.bytecode[operand_index] == _) { |
141 continue; | 143 continue; |
142 } | 144 } |
143 } | 145 } |
144 if (raw_operand != expected.bytecode[i]) { | 146 uint32_t expected_operand; |
| 147 switch (Bytecodes::SizeOfOperand(operand_type)) { |
| 148 case OperandSize::kNone: |
| 149 UNREACHABLE(); |
| 150 case OperandSize::kByte: |
| 151 expected_operand = |
| 152 static_cast<uint32_t>(expected.bytecode[operand_index]); |
| 153 break; |
| 154 case OperandSize::kShort: |
| 155 expected_operand = Bytecodes::ShortOperandFromBytes( |
| 156 &expected.bytecode[operand_index]); |
| 157 break; |
| 158 } |
| 159 if (raw_operand != expected_operand) { |
145 std::ostringstream stream; | 160 std::ostringstream stream; |
146 stream << "Check failed: expected operand [" << j << "] for bytecode [" | 161 stream << "Check failed: expected operand [" << j << "] for bytecode [" |
147 << bytecode_index << "] to be " | 162 << bytecode_index << "] to be " |
148 << static_cast<unsigned int>(expected.bytecode[i]) << " but got " | 163 << static_cast<unsigned int>(expected_operand) << " but got " |
149 << static_cast<unsigned int>(raw_operand); | 164 << static_cast<unsigned int>(raw_operand); |
150 FATAL(stream.str().c_str()); | 165 FATAL(stream.str().c_str()); |
151 } | 166 } |
152 } | 167 } |
153 iterator.Advance(); | 168 iterator.Advance(); |
154 } | 169 } |
155 } | 170 } |
156 | 171 |
157 | 172 |
158 TEST(PrimitiveReturnStatements) { | 173 TEST(PrimitiveReturnStatements) { |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 for (size_t i = 0; i < arraysize(snippets); i++) { | 1181 for (size_t i = 0; i < arraysize(snippets); i++) { |
1167 Handle<BytecodeArray> bytecode_array = | 1182 Handle<BytecodeArray> bytecode_array = |
1168 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 1183 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
1169 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1184 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
1170 } | 1185 } |
1171 } | 1186 } |
1172 | 1187 |
1173 } // namespace interpreter | 1188 } // namespace interpreter |
1174 } // namespace internal | 1189 } // namespace internal |
1175 } // namespace v8 | 1190 } // namespace v8 |
OLD | NEW |