OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/interpreter/bytecode-array-builder.h" | 7 #include "src/interpreter/bytecode-array-builder.h" |
8 #include "test/unittests/test-utils.h" | 8 #include "test/unittests/test-utils.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 namespace interpreter { | 12 namespace interpreter { |
13 | 13 |
14 class BytecodeArrayBuilderTest : public TestWithIsolate { | 14 class BytecodeArrayBuilderTest : public TestWithIsolate { |
15 public: | 15 public: |
16 BytecodeArrayBuilderTest() {} | 16 BytecodeArrayBuilderTest() {} |
17 ~BytecodeArrayBuilderTest() override {} | 17 ~BytecodeArrayBuilderTest() override {} |
18 }; | 18 }; |
19 | 19 |
20 | 20 |
21 TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { | 21 TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { |
22 BytecodeArrayBuilder builder(isolate()); | 22 BytecodeArrayBuilder builder(isolate()); |
23 | 23 |
24 builder.set_locals_count(1); | 24 builder.set_locals_count(1); |
| 25 builder.set_parameter_count(0); |
25 CHECK_EQ(builder.locals_count(), 1); | 26 CHECK_EQ(builder.locals_count(), 1); |
26 | 27 |
27 // Emit constant loads. | 28 // Emit constant loads. |
28 builder.LoadLiteral(Smi::FromInt(0)) | 29 builder.LoadLiteral(Smi::FromInt(0)) |
29 .LoadLiteral(Smi::FromInt(8)) | 30 .LoadLiteral(Smi::FromInt(8)) |
30 .LoadUndefined() | 31 .LoadUndefined() |
31 .LoadNull() | 32 .LoadNull() |
32 .LoadTheHole() | 33 .LoadTheHole() |
33 .LoadTrue() | 34 .LoadTrue() |
34 .LoadFalse(); | 35 .LoadFalse(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); | 73 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); |
73 BYTECODE_LIST(CHECK_BYTECODE_PRESENT) | 74 BYTECODE_LIST(CHECK_BYTECODE_PRESENT) |
74 #undef CHECK_BYTECODE_PRESENT | 75 #undef CHECK_BYTECODE_PRESENT |
75 } | 76 } |
76 | 77 |
77 | 78 |
78 TEST_F(BytecodeArrayBuilderTest, FrameSizesLookGood) { | 79 TEST_F(BytecodeArrayBuilderTest, FrameSizesLookGood) { |
79 for (int locals = 0; locals < 5; locals++) { | 80 for (int locals = 0; locals < 5; locals++) { |
80 for (int temps = 0; temps < 3; temps++) { | 81 for (int temps = 0; temps < 3; temps++) { |
81 BytecodeArrayBuilder builder(isolate()); | 82 BytecodeArrayBuilder builder(isolate()); |
| 83 builder.set_parameter_count(0); |
82 builder.set_locals_count(locals); | 84 builder.set_locals_count(locals); |
83 builder.Return(); | 85 builder.Return(); |
84 | 86 |
85 TemporaryRegisterScope temporaries(&builder); | 87 TemporaryRegisterScope temporaries(&builder); |
86 for (int i = 0; i < temps; i++) { | 88 for (int i = 0; i < temps; i++) { |
87 temporaries.NewRegister(); | 89 temporaries.NewRegister(); |
88 } | 90 } |
89 | 91 |
90 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); | 92 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); |
91 int total_registers = locals + temps; | 93 int total_registers = locals + temps; |
92 CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize); | 94 CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize); |
93 } | 95 } |
94 } | 96 } |
95 } | 97 } |
96 | 98 |
97 | 99 |
98 TEST_F(BytecodeArrayBuilderTest, TemporariesRecycled) { | 100 TEST_F(BytecodeArrayBuilderTest, TemporariesRecycled) { |
99 BytecodeArrayBuilder builder(isolate()); | 101 BytecodeArrayBuilder builder(isolate()); |
| 102 builder.set_parameter_count(0); |
100 builder.set_locals_count(0); | 103 builder.set_locals_count(0); |
101 builder.Return(); | 104 builder.Return(); |
102 | 105 |
103 int first; | 106 int first; |
104 { | 107 { |
105 TemporaryRegisterScope temporaries(&builder); | 108 TemporaryRegisterScope temporaries(&builder); |
106 first = temporaries.NewRegister().index(); | 109 first = temporaries.NewRegister().index(); |
107 temporaries.NewRegister(); | 110 temporaries.NewRegister(); |
108 temporaries.NewRegister(); | 111 temporaries.NewRegister(); |
109 temporaries.NewRegister(); | 112 temporaries.NewRegister(); |
(...skipping 16 matching lines...) Expand all Loading... |
126 Register the_register(index); | 129 Register the_register(index); |
127 CHECK_EQ(the_register.index(), index); | 130 CHECK_EQ(the_register.index(), index); |
128 | 131 |
129 int actual_operand = the_register.ToOperand(); | 132 int actual_operand = the_register.ToOperand(); |
130 CHECK_EQ(actual_operand, operand); | 133 CHECK_EQ(actual_operand, operand); |
131 | 134 |
132 int actual_index = Register::FromOperand(actual_operand).index(); | 135 int actual_index = Register::FromOperand(actual_operand).index(); |
133 CHECK_EQ(actual_index, index); | 136 CHECK_EQ(actual_index, index); |
134 } | 137 } |
135 | 138 |
| 139 |
| 140 TEST_F(BytecodeArrayBuilderTest, Parameters) { |
| 141 BytecodeArrayBuilder builder(isolate()); |
| 142 builder.set_parameter_count(10); |
| 143 builder.set_locals_count(0); |
| 144 |
| 145 Register param0(builder.Parameter(0)); |
| 146 Register param9(builder.Parameter(9)); |
| 147 CHECK_EQ(param9.index() - param0.index(), 9); |
| 148 } |
| 149 |
136 } // namespace interpreter | 150 } // namespace interpreter |
137 } // namespace internal | 151 } // namespace internal |
138 } // namespace v8 | 152 } // namespace v8 |
OLD | NEW |