Chromium Code Reviews| 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 }; | |
| 214 #undef B | |
| 215 | |
| 216 for (size_t i = 0; i < arraysize(cases); ++i) { | |
| 217 // Generate reference string by prepending formatted bytes. | |
| 218 std::stringstream expected_ss; | |
| 219 std::ios ios_fmt(nullptr); | |
|
rmcilroy
2016/03/22 17:15:37
nit - default_format ?
oth
2016/03/23 10:10:06
Done.
| |
| 220 ios_fmt.copyfmt(expected_ss); | |
| 221 expected_ss.fill('0'); | |
|
rmcilroy
2016/03/22 17:15:37
nit - newline, and a comment to explain what this
| |
| 222 expected_ss.flags(std::ios::right | std::ios::hex); | |
| 223 for (size_t b = 0; b < cases[i].length; b++) { | |
| 224 expected_ss << std::setw(2) << static_cast<uint32_t>(cases[i].bytecode[b]) | |
| 225 << ' '; | |
| 226 } | |
| 227 expected_ss.copyfmt(ios_fmt); | |
| 228 expected_ss << cases[i].output; | |
| 229 | |
| 230 // Generate decoded byte output. | |
| 231 std::stringstream actual_ss; | |
| 232 Bytecodes::Decode(actual_ss, cases[i].bytecode, cases[i].parameter_count); | |
| 233 | |
| 234 // Compare. | |
| 235 CHECK_EQ(actual_ss.str(), expected_ss.str()); | |
| 236 } | |
| 237 } | |
| 238 | |
| 180 TEST(Bytecodes, DebugBreakForPrefixBytecodes) { | 239 TEST(Bytecodes, DebugBreakForPrefixBytecodes) { |
| 181 CHECK_EQ(Bytecode::kDebugBreakWide, | 240 CHECK_EQ(Bytecode::kDebugBreakWide, |
| 182 Bytecodes::GetDebugBreak(Bytecode::kWide)); | 241 Bytecodes::GetDebugBreak(Bytecode::kWide)); |
| 183 CHECK_EQ(Bytecode::kDebugBreakExtraWide, | 242 CHECK_EQ(Bytecode::kDebugBreakExtraWide, |
| 184 Bytecodes::GetDebugBreak(Bytecode::kExtraWide)); | 243 Bytecodes::GetDebugBreak(Bytecode::kExtraWide)); |
| 185 } | 244 } |
| 186 | 245 |
| 187 TEST(Bytecodes, PrefixMappings) { | 246 TEST(Bytecodes, PrefixMappings) { |
| 188 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide}; | 247 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide}; |
| 189 TRACED_FOREACH(Bytecode, prefix, prefixes) { | 248 TRACED_FOREACH(Bytecode, prefix, prefixes) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 208 Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kQuadruple)); | 267 Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kQuadruple)); |
| 209 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kDouble) == | 268 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kDouble) == |
| 210 Bytecode::kWide); | 269 Bytecode::kWide); |
| 211 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kQuadruple) == | 270 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kQuadruple) == |
| 212 Bytecode::kExtraWide); | 271 Bytecode::kExtraWide); |
| 213 } | 272 } |
| 214 | 273 |
| 215 } // namespace interpreter | 274 } // namespace interpreter |
| 216 } // namespace internal | 275 } // namespace internal |
| 217 } // namespace v8 | 276 } // namespace v8 |
| OLD | NEW |