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/bytecode-register.h" | |
10 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
| 10 #include "test/unittests/interpreter/bytecode-utils.h" |
11 #include "test/unittests/test-utils.h" | 11 #include "test/unittests/test-utils.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 namespace interpreter { | 15 namespace interpreter { |
16 | 16 |
17 TEST(OperandConversion, Registers) { | 17 TEST(OperandConversion, Registers) { |
18 int register_count = 128; | 18 int register_count = 128; |
19 int step = register_count / 7; | 19 int step = register_count / 7; |
20 for (int i = 0; i < register_count; i += step) { | 20 for (int i = 0; i < register_count; i += step) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name) && \ | 139 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name) && \ |
140 !Bytecodes::IsPrefixScalingBytecode(Bytecode::k##Name)) { \ | 140 !Bytecodes::IsPrefixScalingBytecode(Bytecode::k##Name)) { \ |
141 Bytecode debug_bytecode = Bytecodes::GetDebugBreak(Bytecode::k##Name); \ | 141 Bytecode debug_bytecode = Bytecodes::GetDebugBreak(Bytecode::k##Name); \ |
142 CHECK_EQ(Bytecodes::Size(Bytecode::k##Name, kOperandScale), \ | 142 CHECK_EQ(Bytecodes::Size(Bytecode::k##Name, kOperandScale), \ |
143 Bytecodes::Size(debug_bytecode, kOperandScale)); \ | 143 Bytecodes::Size(debug_bytecode, kOperandScale)); \ |
144 } | 144 } |
145 BYTECODE_LIST(CHECK_DEBUG_BREAK_SIZE) | 145 BYTECODE_LIST(CHECK_DEBUG_BREAK_SIZE) |
146 #undef CHECK_DEBUG_BREAK_SIZE | 146 #undef CHECK_DEBUG_BREAK_SIZE |
147 } | 147 } |
148 | 148 |
| 149 TEST(Bytecodes, DecodeBytecodeAndOperands) { |
| 150 struct BytecodesAndResult { |
| 151 const uint8_t bytecode[32]; |
| 152 const size_t length; |
| 153 int parameter_count; |
| 154 const char* output; |
| 155 }; |
| 156 |
| 157 const BytecodesAndResult cases[] = { |
| 158 {{B(LdaSmi), U8(1)}, 2, 0, " LdaSmi [1]"}, |
| 159 {{B(Wide), B(LdaSmi), U16(1000)}, 4, 0, " LdaSmi.Wide [1000]"}, |
| 160 {{B(ExtraWide), B(LdaSmi), U32(100000)}, |
| 161 6, |
| 162 0, |
| 163 "LdaSmi.ExtraWide [100000]"}, |
| 164 {{B(LdaSmi), U8(-1)}, 2, 0, " LdaSmi [-1]"}, |
| 165 {{B(Wide), B(LdaSmi), U16(-1000)}, 4, 0, " LdaSmi.Wide [-1000]"}, |
| 166 {{B(ExtraWide), B(LdaSmi), U32(-100000)}, |
| 167 6, |
| 168 0, |
| 169 "LdaSmi.ExtraWide [-100000]"}, |
| 170 {{B(Star), R8(5)}, 2, 0, " Star r5"}, |
| 171 {{B(Wide), B(Star), R16(136)}, 4, 0, " Star.Wide r136"}, |
| 172 {{B(Wide), B(Call), R16(134), R16(135), U16(2), U16(177)}, |
| 173 10, |
| 174 0, |
| 175 "Call.Wide r134, r135, #2, [177]"}, |
| 176 {{B(Ldar), |
| 177 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())}, |
| 178 2, |
| 179 3, |
| 180 " Ldar a1"}, |
| 181 {{B(Wide), B(CreateObjectLiteral), U16(513), U16(1027), U8(165)}, |
| 182 7, |
| 183 0, |
| 184 "CreateObjectLiteral.Wide [513], [1027], #165"}, |
| 185 {{B(ExtraWide), B(JumpIfNull), U32(123456789)}, |
| 186 6, |
| 187 0, |
| 188 "JumpIfNull.ExtraWide [123456789]"}, |
| 189 }; |
| 190 |
| 191 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 192 // Generate reference string by prepending formatted bytes. |
| 193 std::stringstream expected_ss; |
| 194 std::ios default_format(nullptr); |
| 195 default_format.copyfmt(expected_ss); |
| 196 // Match format of Bytecodes::Decode() for byte representations. |
| 197 expected_ss.fill('0'); |
| 198 expected_ss.flags(std::ios::right | std::ios::hex); |
| 199 for (size_t b = 0; b < cases[i].length; b++) { |
| 200 expected_ss << std::setw(2) << static_cast<uint32_t>(cases[i].bytecode[b]) |
| 201 << ' '; |
| 202 } |
| 203 expected_ss.copyfmt(default_format); |
| 204 expected_ss << cases[i].output; |
| 205 |
| 206 // Generate decoded byte output. |
| 207 std::stringstream actual_ss; |
| 208 Bytecodes::Decode(actual_ss, cases[i].bytecode, cases[i].parameter_count); |
| 209 |
| 210 // Compare. |
| 211 CHECK_EQ(actual_ss.str(), expected_ss.str()); |
| 212 } |
| 213 } |
| 214 |
149 TEST(Bytecodes, DebugBreakForPrefixBytecodes) { | 215 TEST(Bytecodes, DebugBreakForPrefixBytecodes) { |
150 CHECK_EQ(Bytecode::kDebugBreakWide, | 216 CHECK_EQ(Bytecode::kDebugBreakWide, |
151 Bytecodes::GetDebugBreak(Bytecode::kWide)); | 217 Bytecodes::GetDebugBreak(Bytecode::kWide)); |
152 CHECK_EQ(Bytecode::kDebugBreakExtraWide, | 218 CHECK_EQ(Bytecode::kDebugBreakExtraWide, |
153 Bytecodes::GetDebugBreak(Bytecode::kExtraWide)); | 219 Bytecodes::GetDebugBreak(Bytecode::kExtraWide)); |
154 } | 220 } |
155 | 221 |
156 TEST(Bytecodes, PrefixMappings) { | 222 TEST(Bytecodes, PrefixMappings) { |
157 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide}; | 223 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide}; |
158 TRACED_FOREACH(Bytecode, prefix, prefixes) { | 224 TRACED_FOREACH(Bytecode, prefix, prefixes) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 std::set<std::string> names; | 306 std::set<std::string> names; |
241 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone)); | 307 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone)); |
242 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead)); | 308 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead)); |
243 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite)); | 309 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite)); |
244 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite)); | 310 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite)); |
245 CHECK_EQ(names.size(), 4); | 311 CHECK_EQ(names.size(), 4); |
246 } | 312 } |
247 } // namespace interpreter | 313 } // namespace interpreter |
248 } // namespace internal | 314 } // namespace internal |
249 } // namespace v8 | 315 } // namespace v8 |
OLD | NEW |