OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 Factory* factory = isolate()->factory(); | 26 Factory* factory = isolate()->factory(); |
27 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718); | 27 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718); |
28 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647); | 28 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647); |
29 Smi* zero = Smi::FromInt(0); | 29 Smi* zero = Smi::FromInt(0); |
30 Smi* smi_0 = Smi::FromInt(64); | 30 Smi* smi_0 = Smi::FromInt(64); |
31 Smi* smi_1 = Smi::FromInt(-65536); | 31 Smi* smi_1 = Smi::FromInt(-65536); |
32 Register reg_0(0); | 32 Register reg_0(0); |
33 Register reg_1(1); | 33 Register reg_1(1); |
34 Register reg_2 = Register::FromParameterIndex(2, builder.parameter_count()); | 34 Register reg_2 = Register::FromParameterIndex(2, builder.parameter_count()); |
35 Handle<String> name = factory->NewStringFromStaticChars("abc"); | 35 Handle<String> name = factory->NewStringFromStaticChars("abc"); |
36 int name_index = 3; | 36 int name_index = 2; |
37 int feedback_slot = 97; | 37 int feedback_slot = 97; |
38 | 38 |
39 builder.LoadLiteral(heap_num_0) | 39 builder.LoadLiteral(heap_num_0) |
40 .LoadLiteral(heap_num_1) | 40 .LoadLiteral(heap_num_1) |
41 .LoadLiteral(zero) | 41 .LoadLiteral(zero) |
42 .LoadLiteral(smi_0) | 42 .LoadLiteral(smi_0) |
43 .LoadLiteral(smi_1) | 43 .LoadLiteral(smi_1) |
44 .LoadAccumulatorWithRegister(reg_0) | 44 .LoadAccumulatorWithRegister(reg_0) |
45 .LoadNamedProperty(reg_1, name, feedback_slot) | 45 .LoadNamedProperty(reg_1, name, feedback_slot) |
46 .StoreAccumulatorInRegister(reg_2) | 46 .StoreAccumulatorInRegister(reg_2) |
47 .CallRuntime(Runtime::kLoadIC_Miss, reg_0, 1) | 47 .CallRuntime(Runtime::kLoadIC_Miss, reg_0, 1) |
48 .Debugger() | 48 .Debugger() |
| 49 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF) |
49 .Return(); | 50 .Return(); |
50 | 51 |
51 // Test iterator sees the expected output from the builder. | 52 // Test iterator sees the expected output from the builder. |
52 BytecodeArrayIterator iterator(builder.ToBytecodeArray()); | 53 BytecodeArrayIterator iterator(builder.ToBytecodeArray()); |
53 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); | 54 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); |
| 55 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
54 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0)); | 56 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0)); |
55 CHECK(!iterator.done()); | 57 CHECK(!iterator.done()); |
56 iterator.Advance(); | 58 iterator.Advance(); |
57 | 59 |
58 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); | 60 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); |
| 61 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
59 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1)); | 62 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1)); |
60 CHECK(!iterator.done()); | 63 CHECK(!iterator.done()); |
61 iterator.Advance(); | 64 iterator.Advance(); |
62 | 65 |
63 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaZero); | 66 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaZero); |
| 67 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
64 CHECK(!iterator.done()); | 68 CHECK(!iterator.done()); |
65 iterator.Advance(); | 69 iterator.Advance(); |
66 | 70 |
67 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi8); | 71 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi); |
| 72 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
68 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_0); | 73 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_0); |
69 CHECK(!iterator.done()); | 74 CHECK(!iterator.done()); |
70 iterator.Advance(); | 75 iterator.Advance(); |
71 | 76 |
72 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); | 77 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi); |
73 CHECK_EQ(*iterator.GetConstantForIndexOperand(0), smi_1); | 78 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple); |
| 79 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_1); |
74 CHECK(!iterator.done()); | 80 CHECK(!iterator.done()); |
75 iterator.Advance(); | 81 iterator.Advance(); |
76 | 82 |
77 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdar); | 83 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdar); |
| 84 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
78 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index()); | 85 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index()); |
79 CHECK(!iterator.done()); | 86 CHECK(!iterator.done()); |
80 iterator.Advance(); | 87 iterator.Advance(); |
81 | 88 |
82 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLoadIC); | 89 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLoadIC); |
| 90 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
83 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index()); | 91 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index()); |
84 CHECK_EQ(iterator.GetIndexOperand(1), name_index); | 92 CHECK_EQ(iterator.GetIndexOperand(1), name_index); |
85 CHECK_EQ(iterator.GetIndexOperand(2), feedback_slot); | 93 CHECK_EQ(iterator.GetIndexOperand(2), feedback_slot); |
86 CHECK(!iterator.done()); | 94 CHECK(!iterator.done()); |
87 iterator.Advance(); | 95 iterator.Advance(); |
88 | 96 |
89 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar); | 97 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar); |
| 98 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
90 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_2.index()); | 99 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_2.index()); |
91 CHECK(!iterator.done()); | 100 CHECK(!iterator.done()); |
92 iterator.Advance(); | 101 iterator.Advance(); |
93 | 102 |
94 CHECK_EQ(iterator.current_bytecode(), Bytecode::kCallRuntime); | 103 CHECK_EQ(iterator.current_bytecode(), Bytecode::kCallRuntime); |
95 CHECK_EQ(static_cast<Runtime::FunctionId>(iterator.GetIndexOperand(0)), | 104 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| 105 CHECK_EQ(static_cast<Runtime::FunctionId>(iterator.GetRuntimeIdOperand(0)), |
96 Runtime::kLoadIC_Miss); | 106 Runtime::kLoadIC_Miss); |
97 CHECK_EQ(iterator.GetRegisterOperand(1).index(), reg_0.index()); | 107 CHECK_EQ(iterator.GetRegisterOperand(1).index(), reg_0.index()); |
98 CHECK_EQ(iterator.GetRegisterCountOperand(2), 1); | 108 CHECK_EQ(iterator.GetRegisterCountOperand(2), 1); |
99 CHECK(!iterator.done()); | 109 CHECK(!iterator.done()); |
100 iterator.Advance(); | 110 iterator.Advance(); |
101 | 111 |
102 CHECK_EQ(iterator.current_bytecode(), Bytecode::kDebugger); | 112 CHECK_EQ(iterator.current_bytecode(), Bytecode::kDebugger); |
| 113 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
103 CHECK(!iterator.done()); | 114 CHECK(!iterator.done()); |
104 iterator.Advance(); | 115 iterator.Advance(); |
105 | 116 |
| 117 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaGlobal); |
| 118 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple); |
| 119 CHECK_EQ(iterator.current_bytecode_size(), 10); |
| 120 CHECK_EQ(iterator.GetIndexOperand(1), 0x10000000); |
| 121 iterator.Advance(); |
| 122 |
106 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 123 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
| 124 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
107 CHECK(!iterator.done()); | 125 CHECK(!iterator.done()); |
108 iterator.Advance(); | 126 iterator.Advance(); |
109 CHECK(iterator.done()); | 127 CHECK(iterator.done()); |
110 } | 128 } |
111 | 129 |
112 } // namespace interpreter | 130 } // namespace interpreter |
113 } // namespace internal | 131 } // namespace internal |
114 } // namespace v8 | 132 } // namespace v8 |
OLD | NEW |