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 7e8e2a26c19c4110a00268d2638f11fd1ae38d02..2ba98ab2a26deb1bb3cdd0999c26a712db4fe491 100644 |
--- a/test/cctest/interpreter/test-bytecode-generator.cc |
+++ b/test/cctest/interpreter/test-bytecode-generator.cc |
@@ -259,134 +259,133 @@ TEST(PrimitiveExpressions) { |
InitializedHandleScope handle_scope; |
BytecodeGeneratorHelper helper; |
- ExpectedSnippet<int> snippets[] = { |
- {"var x = 0; return x;", |
- kPointerSize, |
- 1, |
- 4, |
- {B(LdaZero), // |
- B(Star), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 0; return x + 3;", |
- kPointerSize, |
- 1, |
- 8, |
- {B(LdaZero), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(3), // |
- B(Add), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 0; return x - 3;", |
- kPointerSize, |
- 1, |
- 8, |
- {B(LdaZero), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(3), // |
- B(Sub), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 4; return x * 3;", |
- kPointerSize, |
- 1, |
- 9, |
- {B(LdaSmi8), U8(4), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(3), // |
- B(Mul), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 4; return x / 3;", |
- kPointerSize, |
- 1, |
- 9, |
- {B(LdaSmi8), U8(4), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(3), // |
- B(Div), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 4; return x % 3;", |
- kPointerSize, |
- 1, |
- 9, |
- {B(LdaSmi8), U8(4), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(3), // |
- B(Mod), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 1; return x | 2;", |
- kPointerSize, |
- 1, |
- 9, |
- {B(LdaSmi8), U8(1), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(2), // |
- B(BitwiseOr), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 1; return x ^ 2;", |
- kPointerSize, |
- 1, |
- 9, |
- {B(LdaSmi8), U8(1), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(2), // |
- B(BitwiseXor), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 1; return x & 2;", |
- kPointerSize, |
- 1, |
- 9, |
- {B(LdaSmi8), U8(1), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(2), // |
- B(BitwiseAnd), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 10; return x << 3;", |
- kPointerSize, |
- 1, |
- 9, |
- {B(LdaSmi8), U8(10), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(3), // |
- B(ShiftLeft), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 10; return x >> 3;", |
- kPointerSize, |
- 1, |
- 9, |
- {B(LdaSmi8), U8(10), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(3), // |
- B(ShiftRight), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 10; return x >>> 3;", |
- kPointerSize, |
- 1, |
- 9, |
- {B(LdaSmi8), U8(10), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(3), // |
- B(ShiftRightLogical), R(0), // |
- B(Return)}, |
- 0}, |
- {"var x = 0; return (x, 3);", |
- kPointerSize, |
- 1, |
- 6, |
- {B(LdaZero), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(3), // |
- B(Return)}, |
- 0}}; |
+ ExpectedSnippet<int> snippets[] = {{"var x = 0; return x;", |
+ kPointerSize, |
+ 1, |
+ 4, |
+ {B(LdaZero), // |
+ B(Star), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 0; return x + 3;", |
+ kPointerSize, |
+ 1, |
+ 8, |
+ {B(LdaZero), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(3), // |
+ B(Add), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 0; return x - 3;", |
+ kPointerSize, |
+ 1, |
+ 8, |
+ {B(LdaZero), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(3), // |
+ B(Sub), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 4; return x * 3;", |
+ kPointerSize, |
+ 1, |
+ 9, |
+ {B(LdaSmi8), U8(4), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(3), // |
+ B(Mul), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 4; return x / 3;", |
+ kPointerSize, |
+ 1, |
+ 9, |
+ {B(LdaSmi8), U8(4), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(3), // |
+ B(Div), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 4; return x % 3;", |
+ kPointerSize, |
+ 1, |
+ 9, |
+ {B(LdaSmi8), U8(4), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(3), // |
+ B(Mod), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 1; return x | 2;", |
+ kPointerSize, |
+ 1, |
+ 9, |
+ {B(LdaSmi8), U8(1), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(2), // |
+ B(BitwiseOr), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 1; return x ^ 2;", |
+ kPointerSize, |
+ 1, |
+ 9, |
+ {B(LdaSmi8), U8(1), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(2), // |
+ B(BitwiseXor), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 1; return x & 2;", |
+ kPointerSize, |
+ 1, |
+ 9, |
+ {B(LdaSmi8), U8(1), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(2), // |
+ B(BitwiseAnd), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 10; return x << 3;", |
+ kPointerSize, |
+ 1, |
+ 9, |
+ {B(LdaSmi8), U8(10), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(3), // |
+ B(ShiftLeft), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 10; return x >> 3;", |
+ kPointerSize, |
+ 1, |
+ 9, |
+ {B(LdaSmi8), U8(10), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(3), // |
+ B(ShiftRight), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 10; return x >>> 3;", |
+ kPointerSize, |
+ 1, |
+ 9, |
+ {B(LdaSmi8), U8(10), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(3), // |
+ B(ShiftRightLogical), R(0), // |
+ B(Return)}, |
+ 0}, |
+ {"var x = 0; return (x, 3);", |
+ kPointerSize, |
+ 1, |
+ 6, |
+ {B(LdaZero), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(3), // |
+ B(Return)}, |
+ 0}}; |
for (size_t i = 0; i < arraysize(snippets); i++) { |
Handle<BytecodeArray> bytecode_array = |
@@ -472,9 +471,8 @@ TEST(LogicalExpressions) { |
B(LdaSmi8), U8(3), // |
B(Return)}, |
0}, |
- {"var x = 1; var a = 2, b = 3; return x || (" |
- REPEAT_32(SPACE, "a = 1, b = 2, ") |
- "3);", |
+ {"var x = 1; var a = 2, b = 3; return x || (" REPEAT_32( |
+ SPACE, "a = 1, b = 2, ") "3);", |
3 * kPointerSize, |
1, |
275, |
@@ -487,17 +485,17 @@ TEST(LogicalExpressions) { |
B(Ldar), R(0), // |
B(JumpIfToBooleanTrueConstant), U8(0), // |
REPEAT_32(COMMA, // |
- B(LdaSmi8), U8(1), // |
- B(Star), R(1), // |
- B(LdaSmi8), U8(2), // |
- B(Star), R(2)), // |
- B(LdaSmi8), U8(3), // |
+ B(LdaSmi8), U8(1), // |
+ B(Star), R(1), // |
+ B(LdaSmi8), U8(2), // |
+ B(Star), R(2)), // |
+ B(LdaSmi8), |
+ U8(3), // |
B(Return)}, |
1, |
{260, 0, 0, 0}}, |
- {"var x = 0; var a = 2, b = 3; return x && (" |
- REPEAT_32(SPACE, "a = 1, b = 2, ") |
- "3);", |
+ {"var x = 0; var a = 2, b = 3; return x && (" REPEAT_32( |
+ SPACE, "a = 1, b = 2, ") "3);", |
3 * kPointerSize, |
1, |
274, |
@@ -510,17 +508,17 @@ TEST(LogicalExpressions) { |
B(Ldar), R(0), // |
B(JumpIfToBooleanFalseConstant), U8(0), // |
REPEAT_32(COMMA, // |
- B(LdaSmi8), U8(1), // |
- B(Star), R(1), // |
- B(LdaSmi8), U8(2), // |
- B(Star), R(2)), // |
- B(LdaSmi8), U8(3), // |
- B(Return)}, // |
+ B(LdaSmi8), U8(1), // |
+ B(Star), R(1), // |
+ B(LdaSmi8), U8(2), // |
+ B(Star), R(2)), // |
+ B(LdaSmi8), |
+ U8(3), // |
+ B(Return)}, // |
1, |
{260, 0, 0, 0}}, |
- {"var x = 1; var a = 2, b = 3; return (x > 3) || (" |
- REPEAT_32(SPACE, "a = 1, b = 2, ") |
- "3);", |
+ {"var x = 1; var a = 2, b = 3; return (x > 3) || (" REPEAT_32( |
+ SPACE, "a = 1, b = 2, ") "3);", |
3 * kPointerSize, |
1, |
277, |
@@ -534,17 +532,17 @@ TEST(LogicalExpressions) { |
B(TestGreaterThan), R(0), // |
B(JumpIfTrueConstant), U8(0), // |
REPEAT_32(COMMA, // |
- B(LdaSmi8), U8(1), // |
- B(Star), R(1), // |
- B(LdaSmi8), U8(2), // |
- B(Star), R(2)), // |
- B(LdaSmi8), U8(3), // |
+ B(LdaSmi8), U8(1), // |
+ B(Star), R(1), // |
+ B(LdaSmi8), U8(2), // |
+ B(Star), R(2)), // |
+ B(LdaSmi8), |
+ U8(3), // |
B(Return)}, |
1, |
{260, 0, 0, 0}}, |
- {"var x = 0; var a = 2, b = 3; return (x < 5) && (" |
- REPEAT_32(SPACE, "a = 1, b = 2, ") |
- "3);", |
+ {"var x = 0; var a = 2, b = 3; return (x < 5) && (" REPEAT_32( |
+ SPACE, "a = 1, b = 2, ") "3);", |
3 * kPointerSize, |
1, |
276, |
@@ -558,11 +556,12 @@ TEST(LogicalExpressions) { |
B(TestLessThan), R(0), // |
B(JumpIfFalseConstant), U8(0), // |
REPEAT_32(COMMA, // |
- B(LdaSmi8), U8(1), // |
- B(Star), R(1), // |
- B(LdaSmi8), U8(2), // |
- B(Star), R(2)), // |
- B(LdaSmi8), U8(3), // |
+ B(LdaSmi8), U8(1), // |
+ B(Star), R(1), // |
+ B(LdaSmi8), U8(2), // |
+ B(Star), R(2)), // |
+ B(LdaSmi8), |
+ U8(3), // |
B(Return)}, |
1, |
{260, 0, 0, 0}}, |
@@ -1270,21 +1269,21 @@ TEST(PropertyCall) { |
}, |
1, |
{"func"}}, |
- {"function f(a) {\n" |
- REPEAT_127(SPACE, " a.func;\n") |
- " return a.func(); }\nf(" FUNC_ARG ")", |
+ {"function f(a) {\n" REPEAT_127( |
+ SPACE, " a.func;\n") " return a.func(); }\nf(" FUNC_ARG ")", |
2 * kPointerSize, |
2, |
528, |
{ |
- REPEAT_127(COMMA, // |
- B(LoadICSloppy), A(1, 2), U8(0), U8((wide_idx += 2))), // |
- B(Ldar), A(1, 2), // |
- B(Star), R(1), // |
- B(LoadICSloppyWide), R(1), U16(0), U16(wide_idx + 4), // |
- B(Star), R(0), // |
- B(CallWide), R(0), R(1), U16(0), U16(wide_idx + 2), // |
- B(Return), // |
+ REPEAT_127(COMMA, // |
+ B(LoadICSloppy), A(1, 2), U8(0), U8((wide_idx += 2))), // |
+ B(Ldar), |
+ A(1, 2), // |
+ B(Star), R(1), // |
+ B(LoadICSloppyWide), R(1), U16(0), U16(wide_idx + 4), // |
+ B(Star), R(0), // |
+ B(CallWide), R(0), R(1), U16(0), U16(wide_idx + 2), // |
+ B(Return), // |
}, |
1, |
{"func"}}, |
@@ -1731,58 +1730,58 @@ TEST(IfConditions) { |
1, |
{helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused, |
unused}}, |
- {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " |
- REPEAT_64(SPACE, "b = a; a = b; ") |
- " return 200; } else { return -200; } } f(0.001)", |
+ {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " REPEAT_64( |
+ SPACE, |
+ "b = a; a = b; ") " return 200; } else { return -200; } } f(0.001)", |
2 * kPointerSize, |
2, |
278, |
- { |
- B(LdaZero), // |
- B(Star), R(0), // |
- B(LdaZero), // |
- B(Star), R(1), // |
- B(LdaConstant), U8(0), // |
- B(TestEqualStrict), R(0), // |
- B(JumpIfFalseConstant), U8(2), // |
- B(Ldar), R(0), // |
- REPEAT_64(COMMA, // |
- B(Star), R(1), // |
- B(Star), R(0)), // |
- B(LdaConstant), U8(1), // |
- B(Return), // |
- B(LdaConstant), U8(3), // |
- B(Return), // |
- B(LdaUndefined), // |
- B(Return)}, // |
+ {B(LdaZero), // |
+ B(Star), R(0), // |
+ B(LdaZero), // |
+ B(Star), R(1), // |
+ B(LdaConstant), U8(0), // |
+ B(TestEqualStrict), R(0), // |
+ B(JumpIfFalseConstant), U8(2), // |
+ B(Ldar), R(0), // |
+ REPEAT_64(COMMA, // |
+ B(Star), R(1), // |
+ B(Star), R(0)), // |
+ B(LdaConstant), |
+ U8(1), // |
+ B(Return), // |
+ B(LdaConstant), U8(3), // |
+ B(Return), // |
+ B(LdaUndefined), // |
+ B(Return)}, // |
4, |
{helper.factory()->NewHeapNumber(0.01), |
helper.factory()->NewNumberFromInt(200), |
helper.factory()->NewNumberFromInt(263), |
helper.factory()->NewNumberFromInt(-200), unused, unused}}, |
- {"function f() { var a = 0; var b = 0; if (a) { " |
- REPEAT_64(SPACE, "b = a; a = b; ") |
- " return 200; } else { return -200; } } f()", |
+ {"function f() { var a = 0; var b = 0; if (a) { " REPEAT_64( |
+ SPACE, |
+ "b = a; a = b; ") " return 200; } else { return -200; } } f()", |
2 * kPointerSize, |
1, |
276, |
- { |
- B(LdaZero), // |
- B(Star), R(0), // |
- B(LdaZero), // |
- B(Star), R(1), // |
- B(Ldar), R(0), // |
- B(JumpIfToBooleanFalseConstant), U8(1), // |
- B(Ldar), R(0), // |
- REPEAT_64(COMMA, // |
- B(Star), R(1), // |
- B(Star), R(0)), // |
- B(LdaConstant), U8(0), // |
- B(Return), // |
- B(LdaConstant), U8(2), // |
- B(Return), // |
- B(LdaUndefined), // |
- B(Return)}, // |
+ {B(LdaZero), // |
+ B(Star), R(0), // |
+ B(LdaZero), // |
+ B(Star), R(1), // |
+ B(Ldar), R(0), // |
+ B(JumpIfToBooleanFalseConstant), U8(1), // |
+ B(Ldar), R(0), // |
+ REPEAT_64(COMMA, // |
+ B(Star), R(1), // |
+ B(Star), R(0)), // |
+ B(LdaConstant), |
+ U8(0), // |
+ B(Return), // |
+ B(LdaConstant), U8(2), // |
+ B(Return), // |
+ B(LdaUndefined), // |
+ B(Return)}, // |
3, |
{helper.factory()->NewNumberFromInt(200), |
helper.factory()->NewNumberFromInt(263), |
@@ -1833,17 +1832,15 @@ TEST(IfConditions) { |
1 * kPointerSize, |
1, |
13, |
- { |
- B(LdaZero), // |
- B(Star), R(0), // |
- B(JumpIfToBooleanFalse), U8(5), // |
- B(LdaSmi8), U8(20), // |
- B(Return), // |
- B(LdaSmi8), U8(-20), // |
- B(Return), // |
- B(LdaUndefined), // |
- B(Return) |
- }, |
+ {B(LdaZero), // |
+ B(Star), R(0), // |
+ B(JumpIfToBooleanFalse), U8(5), // |
+ B(LdaSmi8), U8(20), // |
+ B(Return), // |
+ B(LdaSmi8), U8(-20), // |
+ B(Return), // |
+ B(LdaUndefined), // |
+ B(Return)}, |
0, |
{unused, unused, unused, unused, unused, unused}}}; |
@@ -1934,7 +1931,7 @@ TEST(DeclareGlobals) { |
B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3), // |
B(LdaSmi8), U8(2), // |
B(StaGlobalSloppy), U8(1), // |
- U8(store_vector->GetIndex(store_slot_2)), // |
+ U8(store_vector->GetIndex(store_slot_2)), // |
B(Star), R(0), // |
B(Return) // |
}, |
@@ -1946,20 +1943,20 @@ TEST(DeclareGlobals) { |
1, |
28, |
{ |
- B(LdaConstant), U8(0), // |
- B(Star), R(1), // |
- B(LdaZero), // |
- B(Star), R(2), // |
- B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // |
- B(LdaUndefined), // |
- B(Star), R(2), // |
- B(LdaGlobalSloppy), U8(1), // |
- U8(load_vector->GetIndex(load_slot_1)), // |
- B(Star), R(1), // |
- B(Call), R(1), R(2), U8(0), // |
- U8(load_vector->GetIndex(call_slot_1)), // |
- B(Star), R(0), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(Star), R(1), // |
+ B(LdaZero), // |
+ B(Star), R(2), // |
+ B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // |
+ B(LdaUndefined), // |
+ B(Star), R(2), // |
+ B(LdaGlobalSloppy), U8(1), // |
+ U8(load_vector->GetIndex(load_slot_1)), // |
+ B(Star), R(1), // |
+ B(Call), R(1), R(2), U8(0), // |
+ U8(load_vector->GetIndex(call_slot_1)), // |
+ B(Star), R(0), // |
+ B(Return) // |
}, |
2, |
{InstanceType::FIXED_ARRAY_TYPE, |
@@ -2202,7 +2199,7 @@ TEST(BasicLoops) { |
B(JumpIfToBooleanTrue), U8(-14), // |
B(Ldar), R(1), // |
B(Return), // |
- }, |
+ }, |
0}, |
{"var x = 10;" |
"var y = 1;" |
@@ -2402,123 +2399,122 @@ TEST(UnaryOperators) { |
InitializedHandleScope handle_scope; |
BytecodeGeneratorHelper helper; |
- ExpectedSnippet<int> snippets[] = { |
- {"var x = 0;" |
- "while (x != 10) {" |
- " x = x + 10;" |
- "}" |
- "return x;", |
- kPointerSize, |
- 1, |
- 21, |
- { |
- B(LdaZero), // |
- B(Star), R(0), // |
- B(Jump), U8(8), // |
- B(LdaSmi8), U8(10), // |
- B(Add), R(0), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(10), // |
- B(TestEqual), R(0), // |
- B(LogicalNot), // |
- B(JumpIfTrue), U8(-11), // |
- B(Ldar), R(0), // |
- B(Return), // |
- }, |
- 0}, |
- {"var x = false;" |
- "do {" |
- " x = !x;" |
- "} while(x == false);" |
- "return x;", |
- kPointerSize, |
- 1, |
- 16, |
- { |
- B(LdaFalse), // |
- B(Star), R(0), // |
- B(Ldar), R(0), // |
- B(LogicalNot), // |
- B(Star), R(0), // |
- B(LdaFalse), // |
- B(TestEqual), R(0), // |
- B(JumpIfTrue), U8(-8), // |
- B(Ldar), R(0), // |
- B(Return), // |
- }, |
- 0}, |
- {"var x = 101;" |
- "return void(x * 3);", |
- kPointerSize, |
- 1, |
- 10, |
- { |
- B(LdaSmi8), U8(101), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(3), // |
- B(Mul), R(0), // |
- B(LdaUndefined), // |
- B(Return), // |
- }, |
- 0}, |
- {"var x = 1234;" |
- "var y = void (x * x - 1);" |
- "return y;", |
- 3 * kPointerSize, |
- 1, |
- 16, |
- { |
- B(LdaConstant), U8(0), // |
- B(Star), R(0), // |
- B(Mul), R(0), // |
- B(Star), R(2), // |
- B(LdaSmi8), U8(1), // |
- B(Sub), R(2), // |
- B(LdaUndefined), // |
- B(Star), R(1), // |
- B(Return), // |
- }, |
- 1, |
- {1234}}, |
- {"var x = 13;" |
- "return ~x;", |
- 1 * kPointerSize, |
- 1, |
- 9, |
- { |
- B(LdaSmi8), U8(13), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(-1), // |
- B(BitwiseXor), R(0), // |
- B(Return), // |
- }, |
- 0}, |
- {"var x = 13;" |
- "return +x;", |
- 1 * kPointerSize, |
- 1, |
- 9, |
- { |
- B(LdaSmi8), U8(13), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(1), // |
- B(Mul), R(0), // |
- B(Return), // |
- }, |
- 0}, |
- {"var x = 13;" |
- "return -x;", |
- 1 * kPointerSize, |
- 1, |
- 9, |
- { |
- B(LdaSmi8), U8(13), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(-1), // |
- B(Mul), R(0), // |
- B(Return), // |
- }, |
- 0}}; |
+ ExpectedSnippet<int> snippets[] = {{"var x = 0;" |
+ "while (x != 10) {" |
+ " x = x + 10;" |
+ "}" |
+ "return x;", |
+ kPointerSize, |
+ 1, |
+ 21, |
+ { |
+ B(LdaZero), // |
+ B(Star), R(0), // |
+ B(Jump), U8(8), // |
+ B(LdaSmi8), U8(10), // |
+ B(Add), R(0), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(10), // |
+ B(TestEqual), R(0), // |
+ B(LogicalNot), // |
+ B(JumpIfTrue), U8(-11), // |
+ B(Ldar), R(0), // |
+ B(Return), // |
+ }, |
+ 0}, |
+ {"var x = false;" |
+ "do {" |
+ " x = !x;" |
+ "} while(x == false);" |
+ "return x;", |
+ kPointerSize, |
+ 1, |
+ 16, |
+ { |
+ B(LdaFalse), // |
+ B(Star), R(0), // |
+ B(Ldar), R(0), // |
+ B(LogicalNot), // |
+ B(Star), R(0), // |
+ B(LdaFalse), // |
+ B(TestEqual), R(0), // |
+ B(JumpIfTrue), U8(-8), // |
+ B(Ldar), R(0), // |
+ B(Return), // |
+ }, |
+ 0}, |
+ {"var x = 101;" |
+ "return void(x * 3);", |
+ kPointerSize, |
+ 1, |
+ 10, |
+ { |
+ B(LdaSmi8), U8(101), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(3), // |
+ B(Mul), R(0), // |
+ B(LdaUndefined), // |
+ B(Return), // |
+ }, |
+ 0}, |
+ {"var x = 1234;" |
+ "var y = void (x * x - 1);" |
+ "return y;", |
+ 3 * kPointerSize, |
+ 1, |
+ 16, |
+ { |
+ B(LdaConstant), U8(0), // |
+ B(Star), R(0), // |
+ B(Mul), R(0), // |
+ B(Star), R(2), // |
+ B(LdaSmi8), U8(1), // |
+ B(Sub), R(2), // |
+ B(LdaUndefined), // |
+ B(Star), R(1), // |
+ B(Return), // |
+ }, |
+ 1, |
+ {1234}}, |
+ {"var x = 13;" |
+ "return ~x;", |
+ 1 * kPointerSize, |
+ 1, |
+ 9, |
+ { |
+ B(LdaSmi8), U8(13), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(-1), // |
+ B(BitwiseXor), R(0), // |
+ B(Return), // |
+ }, |
+ 0}, |
+ {"var x = 13;" |
+ "return +x;", |
+ 1 * kPointerSize, |
+ 1, |
+ 9, |
+ { |
+ B(LdaSmi8), U8(13), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(1), // |
+ B(Mul), R(0), // |
+ B(Return), // |
+ }, |
+ 0}, |
+ {"var x = 13;" |
+ "return -x;", |
+ 1 * kPointerSize, |
+ 1, |
+ 9, |
+ { |
+ B(LdaSmi8), U8(13), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(-1), // |
+ B(Mul), R(0), // |
+ B(Return), // |
+ }, |
+ 0}}; |
for (size_t i = 0; i < arraysize(snippets); i++) { |
Handle<BytecodeArray> bytecode_array = |
@@ -2561,10 +2557,10 @@ TEST(Typeof) { |
1, |
5, |
{ |
- B(LdaGlobalInsideTypeofSloppy), U8(0), // |
- U8(vector->GetIndex(slot)), // |
- B(TypeOf), // |
- B(Return), // |
+ B(LdaGlobalInsideTypeofSloppy), U8(0), // |
+ U8(vector->GetIndex(slot)), // |
+ B(TypeOf), // |
+ B(Return), // |
}, |
1, |
{"x"}}, |
@@ -2577,10 +2573,10 @@ TEST(Typeof) { |
1, |
5, |
{ |
- B(LdaGlobalInsideTypeofStrict), U8(0), // |
- U8(vector->GetIndex(slot)), // |
- B(TypeOf), // |
- B(Return), // |
+ B(LdaGlobalInsideTypeofStrict), U8(0), // |
+ U8(vector->GetIndex(slot)), // |
+ B(TypeOf), // |
+ B(Return), // |
}, |
1, |
{"x"}}, |
@@ -2608,14 +2604,12 @@ TEST(Delete) { |
1 * kPointerSize, |
1, |
12, |
- { |
- B(LdaConstant), U8(0), // |
- B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
- B(Star), R(0), // |
- B(LdaConstant), U8(1), // |
- B(DeletePropertySloppy), R(0), // |
- B(Return) |
- }, |
+ {B(LdaConstant), U8(0), // |
+ B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(1), // |
+ B(DeletePropertySloppy), R(0), // |
+ B(Return)}, |
2, |
{InstanceType::FIXED_ARRAY_TYPE, |
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
@@ -2623,14 +2617,12 @@ TEST(Delete) { |
1 * kPointerSize, |
1, |
12, |
- { |
- B(LdaConstant), U8(0), // |
- B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
- B(Star), R(0), // |
- B(LdaConstant), U8(1), // |
- B(DeletePropertyStrict), R(0), // |
- B(Return) |
- }, |
+ {B(LdaConstant), U8(0), // |
+ B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(1), // |
+ B(DeletePropertyStrict), R(0), // |
+ B(Return)}, |
2, |
{InstanceType::FIXED_ARRAY_TYPE, |
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
@@ -2638,26 +2630,22 @@ TEST(Delete) { |
1 * kPointerSize, |
1, |
12, |
- { |
- B(LdaConstant), U8(0), // |
- B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(2), // |
- B(DeletePropertySloppy), R(0), // |
- B(Return) |
- }, |
+ {B(LdaConstant), U8(0), // |
+ B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(2), // |
+ B(DeletePropertySloppy), R(0), // |
+ B(Return)}, |
1, |
{InstanceType::FIXED_ARRAY_TYPE}}, |
{"var a = 10; return delete a;", |
1 * kPointerSize, |
1, |
6, |
- { |
- B(LdaSmi8), U8(10), // |
- B(Star), R(0), // |
- B(LdaFalse), // |
- B(Return) |
- }, |
+ {B(LdaSmi8), U8(10), // |
+ B(Star), R(0), // |
+ B(LdaFalse), // |
+ B(Return)}, |
0}, |
{"'use strict';" |
"var a = {1:10};" |
@@ -2666,20 +2654,18 @@ TEST(Delete) { |
2 * kPointerSize, |
1, |
28, |
- { |
- B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
- R(closure), U8(1), // |
- B(PushContext), R(0), // |
- B(LdaConstant), U8(0), // |
- B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
- B(StaContextSlot), R(0), U8(first_context_slot), // |
- B(CreateClosure), U8(1), U8(0), // |
- B(LdaContextSlot), R(0), U8(first_context_slot), // |
- B(Star), R(1), // |
- B(LdaSmi8), U8(1), // |
- B(DeletePropertyStrict), R(1), // |
- B(Return) |
- }, |
+ {B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
+ R(closure), U8(1), // |
+ B(PushContext), R(0), // |
+ B(LdaConstant), U8(0), // |
+ B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
+ B(StaContextSlot), R(0), U8(first_context_slot), // |
+ B(CreateClosure), U8(1), U8(0), // |
+ B(LdaContextSlot), R(0), U8(first_context_slot), // |
+ B(Star), R(1), // |
+ B(LdaSmi8), U8(1), // |
+ B(DeletePropertyStrict), R(1), // |
+ B(Return)}, |
2, |
{InstanceType::FIXED_ARRAY_TYPE, |
InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
@@ -2687,10 +2673,8 @@ TEST(Delete) { |
0 * kPointerSize, |
1, |
2, |
- { |
- B(LdaTrue), // |
- B(Return) |
- }, |
+ {B(LdaTrue), // |
+ B(Return)}, |
0}, |
}; |
@@ -3140,7 +3124,7 @@ TEST(ObjectLiterals) { |
B(LdaZero), // |
B(Star), R(4), // |
B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // |
- R(0), U8(5), // |
+ R(0), U8(5), // |
B(Ldar), R(0), // |
B(Return), // |
}, |
@@ -3165,7 +3149,7 @@ TEST(ObjectLiterals) { |
B(LdaZero), // |
B(Star), R(4), // |
B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // |
- R(0), U8(5), // |
+ R(0), U8(5), // |
B(Ldar), R(0), // |
B(Return), // |
}, |
@@ -3191,7 +3175,7 @@ TEST(ObjectLiterals) { |
B(LdaZero), // |
B(Star), R(4), // |
B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // |
- R(0), U8(5), // |
+ R(0), U8(5), // |
B(Ldar), R(0), // |
B(Return), // |
}, |
@@ -3254,7 +3238,7 @@ TEST(ObjectLiterals) { |
B(LdaZero), // |
B(Star), R(4), // |
B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), // |
- U8(4), // |
+ U8(4), // |
B(Ldar), R(1), // |
B(Return), // |
}, |
@@ -3281,7 +3265,7 @@ TEST(ObjectLiterals) { |
B(LdaZero), // |
B(Star), R(4), // |
B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), // |
- U8(4), // |
+ U8(4), // |
B(Ldar), R(1), // |
B(Return), // |
}, |
@@ -3307,7 +3291,7 @@ TEST(ObjectLiterals) { |
B(LdaZero), // |
B(Star), R(4), // |
B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), // |
- U8(4), // |
+ U8(4), // |
B(LdaConstant), U8(1), // |
B(CreateObjectLiteral), U8(0), U8(13), // |
B(Star), R(2), // |
@@ -3336,7 +3320,7 @@ TEST(ObjectLiterals) { |
B(LdaZero), // |
B(Star), R(4), // |
B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), // |
- U8(4), // |
+ U8(4), // |
B(LdaConstant), U8(3), // |
B(ToName), // |
B(Star), R(2), // |
@@ -3345,7 +3329,7 @@ TEST(ObjectLiterals) { |
B(LdaZero), // |
B(Star), R(4), // |
B(CallRuntime), U16(Runtime::kDefineGetterPropertyUnchecked), // |
- R(1), U8(4), // |
+ R(1), U8(4), // |
B(LdaConstant), U8(3), // |
B(ToName), // |
B(Star), R(2), // |
@@ -3354,7 +3338,7 @@ TEST(ObjectLiterals) { |
B(LdaZero), // |
B(Star), R(4), // |
B(CallRuntime), U16(Runtime::kDefineSetterPropertyUnchecked), // |
- R(1), U8(4), // |
+ R(1), U8(4), // |
B(Ldar), R(1), // |
B(Return), // |
}, |
@@ -3645,7 +3629,7 @@ TEST(ContextVariables) { |
11, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
- R(closure), U8(1), // |
+ R(closure), U8(1), // |
B(PushContext), R(0), // |
B(CreateClosure), U8(0), U8(0), // |
B(Return), // |
@@ -3658,7 +3642,7 @@ TEST(ContextVariables) { |
16, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
- R(closure), U8(1), // |
+ R(closure), U8(1), // |
B(PushContext), R(0), // |
B(LdaSmi8), U8(1), // |
B(StaContextSlot), R(0), U8(first_context_slot), // |
@@ -3673,7 +3657,7 @@ TEST(ContextVariables) { |
21, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
- R(closure), U8(1), // |
+ R(closure), U8(1), // |
B(PushContext), R(0), // |
B(LdaSmi8), U8(1), // |
B(StaContextSlot), R(0), U8(first_context_slot), // |
@@ -3690,7 +3674,7 @@ TEST(ContextVariables) { |
24, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
- R(closure), U8(1), // |
+ R(closure), U8(1), // |
B(PushContext), R(0), // |
B(LdaUndefined), // |
B(Star), R(2), // |
@@ -3708,7 +3692,7 @@ TEST(ContextVariables) { |
44, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
- R(closure), U8(1), // |
+ R(closure), U8(1), // |
B(PushContext), R(0), // |
B(LdaTheHole), // |
B(StaContextSlot), R(0), U8(first_context_slot), // |
@@ -3754,7 +3738,7 @@ TEST(ContextParameters) { |
16, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
- R(closure), U8(1), // |
+ R(closure), U8(1), // |
B(PushContext), R(0), // |
B(Ldar), R(helper.kLastParamIndex), // |
B(StaContextSlot), R(0), U8(first_context_slot), // |
@@ -3769,7 +3753,7 @@ TEST(ContextParameters) { |
21, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
- R(closure), U8(1), // |
+ R(closure), U8(1), // |
B(PushContext), R(1), // |
B(Ldar), R(helper.kLastParamIndex), // |
B(StaContextSlot), R(1), U8(first_context_slot), // |
@@ -3786,11 +3770,11 @@ TEST(ContextParameters) { |
21, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
- R(closure), U8(1), // |
+ R(closure), U8(1), // |
B(PushContext), R(0), // |
B(Ldar), R(helper.kLastParamIndex - 3), // |
B(StaContextSlot), R(0), U8(first_context_slot + 1), // |
- B(Ldar), R(helper.kLastParamIndex -1), // |
+ B(Ldar), R(helper.kLastParamIndex - 1), // |
B(StaContextSlot), R(0), U8(first_context_slot), // |
B(CreateClosure), U8(0), U8(0), // |
B(Return), // |
@@ -3803,7 +3787,7 @@ TEST(ContextParameters) { |
16, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
- R(closure), U8(1), // |
+ R(closure), U8(1), // |
B(PushContext), R(0), // |
B(Ldar), R(helper.kLastParamIndex), // |
B(StaContextSlot), R(0), U8(first_context_slot), // |
@@ -4048,7 +4032,7 @@ TEST(CountOperators) { |
26, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
- U8(1), // |
+ U8(1), // |
B(PushContext), R(1), // |
B(LdaSmi8), U8(1), // |
B(StaContextSlot), R(1), U8(first_context_slot), // |
@@ -4068,7 +4052,7 @@ TEST(CountOperators) { |
30, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
- U8(1), // |
+ U8(1), // |
B(PushContext), R(1), // |
B(LdaSmi8), U8(1), // |
B(StaContextSlot), R(1), U8(first_context_slot), // |
@@ -4089,20 +4073,20 @@ TEST(CountOperators) { |
1, |
26, |
{ |
- B(LdaSmi8), U8(1), // |
- B(Star), R(0), // |
- B(LdaConstant), U8(0), // |
- B(CreateArrayLiteral), U8(0), U8(array_literal_flags), // |
- B(Star), R(1), // |
- B(Ldar), R(0), // |
- B(ToNumber), // |
- B(Star), R(2), // |
- B(Inc), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(2), // |
- B(KeyedStoreICSloppy), R(1), R(2), // |
- U8(store_vector->GetIndex(store_slot)), // |
- B(Return), // |
+ B(LdaSmi8), U8(1), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(0), // |
+ B(CreateArrayLiteral), U8(0), U8(array_literal_flags), // |
+ B(Star), R(1), // |
+ B(Ldar), R(0), // |
+ B(ToNumber), // |
+ B(Star), R(2), // |
+ B(Inc), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(2), // |
+ B(KeyedStoreICSloppy), R(1), R(2), // |
+ U8(store_vector->GetIndex(store_slot)), // |
+ B(Return), // |
}, |
1, |
{InstanceType::FIXED_ARRAY_TYPE}}, |
@@ -4285,7 +4269,7 @@ TEST(CompoundExpressions) { |
29, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
- U8(1), // |
+ U8(1), // |
B(PushContext), R(0), // |
B(LdaSmi8), U8(1), // |
B(StaContextSlot), R(0), U8(first_context_slot), // |
@@ -4411,7 +4395,7 @@ TEST(CreateArguments) { |
20, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
- U8(1), // |
+ U8(1), // |
B(PushContext), R(1), // |
B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex), // |
B(StaContextSlot), R(1), U8(first_context_slot), // |
@@ -4427,7 +4411,7 @@ TEST(CreateArguments) { |
26, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
- U8(1), // |
+ U8(1), // |
B(PushContext), R(1), // |
B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex - 2), // |
B(StaContextSlot), R(1), U8(first_context_slot + 2), // |
@@ -4911,10 +4895,9 @@ TEST(Switch) { |
}}, |
{"var a = 1;\n" |
"switch(a) {\n" |
- " case 1:\n" REPEAT_64(SPACE, " a = 2;") |
- "break;\n" |
- " case 2: a = 3; break;" |
- "}\n", |
+ " case 1:\n" REPEAT_64(SPACE, " a = 2;") "break;\n" |
+ " case 2: a = 3; break;" |
+ "}\n", |
2 * kPointerSize, |
1, |
286, |
@@ -4930,14 +4913,15 @@ TEST(Switch) { |
B(JumpIfTrueConstant), U8(0), // |
B(JumpConstant), U8(1), // |
REPEAT_64(COMMA, // |
- B(LdaSmi8), U8(2), // |
- B(Star), R(1)), // |
- B(Jump), U8(8), // |
- B(LdaSmi8), U8(3), // |
- B(Star), R(1), // |
- B(Jump), U8(2), // |
- B(LdaUndefined), // |
- B(Return), // |
+ B(LdaSmi8), U8(2), // |
+ B(Star), R(1)), // |
+ B(Jump), |
+ U8(8), // |
+ B(LdaSmi8), U8(3), // |
+ B(Star), R(1), // |
+ B(Jump), U8(2), // |
+ B(LdaUndefined), // |
+ B(Return), // |
}, |
2, |
{262, 266}}, |
@@ -5194,29 +5178,27 @@ TEST(RemoveRedundantLdar) { |
BytecodeGeneratorHelper helper; |
ExpectedSnippet<int> snippets[] = { |
- {"var ld_a = 1;\n" // This test is to check Ldar does not |
- "while(true) {\n" // get removed if the preceding Star is |
- " ld_a = ld_a + ld_a;\n" // in a different basicblock. |
+ {"var ld_a = 1;\n" // This test is to check Ldar does not |
+ "while(true) {\n" // get removed if the preceding Star is |
+ " ld_a = ld_a + ld_a;\n" // in a different basicblock. |
" if (ld_a > 10) break;\n" |
"}\n" |
"return ld_a;", |
1 * kPointerSize, |
1, |
23, |
- { |
- B(LdaSmi8), U8(1), // |
- B(Star), R(0), // |
- B(Ldar), R(0), // This load should not be removed as it |
- B(Add), R(0), // is the target of the branch. |
- B(Star), R(0), // |
- B(LdaSmi8), U8(10), // |
- B(TestGreaterThan), R(0), // |
- B(JumpIfFalse), U8(4), // |
- B(Jump), U8(4), // |
- B(Jump), U8(-14), // |
- B(Ldar), R(0), // |
- B(Return) |
- }}, |
+ {B(LdaSmi8), U8(1), // |
+ B(Star), R(0), // |
+ B(Ldar), R(0), // This load should not be removed as it |
+ B(Add), R(0), // is the target of the branch. |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(10), // |
+ B(TestGreaterThan), R(0), // |
+ B(JumpIfFalse), U8(4), // |
+ B(Jump), U8(4), // |
+ B(Jump), U8(-14), // |
+ B(Ldar), R(0), // |
+ B(Return)}}, |
{"var ld_a = 1;\n" |
"do {\n" |
" ld_a = ld_a + ld_a;\n" |
@@ -5226,18 +5208,16 @@ TEST(RemoveRedundantLdar) { |
1 * kPointerSize, |
1, |
19, |
- { |
- B(LdaSmi8), U8(1), // |
- B(Star), R(0), // |
- B(Add), R(0), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(10), // |
- B(TestGreaterThan), R(0), // |
- B(JumpIfFalse), U8(4), // |
- B(Jump), U8(2), // |
- B(Ldar), R(0), // |
- B(Return) |
- }}, |
+ {B(LdaSmi8), U8(1), // |
+ B(Star), R(0), // |
+ B(Add), R(0), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(10), // |
+ B(TestGreaterThan), R(0), // |
+ B(JumpIfFalse), U8(4), // |
+ B(Jump), U8(2), // |
+ B(Ldar), R(0), // |
+ B(Return)}}, |
}; |
for (size_t i = 0; i < arraysize(snippets); i++) { |