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 19 matching lines...) Expand all Loading... |
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 param = Register::FromParameterIndex(2, builder.parameter_count()); | 34 Register param = Register::FromParameterIndex(2, builder.parameter_count()); |
35 Handle<String> name = factory->NewStringFromStaticChars("abc"); | 35 Handle<String> name = factory->NewStringFromStaticChars("abc"); |
36 int name_index = 2; | 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 .StoreAccumulatorInRegister(reg_0) |
40 .LoadLiteral(heap_num_1) | 41 .LoadLiteral(heap_num_1) |
| 42 .StoreAccumulatorInRegister(reg_0) |
41 .LoadLiteral(zero) | 43 .LoadLiteral(zero) |
| 44 .StoreAccumulatorInRegister(reg_0) |
42 .LoadLiteral(smi_0) | 45 .LoadLiteral(smi_0) |
| 46 .StoreAccumulatorInRegister(reg_0) |
43 .LoadLiteral(smi_1) | 47 .LoadLiteral(smi_1) |
| 48 .StoreAccumulatorInRegister(reg_1) |
44 .LoadAccumulatorWithRegister(reg_0) | 49 .LoadAccumulatorWithRegister(reg_0) |
| 50 .StoreAccumulatorInRegister(reg_1) |
45 .LoadNamedProperty(reg_1, name, feedback_slot) | 51 .LoadNamedProperty(reg_1, name, feedback_slot) |
46 .StoreAccumulatorInRegister(param) | 52 .StoreAccumulatorInRegister(param) |
47 .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, 1, reg_0) | 53 .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, 1, reg_0) |
48 .ForInPrepare(reg_0) | 54 .ForInPrepare(reg_0) |
49 .CallRuntime(Runtime::kLoadIC_Miss, reg_0, 1) | 55 .CallRuntime(Runtime::kLoadIC_Miss, reg_0, 1) |
50 .Debugger() | 56 .Debugger() |
51 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF) | 57 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF) |
52 .Return(); | 58 .Return(); |
53 | 59 |
54 // Test iterator sees the expected output from the builder. | 60 // Test iterator sees the expected output from the builder. |
55 BytecodeArrayIterator iterator(builder.ToBytecodeArray()); | 61 BytecodeArrayIterator iterator(builder.ToBytecodeArray()); |
56 const int kPrefixByteSize = 1; | 62 const int kPrefixByteSize = 1; |
57 int offset = 0; | 63 int offset = 0; |
58 | 64 |
59 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); | 65 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); |
60 CHECK_EQ(iterator.current_offset(), offset); | 66 CHECK_EQ(iterator.current_offset(), offset); |
61 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | 67 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
62 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0)); | 68 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0)); |
63 CHECK(!iterator.done()); | 69 CHECK(!iterator.done()); |
64 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle); | 70 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle); |
65 iterator.Advance(); | 71 iterator.Advance(); |
66 | 72 |
| 73 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar); |
| 74 CHECK_EQ(iterator.current_offset(), offset); |
| 75 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| 76 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index()); |
| 77 CHECK_EQ(iterator.GetRegisterOperandRange(0), 1); |
| 78 CHECK(!iterator.done()); |
| 79 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle); |
| 80 iterator.Advance(); |
| 81 |
67 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); | 82 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); |
68 CHECK_EQ(iterator.current_offset(), offset); | 83 CHECK_EQ(iterator.current_offset(), offset); |
69 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | 84 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
70 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1)); | 85 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1)); |
71 CHECK(!iterator.done()); | 86 CHECK(!iterator.done()); |
72 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle); | 87 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle); |
73 iterator.Advance(); | 88 iterator.Advance(); |
74 | 89 |
| 90 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar); |
| 91 CHECK_EQ(iterator.current_offset(), offset); |
| 92 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| 93 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index()); |
| 94 CHECK_EQ(iterator.GetRegisterOperandRange(0), 1); |
| 95 CHECK(!iterator.done()); |
| 96 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle); |
| 97 iterator.Advance(); |
| 98 |
75 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaZero); | 99 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaZero); |
76 CHECK_EQ(iterator.current_offset(), offset); | 100 CHECK_EQ(iterator.current_offset(), offset); |
77 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | 101 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
78 CHECK(!iterator.done()); | 102 CHECK(!iterator.done()); |
79 offset += Bytecodes::Size(Bytecode::kLdaZero, OperandScale::kSingle); | 103 offset += Bytecodes::Size(Bytecode::kLdaZero, OperandScale::kSingle); |
80 iterator.Advance(); | 104 iterator.Advance(); |
81 | 105 |
| 106 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar); |
| 107 CHECK_EQ(iterator.current_offset(), offset); |
| 108 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| 109 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index()); |
| 110 CHECK_EQ(iterator.GetRegisterOperandRange(0), 1); |
| 111 CHECK(!iterator.done()); |
| 112 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle); |
| 113 iterator.Advance(); |
| 114 |
82 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi); | 115 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi); |
83 CHECK_EQ(iterator.current_offset(), offset); | 116 CHECK_EQ(iterator.current_offset(), offset); |
84 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | 117 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
85 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_0); | 118 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_0); |
86 CHECK(!iterator.done()); | 119 CHECK(!iterator.done()); |
87 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kSingle); | 120 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kSingle); |
88 iterator.Advance(); | 121 iterator.Advance(); |
89 | 122 |
| 123 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar); |
| 124 CHECK_EQ(iterator.current_offset(), offset); |
| 125 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| 126 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index()); |
| 127 CHECK_EQ(iterator.GetRegisterOperandRange(0), 1); |
| 128 CHECK(!iterator.done()); |
| 129 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle); |
| 130 iterator.Advance(); |
| 131 |
90 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi); | 132 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi); |
91 CHECK_EQ(iterator.current_offset(), offset); | 133 CHECK_EQ(iterator.current_offset(), offset); |
92 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple); | 134 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple); |
93 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_1); | 135 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_1); |
94 CHECK(!iterator.done()); | 136 CHECK(!iterator.done()); |
95 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kQuadruple) + | 137 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kQuadruple) + |
96 kPrefixByteSize; | 138 kPrefixByteSize; |
97 iterator.Advance(); | 139 iterator.Advance(); |
98 | 140 |
| 141 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar); |
| 142 CHECK_EQ(iterator.current_offset(), offset); |
| 143 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| 144 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index()); |
| 145 CHECK_EQ(iterator.GetRegisterOperandRange(0), 1); |
| 146 CHECK(!iterator.done()); |
| 147 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle); |
| 148 iterator.Advance(); |
| 149 |
99 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdar); | 150 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdar); |
100 CHECK_EQ(iterator.current_offset(), offset); | 151 CHECK_EQ(iterator.current_offset(), offset); |
101 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | 152 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
102 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index()); | 153 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index()); |
103 CHECK(!iterator.done()); | 154 CHECK(!iterator.done()); |
104 offset += Bytecodes::Size(Bytecode::kLdar, OperandScale::kSingle); | 155 offset += Bytecodes::Size(Bytecode::kLdar, OperandScale::kSingle); |
105 iterator.Advance(); | 156 iterator.Advance(); |
106 | 157 |
| 158 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar); |
| 159 CHECK_EQ(iterator.current_offset(), offset); |
| 160 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| 161 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index()); |
| 162 CHECK_EQ(iterator.GetRegisterOperandRange(0), 1); |
| 163 CHECK(!iterator.done()); |
| 164 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle); |
| 165 iterator.Advance(); |
| 166 |
107 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLoadIC); | 167 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLoadIC); |
108 CHECK_EQ(iterator.current_offset(), offset); | 168 CHECK_EQ(iterator.current_offset(), offset); |
109 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | 169 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
110 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index()); | 170 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index()); |
111 CHECK_EQ(iterator.GetIndexOperand(1), name_index); | 171 CHECK_EQ(iterator.GetIndexOperand(1), name_index); |
112 CHECK_EQ(iterator.GetIndexOperand(2), feedback_slot); | 172 CHECK_EQ(iterator.GetIndexOperand(2), feedback_slot); |
113 CHECK(!iterator.done()); | 173 CHECK(!iterator.done()); |
114 offset += Bytecodes::Size(Bytecode::kLoadIC, OperandScale::kSingle); | 174 offset += Bytecodes::Size(Bytecode::kLoadIC, OperandScale::kSingle); |
115 iterator.Advance(); | 175 iterator.Advance(); |
116 | 176 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 CHECK_EQ(iterator.current_offset(), offset); | 237 CHECK_EQ(iterator.current_offset(), offset); |
178 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | 238 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
179 CHECK(!iterator.done()); | 239 CHECK(!iterator.done()); |
180 iterator.Advance(); | 240 iterator.Advance(); |
181 CHECK(iterator.done()); | 241 CHECK(iterator.done()); |
182 } | 242 } |
183 | 243 |
184 } // namespace interpreter | 244 } // namespace interpreter |
185 } // namespace internal | 245 } // namespace internal |
186 } // namespace v8 | 246 } // namespace v8 |
OLD | NEW |