Chromium Code Reviews| Index: test/cctest/interpreter/test-bytecode-generator.cc |
| diff --git a/test/cctest/interpreter/test-bytecode-generator.cc b/test/cctest/interpreter/test-bytecode-generator.cc |
| index bff48bcce1a3447d7d1ab9d1fe18df29e985d832..52938b1f1649c58e0d2cdda8111e47a7b4954ae2 100644 |
| --- a/test/cctest/interpreter/test-bytecode-generator.cc |
| +++ b/test/cctest/interpreter/test-bytecode-generator.cc |
| @@ -64,7 +64,7 @@ struct ExpectedSnippet { |
| int frame_size; |
| int parameter_count; |
| int bytecode_length; |
| - const uint8_t bytecode[32]; |
| + const uint8_t bytecode[512]; |
| int constant_count; |
| T constants[16]; |
| }; |
| @@ -608,6 +608,101 @@ TEST(PropertyCall) { |
| } |
| } |
| + |
| +TEST(IfConditions) { |
| + InitializedHandleScope handle_scope; |
| + BytecodeGeneratorHelper helper; |
| + |
| + ExpectedSnippet<void*> snippets[] = { |
| + {"function f() { if (0) { return 1; } else { return -1; } }", |
| + 0, |
| + 1, |
| + 14, |
| + {B(LdaZero), B(CastToBoolean), B(JumpIfFalse), U8(7), B(LdaSmi8), U8(1), |
| + B(Return), B(Jump), |
| + U8(5), // TODO(oth): Fix implicit return so dead-jump has |
| + // a valid target. |
|
rmcilroy
2015/09/23 14:00:29
Is the todo done?
oth
2015/09/24 11:15:27
No, there needs to be code to evaluate whether the
rmcilroy
2015/09/24 11:44:36
Right - I was confused about what the comment mean
|
| + B(LdaSmi8), U8(-1), B(Return), B(LdaUndefined), B(Return)}}, |
|
rmcilroy
2015/09/23 14:00:29
nit - I know git cl format messes this format up,
oth
2015/09/24 11:15:28
Done.
|
| + {"function f() { if ('lucky') { return 1; } else { return -1; } }", |
| + 0, |
| + 1, |
| + 15, |
| + {B(LdaConstant), U8(0), B(CastToBoolean), B(JumpIfFalse), U8(7), |
| + B(LdaSmi8), U8(1), B(Return), B(Jump), |
| + U8(5), // TODO(oth): Fix implicit return so dead-jump has |
| + // a valid target. |
| + B(LdaSmi8), U8(-1), B(Return), B(LdaUndefined), B(Return)}}, |
| + {"function f() { if (false) { return 1; } else { return -1; } }", |
| + 0, |
| + 1, |
| + 13, |
| + {B(LdaFalse), B(JumpIfFalse), U8(7), B(LdaSmi8), U8(1), B(Return), |
| + B(Jump), |
| + U8(5), // TODO(oth): Fix implicit return so dead-jump has |
| + // a valid target. |
| + B(LdaSmi8), U8(-1), B(Return), B(LdaUndefined), B(Return)}}, |
| + {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }", |
| + kPointerSize, |
| + 2, |
| + 19, |
| + {B(Ldar), R(-5), B(Star), R(0), B(LdaZero), B(TestLessThanEqual), R(0), |
| + B(JumpIfFalse), U8(7), B(LdaConstant), U8(0), B(Return), B(Jump), |
| + U8(5), // TODO(oth): Fix implicit return so dead-jump has |
| + // a valid target. |
| + B(LdaConstant), U8(1), B(Return), B(LdaUndefined), B(Return)}}, |
| + {"function f(a, b) { if (a in b) { return 200; } }", |
| + kPointerSize, |
| + 3, |
| + 17, |
| + {B(Ldar), R(-6), B(Star), R(0), B(Ldar), R(-5), B(TestIn), R(0), |
| + B(JumpIfFalse), U8(7), B(LdaConstant), U8(0), B(Return), B(Jump), |
| + U8(2), // TODO(oth): Fix implicit return so dead-jump has |
| + // a valid target. |
| + B(LdaUndefined), B(Return)}}, |
| + {"function f(a, b) { if (a instanceof b) { return 200; } }", |
| + kPointerSize, |
| + 3, |
| + 17, |
| + {B(Ldar), R(-6), B(Star), R(0), B(Ldar), R(-5), B(TestInstanceOf), R(0), |
| + B(JumpIfFalse), U8(7), B(LdaConstant), U8(0), B(Return), B(Jump), |
| + U8(2), // TODO(oth): Fix implicit return so dead-jump has |
| + // a valid target. |
| + B(LdaUndefined), B(Return)}}, |
| + {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " |
| +// Force a jump using a constant pool entry. |
| +#define X "b = a; a = b; " |
| + X X X X X X X X X X X X X X X X X X X X X X X X |
| +#undef X |
| + " return 200; } else { return -200; } }", |
| + 3 * kPointerSize, |
| + 2, |
| + 218, |
| + {B(LdaZero), B(Star), R(0), B(LdaZero), B(Star), R(1), B(Ldar), R(0), |
| + B(Star), R(2), B(LdaConstant), U8(0), B(TestEqualStrict), R(2), |
| + B(JumpIfFalseConstant), U8(2), |
| +#define X B(Ldar), R(0), B(Star), R(1), B(Ldar), R(1), B(Star), R(0), |
| + X X X X X X X X X X X X X X X X X X X X X X X X |
| +#undef X |
| + B(LdaConstant), |
| + U8(1), B(Return), B(Jump), |
| + U8(5), // TODO(oth): Fix implicit return so dead-jump has |
| + // a valid target. |
| + B(LdaConstant), U8(3), B(Return), B(LdaUndefined), B(Return)}}, |
| + }; |
|
rmcilroy
2015/09/23 14:00:29
could you add the expected constant pool entry her
oth
2015/09/24 11:15:28
Done.
|
| + |
| + size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); |
| + for (size_t i = 0; i < num_snippets; i++) { |
| + Handle<BytecodeArray> ba = |
| + helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
| + CHECK_EQ(ba->frame_size(), snippets[i].frame_size); |
| + CHECK_EQ(ba->parameter_count(), snippets[i].parameter_count); |
| + CHECK_EQ(ba->length(), snippets[i].bytecode_length); |
| + CHECK(!memcmp(ba->GetFirstBytecodeAddress(), snippets[i].bytecode, |
| + ba->length())); |
| + } |
| +} |
| + |
| + |
| } // namespace interpreter |
| } // namespace internal |
| } // namespance v8 |