| 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 "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
| 9 #include "test/unittests/test-utils.h" | 9 #include "test/unittests/test-utils.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 namespace interpreter { | 13 namespace interpreter { |
| 14 | 14 |
| 15 class BytecodeArrayBuilderTest : public TestWithIsolateAndZone { | 15 class BytecodeArrayBuilderTest : public TestWithIsolateAndZone { |
| 16 public: | 16 public: |
| 17 BytecodeArrayBuilderTest() {} | 17 BytecodeArrayBuilderTest() {} |
| 18 ~BytecodeArrayBuilderTest() override {} | 18 ~BytecodeArrayBuilderTest() override {} |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 | 21 |
| 22 TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { | 22 TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { |
| 23 BytecodeArrayBuilder builder(isolate(), zone()); | 23 BytecodeArrayBuilder builder(isolate(), zone()); |
| 24 | 24 |
| 25 builder.set_locals_count(1); | 25 builder.set_locals_count(2); |
| 26 builder.set_context_count(1); | 26 builder.set_context_count(1); |
| 27 builder.set_parameter_count(0); | 27 builder.set_parameter_count(0); |
| 28 CHECK_EQ(builder.locals_count(), 1); | 28 CHECK_EQ(builder.locals_count(), 2); |
| 29 CHECK_EQ(builder.context_count(), 1); | 29 CHECK_EQ(builder.context_count(), 1); |
| 30 CHECK_EQ(builder.fixed_register_count(), 2); | 30 CHECK_EQ(builder.fixed_register_count(), 3); |
| 31 | 31 |
| 32 // Emit constant loads. | 32 // Emit constant loads. |
| 33 builder.LoadLiteral(Smi::FromInt(0)) | 33 builder.LoadLiteral(Smi::FromInt(0)) |
| 34 .LoadLiteral(Smi::FromInt(8)) | 34 .LoadLiteral(Smi::FromInt(8)) |
| 35 .LoadLiteral(Smi::FromInt(10000000)) | 35 .LoadLiteral(Smi::FromInt(10000000)) |
| 36 .LoadUndefined() | 36 .LoadUndefined() |
| 37 .LoadNull() | 37 .LoadNull() |
| 38 .LoadTheHole() | 38 .LoadTheHole() |
| 39 .LoadTrue() | 39 .LoadTrue() |
| 40 .LoadFalse(); | 40 .LoadFalse(); |
| 41 | 41 |
| 42 // Emit accumulator transfers. | 42 // Emit accumulator transfers. |
| 43 Register reg(0); | 43 Register reg(0); |
| 44 builder.LoadAccumulatorWithRegister(reg).StoreAccumulatorInRegister(reg); | 44 builder.LoadAccumulatorWithRegister(reg).StoreAccumulatorInRegister(reg); |
| 45 | 45 |
| 46 // Emit register-register transfer. |
| 47 Register other(1); |
| 48 builder.MoveRegister(reg, other); |
| 49 |
| 46 // Emit global load / store operations. | 50 // Emit global load / store operations. |
| 47 builder.LoadGlobal(0, 1, LanguageMode::SLOPPY) | 51 builder.LoadGlobal(0, 1, LanguageMode::SLOPPY) |
| 48 .LoadGlobal(0, 1, LanguageMode::STRICT) | 52 .LoadGlobal(0, 1, LanguageMode::STRICT) |
| 49 .StoreGlobal(0, 1, LanguageMode::SLOPPY) | 53 .StoreGlobal(0, 1, LanguageMode::SLOPPY) |
| 50 .StoreGlobal(0, 1, LanguageMode::STRICT); | 54 .StoreGlobal(0, 1, LanguageMode::STRICT); |
| 51 | 55 |
| 52 // Emit wide global load / store operations. | 56 // Emit wide global load / store operations. |
| 53 builder.LoadGlobal(0, 1024, LanguageMode::SLOPPY) | 57 builder.LoadGlobal(0, 1024, LanguageMode::SLOPPY) |
| 54 .LoadGlobal(1024, 1, LanguageMode::STRICT) | 58 .LoadGlobal(1024, 1, LanguageMode::STRICT) |
| 55 .StoreGlobal(0, 1024, LanguageMode::SLOPPY) | 59 .StoreGlobal(0, 1024, LanguageMode::SLOPPY) |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 680 |
| 677 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 681 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
| 678 iterator.Advance(); | 682 iterator.Advance(); |
| 679 CHECK(iterator.done()); | 683 CHECK(iterator.done()); |
| 680 } | 684 } |
| 681 | 685 |
| 682 | 686 |
| 683 } // namespace interpreter | 687 } // namespace interpreter |
| 684 } // namespace internal | 688 } // namespace internal |
| 685 } // namespace v8 | 689 } // namespace v8 |
| OLD | NEW |