| 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 TestWithIsolateAndZone { |
| 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(), zone()); |
| 23 | 23 |
| 24 builder.set_locals_count(1); | 24 builder.set_locals_count(1); |
| 25 builder.set_parameter_count(0); | 25 builder.set_parameter_count(0); |
| 26 CHECK_EQ(builder.locals_count(), 1); | 26 CHECK_EQ(builder.locals_count(), 1); |
| 27 | 27 |
| 28 // Emit constant loads. | 28 // Emit constant loads. |
| 29 builder.LoadLiteral(Smi::FromInt(0)) | 29 builder.LoadLiteral(Smi::FromInt(0)) |
| 30 .LoadLiteral(Smi::FromInt(8)) | 30 .LoadLiteral(Smi::FromInt(8)) |
| 31 .LoadLiteral(Smi::FromInt(10000000)) |
| 31 .LoadUndefined() | 32 .LoadUndefined() |
| 32 .LoadNull() | 33 .LoadNull() |
| 33 .LoadTheHole() | 34 .LoadTheHole() |
| 34 .LoadTrue() | 35 .LoadTrue() |
| 35 .LoadFalse(); | 36 .LoadFalse(); |
| 36 | 37 |
| 37 // Emit accumulator transfers. | 38 // Emit accumulator transfers. |
| 38 Register reg(0); | 39 Register reg(0); |
| 39 builder.LoadAccumulatorWithRegister(reg).StoreAccumulatorInRegister(reg); | 40 builder.LoadAccumulatorWithRegister(reg).StoreAccumulatorInRegister(reg); |
| 40 | 41 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 /* Check Bytecode is marked in scorecard */ \ | 73 /* Check Bytecode is marked in scorecard */ \ |
| 73 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); | 74 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); |
| 74 BYTECODE_LIST(CHECK_BYTECODE_PRESENT) | 75 BYTECODE_LIST(CHECK_BYTECODE_PRESENT) |
| 75 #undef CHECK_BYTECODE_PRESENT | 76 #undef CHECK_BYTECODE_PRESENT |
| 76 } | 77 } |
| 77 | 78 |
| 78 | 79 |
| 79 TEST_F(BytecodeArrayBuilderTest, FrameSizesLookGood) { | 80 TEST_F(BytecodeArrayBuilderTest, FrameSizesLookGood) { |
| 80 for (int locals = 0; locals < 5; locals++) { | 81 for (int locals = 0; locals < 5; locals++) { |
| 81 for (int temps = 0; temps < 3; temps++) { | 82 for (int temps = 0; temps < 3; temps++) { |
| 82 BytecodeArrayBuilder builder(isolate()); | 83 BytecodeArrayBuilder builder(isolate(), zone()); |
| 83 builder.set_parameter_count(0); | 84 builder.set_parameter_count(0); |
| 84 builder.set_locals_count(locals); | 85 builder.set_locals_count(locals); |
| 85 builder.Return(); | 86 builder.Return(); |
| 86 | 87 |
| 87 TemporaryRegisterScope temporaries(&builder); | 88 TemporaryRegisterScope temporaries(&builder); |
| 88 for (int i = 0; i < temps; i++) { | 89 for (int i = 0; i < temps; i++) { |
| 89 temporaries.NewRegister(); | 90 temporaries.NewRegister(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); | 93 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); |
| 93 int total_registers = locals + temps; | 94 int total_registers = locals + temps; |
| 94 CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize); | 95 CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize); |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 | 99 |
| 99 | 100 |
| 100 TEST_F(BytecodeArrayBuilderTest, TemporariesRecycled) { | 101 TEST_F(BytecodeArrayBuilderTest, TemporariesRecycled) { |
| 101 BytecodeArrayBuilder builder(isolate()); | 102 BytecodeArrayBuilder builder(isolate(), zone()); |
| 102 builder.set_parameter_count(0); | 103 builder.set_parameter_count(0); |
| 103 builder.set_locals_count(0); | 104 builder.set_locals_count(0); |
| 104 builder.Return(); | 105 builder.Return(); |
| 105 | 106 |
| 106 int first; | 107 int first; |
| 107 { | 108 { |
| 108 TemporaryRegisterScope temporaries(&builder); | 109 TemporaryRegisterScope temporaries(&builder); |
| 109 first = temporaries.NewRegister().index(); | 110 first = temporaries.NewRegister().index(); |
| 110 temporaries.NewRegister(); | 111 temporaries.NewRegister(); |
| 111 temporaries.NewRegister(); | 112 temporaries.NewRegister(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 131 | 132 |
| 132 int actual_operand = the_register.ToOperand(); | 133 int actual_operand = the_register.ToOperand(); |
| 133 CHECK_EQ(actual_operand, operand); | 134 CHECK_EQ(actual_operand, operand); |
| 134 | 135 |
| 135 int actual_index = Register::FromOperand(actual_operand).index(); | 136 int actual_index = Register::FromOperand(actual_operand).index(); |
| 136 CHECK_EQ(actual_index, index); | 137 CHECK_EQ(actual_index, index); |
| 137 } | 138 } |
| 138 | 139 |
| 139 | 140 |
| 140 TEST_F(BytecodeArrayBuilderTest, Parameters) { | 141 TEST_F(BytecodeArrayBuilderTest, Parameters) { |
| 141 BytecodeArrayBuilder builder(isolate()); | 142 BytecodeArrayBuilder builder(isolate(), zone()); |
| 142 builder.set_parameter_count(10); | 143 builder.set_parameter_count(10); |
| 143 builder.set_locals_count(0); | 144 builder.set_locals_count(0); |
| 144 | 145 |
| 145 Register param0(builder.Parameter(0)); | 146 Register param0(builder.Parameter(0)); |
| 146 Register param9(builder.Parameter(9)); | 147 Register param9(builder.Parameter(9)); |
| 147 CHECK_EQ(param9.index() - param0.index(), 9); | 148 CHECK_EQ(param9.index() - param0.index(), 9); |
| 148 } | 149 } |
| 149 | 150 |
| 151 |
| 152 TEST_F(BytecodeArrayBuilderTest, Constants) { |
| 153 BytecodeArrayBuilder builder(isolate(), zone()); |
| 154 builder.set_parameter_count(0); |
| 155 builder.set_locals_count(0); |
| 156 |
| 157 Factory* factory = isolate()->factory(); |
| 158 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(3.14); |
| 159 Handle<HeapObject> heap_num_2 = factory->NewHeapNumber(5.2); |
| 160 Handle<Object> large_smi(Smi::FromInt(0x12345678), isolate()); |
| 161 Handle<HeapObject> heap_num_2_copy(*heap_num_2); |
| 162 builder.LoadLiteral(heap_num_1) |
| 163 .LoadLiteral(heap_num_2) |
| 164 .LoadLiteral(large_smi) |
| 165 .LoadLiteral(heap_num_1) |
| 166 .LoadLiteral(heap_num_1) |
| 167 .LoadLiteral(heap_num_2_copy); |
| 168 |
| 169 Handle<BytecodeArray> array = builder.ToBytecodeArray(); |
| 170 // Should only have one entry for each identical constant. |
| 171 CHECK_EQ(array->constant_pool()->length(), 3); |
| 172 } |
| 173 |
| 150 } // namespace interpreter | 174 } // namespace interpreter |
| 151 } // namespace internal | 175 } // namespace internal |
| 152 } // namespace v8 | 176 } // namespace v8 |
| OLD | NEW |