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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
10 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name) && \ | 170 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name) && \ |
171 !Bytecodes::IsPrefixScalingBytecode(Bytecode::k##Name)) { \ | 171 !Bytecodes::IsPrefixScalingBytecode(Bytecode::k##Name)) { \ |
172 Bytecode debug_bytecode = Bytecodes::GetDebugBreak(Bytecode::k##Name); \ | 172 Bytecode debug_bytecode = Bytecodes::GetDebugBreak(Bytecode::k##Name); \ |
173 CHECK_EQ(Bytecodes::Size(Bytecode::k##Name, kOperandScale), \ | 173 CHECK_EQ(Bytecodes::Size(Bytecode::k##Name, kOperandScale), \ |
174 Bytecodes::Size(debug_bytecode, kOperandScale)); \ | 174 Bytecodes::Size(debug_bytecode, kOperandScale)); \ |
175 } | 175 } |
176 BYTECODE_LIST(CHECK_DEBUG_BREAK_SIZE) | 176 BYTECODE_LIST(CHECK_DEBUG_BREAK_SIZE) |
177 #undef CHECK_DEBUG_BREAK_SIZE | 177 #undef CHECK_DEBUG_BREAK_SIZE |
178 } | 178 } |
179 | 179 |
| 180 TEST(Bytecodes, DecodeBytecodeAndOperands) { |
| 181 struct BytecodesAndResult { |
| 182 const uint8_t bytecode[32]; |
| 183 const size_t length; |
| 184 int parameter_count; |
| 185 const char* output; |
| 186 }; |
| 187 |
| 188 #define B(Name) static_cast<uint8_t>(Bytecode::k##Name) |
| 189 const BytecodesAndResult cases[] = { |
| 190 {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"}, |
| 191 {{B(Wide), B(LdaSmi), 0xe8, 0x03}, 4, 0, " LdaSmi.Wide [1000]"}, |
| 192 {{B(ExtraWide), B(LdaSmi), 0xa0, 0x86, 0x01, 0x00}, |
| 193 6, |
| 194 0, |
| 195 "LdaSmi.ExtraWide [100000]"}, |
| 196 {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"}, |
| 197 {{B(Wide), B(LdaSmi), 0x18, 0xfc}, 4, 0, " LdaSmi.Wide [-1000]"}, |
| 198 {{B(ExtraWide), B(LdaSmi), 0x60, 0x79, 0xfe, 0xff}, |
| 199 6, |
| 200 0, |
| 201 "LdaSmi.ExtraWide [-100000]"}, |
| 202 {{B(Star), 0xfb}, 2, 0, " Star r5"}, |
| 203 {{B(Wide), B(Star), 0x78, 0xff}, 4, 0, " Star.Wide r136"}, |
| 204 {{B(Wide), B(Call), 0x7a, 0xff, 0x79, 0xff, 0x02, 0x00, 0xb1, 0x00}, |
| 205 10, |
| 206 0, |
| 207 "Call.Wide r134, r135, #2, [177]"}, |
| 208 {{B(Ldar), |
| 209 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())}, |
| 210 2, |
| 211 3, |
| 212 " Ldar a1"}, |
| 213 {{B(Wide), B(CreateObjectLiteral), 0x01, 0x02, 0x03, 0x04, 0xa5}, |
| 214 7, |
| 215 0, |
| 216 "CreateObjectLiteral.Wide [513], [1027], #165"}, |
| 217 {{B(ExtraWide), B(JumpIfNull), 0x15, 0xcd, 0x5b, 0x07}, |
| 218 6, |
| 219 0, |
| 220 "JumpIfNull.ExtraWide [123456789]"}, |
| 221 }; |
| 222 #undef B |
| 223 |
| 224 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 225 // Generate reference string by prepending formatted bytes. |
| 226 std::stringstream expected_ss; |
| 227 std::ios default_format(nullptr); |
| 228 default_format.copyfmt(expected_ss); |
| 229 // Match format of Bytecodes::Decode() for byte representations. |
| 230 expected_ss.fill('0'); |
| 231 expected_ss.flags(std::ios::right | std::ios::hex); |
| 232 for (size_t b = 0; b < cases[i].length; b++) { |
| 233 expected_ss << std::setw(2) << static_cast<uint32_t>(cases[i].bytecode[b]) |
| 234 << ' '; |
| 235 } |
| 236 expected_ss.copyfmt(default_format); |
| 237 expected_ss << cases[i].output; |
| 238 |
| 239 // Generate decoded byte output. |
| 240 std::stringstream actual_ss; |
| 241 Bytecodes::Decode(actual_ss, cases[i].bytecode, cases[i].parameter_count); |
| 242 |
| 243 // Compare. |
| 244 CHECK_EQ(actual_ss.str(), expected_ss.str()); |
| 245 } |
| 246 } |
| 247 |
180 TEST(Bytecodes, DebugBreakForPrefixBytecodes) { | 248 TEST(Bytecodes, DebugBreakForPrefixBytecodes) { |
181 CHECK_EQ(Bytecode::kDebugBreakWide, | 249 CHECK_EQ(Bytecode::kDebugBreakWide, |
182 Bytecodes::GetDebugBreak(Bytecode::kWide)); | 250 Bytecodes::GetDebugBreak(Bytecode::kWide)); |
183 CHECK_EQ(Bytecode::kDebugBreakExtraWide, | 251 CHECK_EQ(Bytecode::kDebugBreakExtraWide, |
184 Bytecodes::GetDebugBreak(Bytecode::kExtraWide)); | 252 Bytecodes::GetDebugBreak(Bytecode::kExtraWide)); |
185 } | 253 } |
186 | 254 |
187 TEST(Bytecodes, PrefixMappings) { | 255 TEST(Bytecodes, PrefixMappings) { |
188 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide}; | 256 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide}; |
189 TRACED_FOREACH(Bytecode, prefix, prefixes) { | 257 TRACED_FOREACH(Bytecode, prefix, prefixes) { |
(...skipping 18 matching lines...) Expand all Loading... |
208 Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kQuadruple)); | 276 Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kQuadruple)); |
209 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kDouble) == | 277 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kDouble) == |
210 Bytecode::kWide); | 278 Bytecode::kWide); |
211 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kQuadruple) == | 279 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kQuadruple) == |
212 Bytecode::kExtraWide); | 280 Bytecode::kExtraWide); |
213 } | 281 } |
214 | 282 |
215 } // namespace interpreter | 283 } // namespace interpreter |
216 } // namespace internal | 284 } // namespace internal |
217 } // namespace v8 | 285 } // namespace v8 |
OLD | NEW |