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" | 9 #include "src/interpreter/bytecode-register.h" |
10 #include "src/interpreter/bytecodes.h" | 10 #include "src/interpreter/bytecodes.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(kMaxUInt8 + 1)) == | 193 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(kMaxUInt8 + 1)) == |
194 OperandSize::kShort); | 194 OperandSize::kShort); |
195 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(kMaxUInt16)) == | 195 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(kMaxUInt16)) == |
196 OperandSize::kShort); | 196 OperandSize::kShort); |
197 CHECK(Bytecodes::SizeForUnsignedOperand( | 197 CHECK(Bytecodes::SizeForUnsignedOperand( |
198 static_cast<size_t>(kMaxUInt16 + 1)) == OperandSize::kQuad); | 198 static_cast<size_t>(kMaxUInt16 + 1)) == OperandSize::kQuad); |
199 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(kMaxUInt32)) == | 199 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(kMaxUInt32)) == |
200 OperandSize::kQuad); | 200 OperandSize::kQuad); |
201 } | 201 } |
202 | 202 |
203 // Helper macros to generate a check for if a bytecode is in a macro list of | |
204 // bytecodes. We can use these to exhaustively test a check over all bytecodes, | |
205 // both those that should pass and those that should fail the check. | |
206 #define OR_IS_BYTECODE(Name, ...) || bytecode == Bytecode::k##Name | |
207 #define IN_BYTECODE_LIST(BYTECODE, LIST) \ | |
208 ([](Bytecode bytecode) { return false LIST(OR_IS_BYTECODE); }(BYTECODE)) | |
rmcilroy
2016/12/05 14:33:40
I had this hack earlier in bytecode-operands and d
Leszek Swirski
2016/12/05 17:53:11
Yeah, I hated it too but I couldn't think of a bet
| |
209 | |
210 TEST(Bytecodes, IsJump) { | |
211 #define TEST_BYTECODE(Name, ...) \ | |
212 if (IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_BYTECODE_LIST)) { \ | |
213 EXPECT_TRUE(Bytecodes::IsJump(Bytecode::k##Name)); \ | |
214 } else { \ | |
215 EXPECT_FALSE(Bytecodes::IsJump(Bytecode::k##Name)); \ | |
216 } | |
217 | |
218 BYTECODE_LIST(TEST_BYTECODE) | |
219 #undef TEST_BYTECODE | |
220 } | |
221 | |
222 TEST(Bytecodes, IsForwardJump) { | |
223 #define TEST_BYTECODE(Name, ...) \ | |
224 if (IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_FORWARD_BYTECODE_LIST)) { \ | |
225 EXPECT_TRUE(Bytecodes::IsForwardJump(Bytecode::k##Name)); \ | |
226 } else { \ | |
227 EXPECT_FALSE(Bytecodes::IsForwardJump(Bytecode::k##Name)); \ | |
228 } | |
229 | |
230 BYTECODE_LIST(TEST_BYTECODE) | |
231 #undef TEST_BYTECODE | |
232 } | |
233 | |
234 TEST(Bytecodes, IsConditionalJump) { | |
235 #define TEST_BYTECODE(Name, ...) \ | |
236 if (IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_CONDITIONAL_BYTECODE_LIST)) { \ | |
237 EXPECT_TRUE(Bytecodes::IsConditionalJump(Bytecode::k##Name)); \ | |
238 } else { \ | |
239 EXPECT_FALSE(Bytecodes::IsConditionalJump(Bytecode::k##Name)); \ | |
240 } | |
241 | |
242 BYTECODE_LIST(TEST_BYTECODE) | |
243 #undef TEST_BYTECODE | |
244 } | |
245 | |
246 TEST(Bytecodes, IsUnconditionalJump) { | |
247 #define TEST_BYTECODE(Name, ...) \ | |
248 if (IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_UNCONDITIONAL_BYTECODE_LIST)) { \ | |
249 EXPECT_TRUE(Bytecodes::IsUnconditionalJump(Bytecode::k##Name)); \ | |
250 } else { \ | |
251 EXPECT_FALSE(Bytecodes::IsUnconditionalJump(Bytecode::k##Name)); \ | |
252 } | |
253 | |
254 BYTECODE_LIST(TEST_BYTECODE) | |
255 #undef TEST_BYTECODE | |
256 } | |
257 | |
258 TEST(Bytecodes, IsJumpImmediate) { | |
259 #define TEST_BYTECODE(Name, ...) \ | |
260 if (IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_IMMEDIATE_BYTECODE_LIST)) { \ | |
261 EXPECT_TRUE(Bytecodes::IsJumpImmediate(Bytecode::k##Name)); \ | |
262 } else { \ | |
263 EXPECT_FALSE(Bytecodes::IsJumpImmediate(Bytecode::k##Name)); \ | |
264 } | |
265 | |
266 BYTECODE_LIST(TEST_BYTECODE) | |
267 #undef TEST_BYTECODE | |
268 } | |
269 | |
270 TEST(Bytecodes, IsJumpConstant) { | |
271 #define TEST_BYTECODE(Name, ...) \ | |
272 if (IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_CONSTANT_BYTECODE_LIST)) { \ | |
273 EXPECT_TRUE(Bytecodes::IsJumpConstant(Bytecode::k##Name)); \ | |
274 } else { \ | |
275 EXPECT_FALSE(Bytecodes::IsJumpConstant(Bytecode::k##Name)); \ | |
276 } | |
277 | |
278 BYTECODE_LIST(TEST_BYTECODE) | |
279 #undef TEST_BYTECODE | |
280 } | |
281 | |
282 TEST(Bytecodes, IsConditionalJumpImmediate) { | |
283 #define TEST_BYTECODE(Name, ...) \ | |
284 if (IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_CONDITIONAL_BYTECODE_LIST) && \ | |
285 IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_IMMEDIATE_BYTECODE_LIST)) { \ | |
286 EXPECT_TRUE(Bytecodes::IsConditionalJumpImmediate(Bytecode::k##Name)); \ | |
287 } else { \ | |
288 EXPECT_FALSE(Bytecodes::IsConditionalJumpImmediate(Bytecode::k##Name)); \ | |
289 } | |
290 | |
291 BYTECODE_LIST(TEST_BYTECODE) | |
292 #undef TEST_BYTECODE | |
293 } | |
294 | |
295 TEST(Bytecodes, IsConditionalJumpConstant) { | |
296 #define TEST_BYTECODE(Name, ...) \ | |
297 if (IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_CONDITIONAL_BYTECODE_LIST) && \ | |
298 IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_CONSTANT_BYTECODE_LIST)) { \ | |
299 EXPECT_TRUE(Bytecodes::IsConditionalJumpConstant(Bytecode::k##Name)); \ | |
300 } else { \ | |
301 EXPECT_FALSE(Bytecodes::IsConditionalJumpConstant(Bytecode::k##Name)); \ | |
302 } | |
303 | |
304 BYTECODE_LIST(TEST_BYTECODE) | |
305 #undef TEST_BYTECODE | |
306 } | |
307 | |
308 TEST(Bytecodes, IsJumpIfToBoolean) { | |
309 #define TEST_BYTECODE(Name, ...) \ | |
310 if (IN_BYTECODE_LIST(Bytecode::k##Name, JUMP_TO_BOOLEAN_BYTECODE_LIST)) { \ | |
311 EXPECT_TRUE(Bytecodes::IsJumpIfToBoolean(Bytecode::k##Name)); \ | |
312 } else { \ | |
313 EXPECT_FALSE(Bytecodes::IsJumpIfToBoolean(Bytecode::k##Name)); \ | |
314 } | |
315 | |
316 BYTECODE_LIST(TEST_BYTECODE) | |
317 #undef TEST_BYTECODE | |
318 } | |
319 | |
320 #undef OR_IS_BYTECODE | |
321 #undef IN_BYTECODE_LIST | |
322 | |
203 TEST(OperandScale, PrefixesRequired) { | 323 TEST(OperandScale, PrefixesRequired) { |
204 CHECK(!Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kSingle)); | 324 CHECK(!Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kSingle)); |
205 CHECK(Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kDouble)); | 325 CHECK(Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kDouble)); |
206 CHECK( | 326 CHECK( |
207 Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kQuadruple)); | 327 Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kQuadruple)); |
208 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kDouble) == | 328 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kDouble) == |
209 Bytecode::kWide); | 329 Bytecode::kWide); |
210 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kQuadruple) == | 330 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kQuadruple) == |
211 Bytecode::kExtraWide); | 331 Bytecode::kExtraWide); |
212 } | 332 } |
(...skipping 20 matching lines...) Expand all Loading... | |
233 AccumulatorUse::kWrite); | 353 AccumulatorUse::kWrite); |
234 CHECK(Bytecodes::ReadsAccumulator(Bytecode::kAdd)); | 354 CHECK(Bytecodes::ReadsAccumulator(Bytecode::kAdd)); |
235 CHECK(Bytecodes::WritesAccumulator(Bytecode::kAdd)); | 355 CHECK(Bytecodes::WritesAccumulator(Bytecode::kAdd)); |
236 CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kAdd), | 356 CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kAdd), |
237 AccumulatorUse::kReadWrite); | 357 AccumulatorUse::kReadWrite); |
238 } | 358 } |
239 | 359 |
240 } // namespace interpreter | 360 } // namespace interpreter |
241 } // namespace internal | 361 } // namespace internal |
242 } // namespace v8 | 362 } // namespace v8 |
OLD | NEW |