Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: test/unittests/interpreter/bytecode-array-random-iterator-unittest.cc

Issue 2536653003: [ignition] Rewrite reverse iterator as random iterator (Closed)
Patch Set: Rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "src/interpreter/bytecode-array-builder.h"
8 #include "src/interpreter/bytecode-array-random-iterator.h"
9 #include "test/unittests/test-utils.h"
10
11 namespace v8 {
12 namespace internal {
13 namespace interpreter {
14
15 class BytecodeArrayRandomIteratorTest : public TestWithIsolateAndZone {
16 public:
17 BytecodeArrayRandomIteratorTest() {}
18 ~BytecodeArrayRandomIteratorTest() override {}
19 };
20
21 TEST_F(BytecodeArrayRandomIteratorTest, InvalidBeforeStart) {
22 // Use a builder to create an array with containing multiple bytecodes
23 // with 0, 1 and 2 operands.
24 BytecodeArrayBuilder builder(isolate(), zone(), 3, 3, 0);
25 Factory* factory = isolate()->factory();
26 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
27 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
28 Smi* zero = Smi::kZero;
29 Smi* smi_0 = Smi::FromInt(64);
30 Smi* smi_1 = Smi::FromInt(-65536);
31 Register reg_0(0);
32 Register reg_1(1);
33 RegisterList pair(0, 2);
34 RegisterList triple(0, 3);
35 Register param = Register::FromParameterIndex(2, builder.parameter_count());
36 Handle<String> name = factory->NewStringFromStaticChars("abc");
37 uint32_t feedback_slot = 97;
38
39 builder.LoadLiteral(heap_num_0)
40 .StoreAccumulatorInRegister(reg_0)
41 .LoadLiteral(heap_num_1)
42 .StoreAccumulatorInRegister(reg_0)
43 .LoadLiteral(zero)
44 .StoreAccumulatorInRegister(reg_0)
45 .LoadLiteral(smi_0)
46 .StackCheck(0)
47 .StoreAccumulatorInRegister(reg_0)
48 .LoadLiteral(smi_1)
49 .StackCheck(1)
50 .StoreAccumulatorInRegister(reg_1)
51 .LoadAccumulatorWithRegister(reg_0)
52 .BinaryOperation(Token::Value::ADD, reg_0, 2)
53 .StoreAccumulatorInRegister(reg_1)
54 .LoadNamedProperty(reg_1, name, feedback_slot)
55 .BinaryOperation(Token::Value::ADD, reg_0, 3)
56 .StoreAccumulatorInRegister(param)
57 .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, pair)
58 .ForInPrepare(reg_0, triple)
59 .CallRuntime(Runtime::kLoadIC_Miss, reg_0)
60 .Debugger()
61 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF)
62 .Return();
63
64 Handle<BytecodeArray> bytecodeArray = builder.ToBytecodeArray(isolate());
65 BytecodeArrayRandomIterator iterator(bytecodeArray, zone());
66
67 iterator.GoToStart();
68 ASSERT_TRUE(iterator.IsValid());
69 --iterator;
70 ASSERT_FALSE(iterator.IsValid());
71 }
72
73 TEST_F(BytecodeArrayRandomIteratorTest, InvalidAfterEnd) {
74 // Use a builder to create an array with containing multiple bytecodes
75 // with 0, 1 and 2 operands.
76 BytecodeArrayBuilder builder(isolate(), zone(), 3, 3, 0);
77 Factory* factory = isolate()->factory();
78 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
79 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
80 Smi* zero = Smi::kZero;
81 Smi* smi_0 = Smi::FromInt(64);
82 Smi* smi_1 = Smi::FromInt(-65536);
83 Register reg_0(0);
84 Register reg_1(1);
85 RegisterList pair(0, 2);
86 RegisterList triple(0, 3);
87 Register param = Register::FromParameterIndex(2, builder.parameter_count());
88 Handle<String> name = factory->NewStringFromStaticChars("abc");
89 uint32_t feedback_slot = 97;
90
91 builder.LoadLiteral(heap_num_0)
92 .StoreAccumulatorInRegister(reg_0)
93 .LoadLiteral(heap_num_1)
94 .StoreAccumulatorInRegister(reg_0)
95 .LoadLiteral(zero)
96 .StoreAccumulatorInRegister(reg_0)
97 .LoadLiteral(smi_0)
98 .StackCheck(0)
99 .StoreAccumulatorInRegister(reg_0)
100 .LoadLiteral(smi_1)
101 .StackCheck(1)
102 .StoreAccumulatorInRegister(reg_1)
103 .LoadAccumulatorWithRegister(reg_0)
104 .BinaryOperation(Token::Value::ADD, reg_0, 2)
105 .StoreAccumulatorInRegister(reg_1)
106 .LoadNamedProperty(reg_1, name, feedback_slot)
107 .BinaryOperation(Token::Value::ADD, reg_0, 3)
108 .StoreAccumulatorInRegister(param)
109 .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, pair)
110 .ForInPrepare(reg_0, triple)
111 .CallRuntime(Runtime::kLoadIC_Miss, reg_0)
112 .Debugger()
113 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF)
114 .Return();
115
116 Handle<BytecodeArray> bytecodeArray = builder.ToBytecodeArray(isolate());
117 BytecodeArrayRandomIterator iterator(bytecodeArray, zone());
118
119 iterator.GoToEnd();
120 ASSERT_TRUE(iterator.IsValid());
121 ++iterator;
122 ASSERT_FALSE(iterator.IsValid());
123 }
124
125 TEST_F(BytecodeArrayRandomIteratorTest, AccessesFirst) {
126 // Use a builder to create an array with containing multiple bytecodes
127 // with 0, 1 and 2 operands.
128 BytecodeArrayBuilder builder(isolate(), zone(), 3, 3, 0);
129 Factory* factory = isolate()->factory();
130 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
131 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
132 Smi* zero = Smi::kZero;
133 Smi* smi_0 = Smi::FromInt(64);
134 Smi* smi_1 = Smi::FromInt(-65536);
135 Register reg_0(0);
136 Register reg_1(1);
137 RegisterList pair(0, 2);
138 RegisterList triple(0, 3);
139 Register param = Register::FromParameterIndex(2, builder.parameter_count());
140 Handle<String> name = factory->NewStringFromStaticChars("abc");
141 uint32_t feedback_slot = 97;
142
143 builder.LoadLiteral(heap_num_0)
144 .StoreAccumulatorInRegister(reg_0)
145 .LoadLiteral(heap_num_1)
146 .StoreAccumulatorInRegister(reg_0)
147 .LoadLiteral(zero)
148 .StoreAccumulatorInRegister(reg_0)
149 .LoadLiteral(smi_0)
150 .StackCheck(0)
151 .StoreAccumulatorInRegister(reg_0)
152 .LoadLiteral(smi_1)
153 .StackCheck(1)
154 .StoreAccumulatorInRegister(reg_1)
155 .LoadAccumulatorWithRegister(reg_0)
156 .BinaryOperation(Token::Value::ADD, reg_0, 2)
157 .StoreAccumulatorInRegister(reg_1)
158 .LoadNamedProperty(reg_1, name, feedback_slot)
159 .BinaryOperation(Token::Value::ADD, reg_0, 3)
160 .StoreAccumulatorInRegister(param)
161 .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, pair)
162 .ForInPrepare(reg_0, triple)
163 .CallRuntime(Runtime::kLoadIC_Miss, reg_0)
164 .Debugger()
165 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF)
166 .Return();
167
168 Handle<BytecodeArray> bytecodeArray = builder.ToBytecodeArray(isolate());
169 BytecodeArrayRandomIterator iterator(bytecodeArray, zone());
170
171 iterator.GoToStart();
172
173 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
174 EXPECT_EQ(iterator.current_index(), 0);
175 EXPECT_EQ(iterator.current_offset(), 0);
176 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
177 EXPECT_TRUE(
178 iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0));
179 ASSERT_TRUE(iterator.IsValid());
180 }
181
182 TEST_F(BytecodeArrayRandomIteratorTest, AccessesLast) {
183 // Use a builder to create an array with containing multiple bytecodes
184 // with 0, 1 and 2 operands.
185 BytecodeArrayBuilder builder(isolate(), zone(), 3, 3, 0);
186 Factory* factory = isolate()->factory();
187 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
188 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
189 Smi* zero = Smi::kZero;
190 Smi* smi_0 = Smi::FromInt(64);
191 Smi* smi_1 = Smi::FromInt(-65536);
192 Register reg_0(0);
193 Register reg_1(1);
194 RegisterList pair(0, 2);
195 RegisterList triple(0, 3);
196 Register param = Register::FromParameterIndex(2, builder.parameter_count());
197 Handle<String> name = factory->NewStringFromStaticChars("abc");
198 uint32_t feedback_slot = 97;
199
200 builder.LoadLiteral(heap_num_0)
201 .StoreAccumulatorInRegister(reg_0)
202 .LoadLiteral(heap_num_1)
203 .StoreAccumulatorInRegister(reg_0)
204 .LoadLiteral(zero)
205 .StoreAccumulatorInRegister(reg_0)
206 .LoadLiteral(smi_0)
207 .StackCheck(0)
208 .StoreAccumulatorInRegister(reg_0)
209 .LoadLiteral(smi_1)
210 .StackCheck(1)
211 .StoreAccumulatorInRegister(reg_1)
212 .LoadAccumulatorWithRegister(reg_0)
213 .BinaryOperation(Token::Value::ADD, reg_0, 2)
214 .StoreAccumulatorInRegister(reg_1)
215 .LoadNamedProperty(reg_1, name, feedback_slot)
216 .BinaryOperation(Token::Value::ADD, reg_0, 3)
217 .StoreAccumulatorInRegister(param)
218 .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, pair)
219 .ForInPrepare(reg_0, triple)
220 .CallRuntime(Runtime::kLoadIC_Miss, reg_0)
221 .Debugger()
222 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF)
223 .Return();
224
225 Handle<BytecodeArray> bytecodeArray = builder.ToBytecodeArray(isolate());
226 BytecodeArrayRandomIterator iterator(bytecodeArray, zone());
227
228 iterator.GoToEnd();
229
230 int offset = bytecodeArray->length() -
231 Bytecodes::Size(Bytecode::kReturn, OperandScale::kSingle);
232 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kReturn);
233 EXPECT_EQ(iterator.current_index(), 23);
234 EXPECT_EQ(iterator.current_offset(), offset);
235 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
236 ASSERT_TRUE(iterator.IsValid());
237 }
238
239 TEST_F(BytecodeArrayRandomIteratorTest, RandomAccessValid) {
240 // Use a builder to create an array with containing multiple bytecodes
241 // with 0, 1 and 2 operands.
242 BytecodeArrayBuilder builder(isolate(), zone(), 3, 3, 0);
243 Factory* factory = isolate()->factory();
244 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
245 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
246 Smi* zero = Smi::kZero;
247 Smi* smi_0 = Smi::FromInt(64);
248 Smi* smi_1 = Smi::FromInt(-65536);
249 Register reg_0(0);
250 Register reg_1(1);
251 RegisterList pair(0, 2);
252 RegisterList triple(0, 3);
253 Register param = Register::FromParameterIndex(2, builder.parameter_count());
254 Handle<String> name = factory->NewStringFromStaticChars("abc");
255 uint32_t name_index = 2;
256 uint32_t feedback_slot = 97;
257
258 builder.LoadLiteral(heap_num_0)
259 .StoreAccumulatorInRegister(reg_0)
260 .LoadLiteral(heap_num_1)
261 .StoreAccumulatorInRegister(reg_0)
262 .LoadLiteral(zero)
263 .StoreAccumulatorInRegister(reg_0)
264 .LoadLiteral(smi_0)
265 .StackCheck(0)
266 .StoreAccumulatorInRegister(reg_0)
267 .LoadLiteral(smi_1)
268 .StackCheck(1)
269 .StoreAccumulatorInRegister(reg_1)
270 .LoadAccumulatorWithRegister(reg_0)
271 .BinaryOperation(Token::Value::ADD, reg_0, 2)
272 .StoreAccumulatorInRegister(reg_1)
273 .LoadNamedProperty(reg_1, name, feedback_slot)
274 .BinaryOperation(Token::Value::ADD, reg_0, 3)
275 .StoreAccumulatorInRegister(param)
276 .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, pair)
277 .ForInPrepare(reg_0, triple)
278 .CallRuntime(Runtime::kLoadIC_Miss, reg_0)
279 .Debugger()
280 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF)
281 .Return();
282
283 // Test iterator sees the expected output from the builder.
284 BytecodeArrayRandomIterator iterator(builder.ToBytecodeArray(isolate()),
285 zone());
286 const int kPrefixByteSize = 1;
287 int offset = 0;
288
289 iterator.GoToIndex(13);
290 offset = Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
291 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
292 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
293 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
294 offset += Bytecodes::Size(Bytecode::kLdaZero, OperandScale::kSingle);
295 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
296 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kSingle);
297 offset += Bytecodes::Size(Bytecode::kStackCheck, OperandScale::kSingle);
298 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
299 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kQuadruple) +
300 kPrefixByteSize;
301 offset += Bytecodes::Size(Bytecode::kStackCheck, OperandScale::kSingle);
302 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
303 offset += Bytecodes::Size(Bytecode::kLdar, OperandScale::kSingle);
304
305 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kAdd);
306 EXPECT_EQ(iterator.current_index(), 13);
307 EXPECT_EQ(iterator.current_offset(), offset);
308 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
309 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
310 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
311 ASSERT_TRUE(iterator.IsValid());
312
313 iterator.GoToIndex(2);
314 offset = Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
315 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
316
317 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
318 EXPECT_EQ(iterator.current_index(), 2);
319 EXPECT_EQ(iterator.current_offset(), offset);
320 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
321 EXPECT_TRUE(
322 iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1));
323 ASSERT_TRUE(iterator.IsValid());
324
325 iterator.GoToIndex(18);
326 offset = Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
327 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
328 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
329 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
330 offset += Bytecodes::Size(Bytecode::kLdaZero, OperandScale::kSingle);
331 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
332 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kSingle);
333 offset += Bytecodes::Size(Bytecode::kStackCheck, OperandScale::kSingle);
334 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
335 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kQuadruple) +
336 kPrefixByteSize;
337 offset += Bytecodes::Size(Bytecode::kStackCheck, OperandScale::kSingle);
338 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
339 offset += Bytecodes::Size(Bytecode::kLdar, OperandScale::kSingle);
340 offset += Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
341 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
342 offset += Bytecodes::Size(Bytecode::kLdaNamedProperty, OperandScale::kSingle);
343 offset += Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
344 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
345
346 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kCallRuntimeForPair);
347 EXPECT_EQ(iterator.current_index(), 18);
348 EXPECT_EQ(iterator.current_offset(), offset);
349 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
350 EXPECT_EQ(iterator.GetRuntimeIdOperand(0), Runtime::kLoadLookupSlotForCall);
351 EXPECT_EQ(iterator.GetRegisterOperand(1).index(), param.index());
352 EXPECT_EQ(iterator.GetRegisterOperandRange(1), 1);
353 EXPECT_EQ(iterator.GetRegisterCountOperand(2), 1u);
354 EXPECT_EQ(iterator.GetRegisterOperand(3).index(), reg_0.index());
355 EXPECT_EQ(iterator.GetRegisterOperandRange(3), 2);
356 ASSERT_TRUE(iterator.IsValid());
357
358 iterator -= 3;
359 offset -= Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
360 offset -= Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
361 offset -= Bytecodes::Size(Bytecode::kLdaNamedProperty, OperandScale::kSingle);
362
363 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaNamedProperty);
364 EXPECT_EQ(iterator.current_index(), 15);
365 EXPECT_EQ(iterator.current_offset(), offset);
366 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
367 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index());
368 EXPECT_EQ(iterator.GetIndexOperand(1), name_index);
369 EXPECT_EQ(iterator.GetIndexOperand(2), feedback_slot);
370 ASSERT_TRUE(iterator.IsValid());
371
372 iterator += 2;
373 offset += Bytecodes::Size(Bytecode::kLdaNamedProperty, OperandScale::kSingle);
374 offset += Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
375
376 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
377 EXPECT_EQ(iterator.current_index(), 17);
378 EXPECT_EQ(iterator.current_offset(), offset);
379 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
380 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), param.index());
381 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
382 ASSERT_TRUE(iterator.IsValid());
383
384 iterator.GoToIndex(23);
385 offset = Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
386 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
387 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
388 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
389 offset += Bytecodes::Size(Bytecode::kLdaZero, OperandScale::kSingle);
390 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
391 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kSingle);
392 offset += Bytecodes::Size(Bytecode::kStackCheck, OperandScale::kSingle);
393 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
394 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kQuadruple) +
395 kPrefixByteSize;
396 offset += Bytecodes::Size(Bytecode::kStackCheck, OperandScale::kSingle);
397 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
398 offset += Bytecodes::Size(Bytecode::kLdar, OperandScale::kSingle);
399 offset += Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
400 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
401 offset += Bytecodes::Size(Bytecode::kLdaNamedProperty, OperandScale::kSingle);
402 offset += Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
403 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
404 offset +=
405 Bytecodes::Size(Bytecode::kCallRuntimeForPair, OperandScale::kSingle);
406 offset += Bytecodes::Size(Bytecode::kForInPrepare, OperandScale::kSingle);
407 offset += Bytecodes::Size(Bytecode::kCallRuntime, OperandScale::kSingle);
408 offset += Bytecodes::Size(Bytecode::kDebugger, OperandScale::kSingle);
409 offset += Bytecodes::Size(Bytecode::kLdaGlobal, OperandScale::kQuadruple) +
410 kPrefixByteSize;
411
412 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kReturn);
413 EXPECT_EQ(iterator.current_index(), 23);
414 EXPECT_EQ(iterator.current_offset(), offset);
415 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
416 ASSERT_TRUE(iterator.IsValid());
417
418 iterator.GoToIndex(24);
419 EXPECT_FALSE(iterator.IsValid());
420
421 iterator.GoToIndex(-5);
422 EXPECT_FALSE(iterator.IsValid());
423 }
424
425 TEST_F(BytecodeArrayRandomIteratorTest, IteratesBytecodeArray) {
426 // Use a builder to create an array with containing multiple bytecodes
427 // with 0, 1 and 2 operands.
428 BytecodeArrayBuilder builder(isolate(), zone(), 3, 3, 0);
429 Factory* factory = isolate()->factory();
430 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
431 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
432 Smi* zero = Smi::kZero;
433 Smi* smi_0 = Smi::FromInt(64);
434 Smi* smi_1 = Smi::FromInt(-65536);
435 Register reg_0(0);
436 Register reg_1(1);
437 RegisterList pair(0, 2);
438 RegisterList triple(0, 3);
439 Register param = Register::FromParameterIndex(2, builder.parameter_count());
440 Handle<String> name = factory->NewStringFromStaticChars("abc");
441 uint32_t name_index = 2;
442 uint32_t feedback_slot = 97;
443
444 builder.LoadLiteral(heap_num_0)
445 .StoreAccumulatorInRegister(reg_0)
446 .LoadLiteral(heap_num_1)
447 .StoreAccumulatorInRegister(reg_0)
448 .LoadLiteral(zero)
449 .StoreAccumulatorInRegister(reg_0)
450 .LoadLiteral(smi_0)
451 .StackCheck(0)
452 .StoreAccumulatorInRegister(reg_0)
453 .LoadLiteral(smi_1)
454 .StackCheck(1)
455 .StoreAccumulatorInRegister(reg_1)
456 .LoadAccumulatorWithRegister(reg_0)
457 .BinaryOperation(Token::Value::ADD, reg_0, 2)
458 .StoreAccumulatorInRegister(reg_1)
459 .LoadNamedProperty(reg_1, name, feedback_slot)
460 .BinaryOperation(Token::Value::ADD, reg_0, 3)
461 .StoreAccumulatorInRegister(param)
462 .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, pair)
463 .ForInPrepare(reg_0, triple)
464 .CallRuntime(Runtime::kLoadIC_Miss, reg_0)
465 .Debugger()
466 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF)
467 .Return();
468
469 // Test iterator sees the expected output from the builder.
470 BytecodeArrayRandomIterator iterator(builder.ToBytecodeArray(isolate()),
471 zone());
472 const int kPrefixByteSize = 1;
473 int offset = 0;
474
475 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
476 EXPECT_EQ(iterator.current_index(), 0);
477 EXPECT_EQ(iterator.current_offset(), offset);
478 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
479 EXPECT_TRUE(
480 iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0));
481 ASSERT_TRUE(iterator.IsValid());
482 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
483 ++iterator;
484
485 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
486 EXPECT_EQ(iterator.current_index(), 1);
487 EXPECT_EQ(iterator.current_offset(), offset);
488 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
489 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
490 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
491 ASSERT_TRUE(iterator.IsValid());
492 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
493 ++iterator;
494
495 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
496 EXPECT_EQ(iterator.current_index(), 2);
497 EXPECT_EQ(iterator.current_offset(), offset);
498 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
499 EXPECT_TRUE(
500 iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1));
501 ASSERT_TRUE(iterator.IsValid());
502 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
503 ++iterator;
504
505 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
506 EXPECT_EQ(iterator.current_index(), 3);
507 EXPECT_EQ(iterator.current_offset(), offset);
508 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
509 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
510 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
511 ASSERT_TRUE(iterator.IsValid());
512 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
513 ++iterator;
514
515 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaZero);
516 EXPECT_EQ(iterator.current_index(), 4);
517 EXPECT_EQ(iterator.current_offset(), offset);
518 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
519 ASSERT_TRUE(iterator.IsValid());
520 offset += Bytecodes::Size(Bytecode::kLdaZero, OperandScale::kSingle);
521 ++iterator;
522
523 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
524 EXPECT_EQ(iterator.current_index(), 5);
525 EXPECT_EQ(iterator.current_offset(), offset);
526 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
527 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
528 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
529 ASSERT_TRUE(iterator.IsValid());
530 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
531 ++iterator;
532
533 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi);
534 EXPECT_EQ(iterator.current_index(), 6);
535 EXPECT_EQ(iterator.current_offset(), offset);
536 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
537 EXPECT_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_0);
538 ASSERT_TRUE(iterator.IsValid());
539 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kSingle);
540 ++iterator;
541
542 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStackCheck);
543 EXPECT_EQ(iterator.current_index(), 7);
544 EXPECT_EQ(iterator.current_offset(), offset);
545 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
546 EXPECT_EQ(Bytecodes::NumberOfOperands(iterator.current_bytecode()), 0);
547 ASSERT_TRUE(iterator.IsValid());
548 offset += Bytecodes::Size(Bytecode::kStackCheck, OperandScale::kSingle);
549 ++iterator;
550
551 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
552 EXPECT_EQ(iterator.current_index(), 8);
553 EXPECT_EQ(iterator.current_offset(), offset);
554 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
555 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
556 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
557 ASSERT_TRUE(iterator.IsValid());
558 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
559 ++iterator;
560
561 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi);
562 EXPECT_EQ(iterator.current_index(), 9);
563 EXPECT_EQ(iterator.current_offset(), offset);
564 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple);
565 EXPECT_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_1);
566 ASSERT_TRUE(iterator.IsValid());
567 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kQuadruple) +
568 kPrefixByteSize;
569 ++iterator;
570
571 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStackCheck);
572 EXPECT_EQ(iterator.current_index(), 10);
573 EXPECT_EQ(iterator.current_offset(), offset);
574 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
575 EXPECT_EQ(Bytecodes::NumberOfOperands(iterator.current_bytecode()), 0);
576 ASSERT_TRUE(iterator.IsValid());
577 offset += Bytecodes::Size(Bytecode::kStackCheck, OperandScale::kSingle);
578 ++iterator;
579
580 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
581 EXPECT_EQ(iterator.current_index(), 11);
582 EXPECT_EQ(iterator.current_offset(), offset);
583 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
584 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index());
585 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
586 ASSERT_TRUE(iterator.IsValid());
587 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
588 ++iterator;
589
590 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdar);
591 EXPECT_EQ(iterator.current_index(), 12);
592 EXPECT_EQ(iterator.current_offset(), offset);
593 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
594 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
595 ASSERT_TRUE(iterator.IsValid());
596 offset += Bytecodes::Size(Bytecode::kLdar, OperandScale::kSingle);
597 ++iterator;
598
599 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kAdd);
600 EXPECT_EQ(iterator.current_index(), 13);
601 EXPECT_EQ(iterator.current_offset(), offset);
602 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
603 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
604 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
605 ASSERT_TRUE(iterator.IsValid());
606 offset += Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
607 ++iterator;
608
609 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
610 EXPECT_EQ(iterator.current_index(), 14);
611 EXPECT_EQ(iterator.current_offset(), offset);
612 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
613 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index());
614 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
615 ASSERT_TRUE(iterator.IsValid());
616 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
617 ++iterator;
618
619 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaNamedProperty);
620 EXPECT_EQ(iterator.current_index(), 15);
621 EXPECT_EQ(iterator.current_offset(), offset);
622 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
623 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index());
624 EXPECT_EQ(iterator.GetIndexOperand(1), name_index);
625 EXPECT_EQ(iterator.GetIndexOperand(2), feedback_slot);
626 ASSERT_TRUE(iterator.IsValid());
627 offset += Bytecodes::Size(Bytecode::kLdaNamedProperty, OperandScale::kSingle);
628 ++iterator;
629
630 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kAdd);
631 EXPECT_EQ(iterator.current_index(), 16);
632 EXPECT_EQ(iterator.current_offset(), offset);
633 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
634 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
635 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
636 ASSERT_TRUE(iterator.IsValid());
637 offset += Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
638 ++iterator;
639
640 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
641 EXPECT_EQ(iterator.current_index(), 17);
642 EXPECT_EQ(iterator.current_offset(), offset);
643 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
644 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), param.index());
645 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
646 ASSERT_TRUE(iterator.IsValid());
647 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
648 ++iterator;
649
650 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kCallRuntimeForPair);
651 EXPECT_EQ(iterator.current_index(), 18);
652 EXPECT_EQ(iterator.current_offset(), offset);
653 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
654 EXPECT_EQ(iterator.GetRuntimeIdOperand(0), Runtime::kLoadLookupSlotForCall);
655 EXPECT_EQ(iterator.GetRegisterOperand(1).index(), param.index());
656 EXPECT_EQ(iterator.GetRegisterOperandRange(1), 1);
657 EXPECT_EQ(iterator.GetRegisterCountOperand(2), 1u);
658 EXPECT_EQ(iterator.GetRegisterOperand(3).index(), reg_0.index());
659 EXPECT_EQ(iterator.GetRegisterOperandRange(3), 2);
660 ASSERT_TRUE(iterator.IsValid());
661 offset +=
662 Bytecodes::Size(Bytecode::kCallRuntimeForPair, OperandScale::kSingle);
663 ++iterator;
664
665 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kForInPrepare);
666 EXPECT_EQ(iterator.current_index(), 19);
667 EXPECT_EQ(iterator.current_offset(), offset);
668 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
669 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
670 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
671 EXPECT_EQ(iterator.GetRegisterOperand(1).index(), reg_0.index());
672 EXPECT_EQ(iterator.GetRegisterOperandRange(1), 3);
673 ASSERT_TRUE(iterator.IsValid());
674 offset += Bytecodes::Size(Bytecode::kForInPrepare, OperandScale::kSingle);
675 ++iterator;
676
677 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kCallRuntime);
678 EXPECT_EQ(iterator.current_index(), 20);
679 EXPECT_EQ(iterator.current_offset(), offset);
680 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
681 EXPECT_EQ(iterator.GetRuntimeIdOperand(0), Runtime::kLoadIC_Miss);
682 EXPECT_EQ(iterator.GetRegisterOperand(1).index(), reg_0.index());
683 EXPECT_EQ(iterator.GetRegisterCountOperand(2), 1u);
684 ASSERT_TRUE(iterator.IsValid());
685 offset += Bytecodes::Size(Bytecode::kCallRuntime, OperandScale::kSingle);
686 ++iterator;
687
688 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kDebugger);
689 EXPECT_EQ(iterator.current_index(), 21);
690 EXPECT_EQ(iterator.current_offset(), offset);
691 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
692 ASSERT_TRUE(iterator.IsValid());
693 offset += Bytecodes::Size(Bytecode::kDebugger, OperandScale::kSingle);
694 ++iterator;
695
696 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaGlobal);
697 EXPECT_EQ(iterator.current_index(), 22);
698 EXPECT_EQ(iterator.current_offset(), offset);
699 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple);
700 EXPECT_EQ(iterator.current_bytecode_size(), 10);
701 EXPECT_EQ(iterator.GetIndexOperand(1), 0x10000000u);
702 offset += Bytecodes::Size(Bytecode::kLdaGlobal, OperandScale::kQuadruple) +
703 kPrefixByteSize;
704 ++iterator;
705
706 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kReturn);
707 EXPECT_EQ(iterator.current_index(), 23);
708 EXPECT_EQ(iterator.current_offset(), offset);
709 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
710 ASSERT_TRUE(iterator.IsValid());
711 ++iterator;
712 ASSERT_TRUE(!iterator.IsValid());
713 }
714
715 TEST_F(BytecodeArrayRandomIteratorTest, IteratesBytecodeArrayBackwards) {
716 // Use a builder to create an array with containing multiple bytecodes
717 // with 0, 1 and 2 operands.
718 BytecodeArrayBuilder builder(isolate(), zone(), 3, 3, 0);
719 Factory* factory = isolate()->factory();
720 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
721 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
722 Smi* zero = Smi::kZero;
723 Smi* smi_0 = Smi::FromInt(64);
724 Smi* smi_1 = Smi::FromInt(-65536);
725 Register reg_0(0);
726 Register reg_1(1);
727 RegisterList pair(0, 2);
728 RegisterList triple(0, 3);
729 Register param = Register::FromParameterIndex(2, builder.parameter_count());
730 Handle<String> name = factory->NewStringFromStaticChars("abc");
731 uint32_t name_index = 2;
732 uint32_t feedback_slot = 97;
733
734 builder.LoadLiteral(heap_num_0)
735 .StoreAccumulatorInRegister(reg_0)
736 .LoadLiteral(heap_num_1)
737 .StoreAccumulatorInRegister(reg_0)
738 .LoadLiteral(zero)
739 .StoreAccumulatorInRegister(reg_0)
740 .LoadLiteral(smi_0)
741 .StackCheck(0)
742 .StoreAccumulatorInRegister(reg_0)
743 .LoadLiteral(smi_1)
744 .StackCheck(1)
745 .StoreAccumulatorInRegister(reg_1)
746 .LoadAccumulatorWithRegister(reg_0)
747 .BinaryOperation(Token::Value::ADD, reg_0, 2)
748 .StoreAccumulatorInRegister(reg_1)
749 .LoadNamedProperty(reg_1, name, feedback_slot)
750 .BinaryOperation(Token::Value::ADD, reg_0, 3)
751 .StoreAccumulatorInRegister(param)
752 .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, pair)
753 .ForInPrepare(reg_0, triple)
754 .CallRuntime(Runtime::kLoadIC_Miss, reg_0)
755 .Debugger()
756 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF)
757 .Return();
758
759 // Test iterator sees the expected output from the builder.
760 Handle<BytecodeArray> bytecodeArray = builder.ToBytecodeArray(isolate());
761 BytecodeArrayRandomIterator iterator(bytecodeArray, zone());
762 const int kPrefixByteSize = 1;
763 int offset = bytecodeArray->length();
764
765 iterator.GoToEnd();
766
767 offset -= Bytecodes::Size(Bytecode::kReturn, OperandScale::kSingle);
768 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kReturn);
769 EXPECT_EQ(iterator.current_index(), 23);
770 EXPECT_EQ(iterator.current_offset(), offset);
771 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
772 ASSERT_TRUE(iterator.IsValid());
773 --iterator;
774
775 offset -= Bytecodes::Size(Bytecode::kLdaGlobal, OperandScale::kQuadruple) +
776 kPrefixByteSize;
777 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaGlobal);
778 EXPECT_EQ(iterator.current_index(), 22);
779 EXPECT_EQ(iterator.current_offset(), offset);
780 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple);
781 EXPECT_EQ(iterator.current_bytecode_size(), 10);
782 EXPECT_EQ(iterator.GetIndexOperand(1), 0x10000000u);
783 --iterator;
784
785 offset -= Bytecodes::Size(Bytecode::kDebugger, OperandScale::kSingle);
786 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kDebugger);
787 EXPECT_EQ(iterator.current_index(), 21);
788 EXPECT_EQ(iterator.current_offset(), offset);
789 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
790 ASSERT_TRUE(iterator.IsValid());
791 --iterator;
792
793 offset -= Bytecodes::Size(Bytecode::kCallRuntime, OperandScale::kSingle);
794 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kCallRuntime);
795 EXPECT_EQ(iterator.current_index(), 20);
796 EXPECT_EQ(iterator.current_offset(), offset);
797 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
798 EXPECT_EQ(iterator.GetRuntimeIdOperand(0), Runtime::kLoadIC_Miss);
799 EXPECT_EQ(iterator.GetRegisterOperand(1).index(), reg_0.index());
800 EXPECT_EQ(iterator.GetRegisterCountOperand(2), 1u);
801 ASSERT_TRUE(iterator.IsValid());
802 --iterator;
803
804 offset -= Bytecodes::Size(Bytecode::kForInPrepare, OperandScale::kSingle);
805 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kForInPrepare);
806 EXPECT_EQ(iterator.current_index(), 19);
807 EXPECT_EQ(iterator.current_offset(), offset);
808 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
809 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
810 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
811 EXPECT_EQ(iterator.GetRegisterOperand(1).index(), reg_0.index());
812 EXPECT_EQ(iterator.GetRegisterOperandRange(1), 3);
813 ASSERT_TRUE(iterator.IsValid());
814 --iterator;
815
816 offset -=
817 Bytecodes::Size(Bytecode::kCallRuntimeForPair, OperandScale::kSingle);
818 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kCallRuntimeForPair);
819 EXPECT_EQ(iterator.current_index(), 18);
820 EXPECT_EQ(iterator.current_offset(), offset);
821 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
822 EXPECT_EQ(iterator.GetRuntimeIdOperand(0), Runtime::kLoadLookupSlotForCall);
823 EXPECT_EQ(iterator.GetRegisterOperand(1).index(), param.index());
824 EXPECT_EQ(iterator.GetRegisterOperandRange(1), 1);
825 EXPECT_EQ(iterator.GetRegisterCountOperand(2), 1u);
826 EXPECT_EQ(iterator.GetRegisterOperand(3).index(), reg_0.index());
827 EXPECT_EQ(iterator.GetRegisterOperandRange(3), 2);
828 ASSERT_TRUE(iterator.IsValid());
829 --iterator;
830
831 offset -= Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
832 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
833 EXPECT_EQ(iterator.current_index(), 17);
834 EXPECT_EQ(iterator.current_offset(), offset);
835 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
836 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), param.index());
837 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
838 ASSERT_TRUE(iterator.IsValid());
839 --iterator;
840
841 offset -= Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
842 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kAdd);
843 EXPECT_EQ(iterator.current_index(), 16);
844 EXPECT_EQ(iterator.current_offset(), offset);
845 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
846 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
847 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
848 ASSERT_TRUE(iterator.IsValid());
849 --iterator;
850
851 offset -= Bytecodes::Size(Bytecode::kLdaNamedProperty, OperandScale::kSingle);
852 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaNamedProperty);
853 EXPECT_EQ(iterator.current_index(), 15);
854 EXPECT_EQ(iterator.current_offset(), offset);
855 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
856 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index());
857 EXPECT_EQ(iterator.GetIndexOperand(1), name_index);
858 EXPECT_EQ(iterator.GetIndexOperand(2), feedback_slot);
859 ASSERT_TRUE(iterator.IsValid());
860 --iterator;
861
862 offset -= Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
863 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
864 EXPECT_EQ(iterator.current_index(), 14);
865 EXPECT_EQ(iterator.current_offset(), offset);
866 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
867 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index());
868 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
869 ASSERT_TRUE(iterator.IsValid());
870 --iterator;
871
872 offset -= Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
873 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kAdd);
874 EXPECT_EQ(iterator.current_index(), 13);
875 EXPECT_EQ(iterator.current_offset(), offset);
876 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
877 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
878 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
879 ASSERT_TRUE(iterator.IsValid());
880 --iterator;
881
882 offset -= Bytecodes::Size(Bytecode::kLdar, OperandScale::kSingle);
883 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdar);
884 EXPECT_EQ(iterator.current_index(), 12);
885 EXPECT_EQ(iterator.current_offset(), offset);
886 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
887 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
888 ASSERT_TRUE(iterator.IsValid());
889 --iterator;
890
891 offset -= Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
892 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
893 EXPECT_EQ(iterator.current_index(), 11);
894 EXPECT_EQ(iterator.current_offset(), offset);
895 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
896 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index());
897 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
898 ASSERT_TRUE(iterator.IsValid());
899 --iterator;
900
901 offset -= Bytecodes::Size(Bytecode::kStackCheck, OperandScale::kSingle);
902 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStackCheck);
903 EXPECT_EQ(iterator.current_index(), 10);
904 EXPECT_EQ(iterator.current_offset(), offset);
905 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
906 EXPECT_EQ(Bytecodes::NumberOfOperands(iterator.current_bytecode()), 0);
907 ASSERT_TRUE(iterator.IsValid());
908 --iterator;
909
910 offset -= Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kQuadruple) +
911 kPrefixByteSize;
912 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi);
913 EXPECT_EQ(iterator.current_index(), 9);
914 EXPECT_EQ(iterator.current_offset(), offset);
915 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple);
916 EXPECT_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_1);
917 ASSERT_TRUE(iterator.IsValid());
918 --iterator;
919
920 offset -= Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
921 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
922 EXPECT_EQ(iterator.current_index(), 8);
923 EXPECT_EQ(iterator.current_offset(), offset);
924 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
925 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
926 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
927 ASSERT_TRUE(iterator.IsValid());
928 --iterator;
929
930 offset -= Bytecodes::Size(Bytecode::kStackCheck, OperandScale::kSingle);
931 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStackCheck);
932 EXPECT_EQ(iterator.current_index(), 7);
933 EXPECT_EQ(iterator.current_offset(), offset);
934 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
935 EXPECT_EQ(Bytecodes::NumberOfOperands(iterator.current_bytecode()), 0);
936 ASSERT_TRUE(iterator.IsValid());
937 --iterator;
938
939 offset -= Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kSingle);
940 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi);
941 EXPECT_EQ(iterator.current_index(), 6);
942 EXPECT_EQ(iterator.current_offset(), offset);
943 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
944 EXPECT_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_0);
945 ASSERT_TRUE(iterator.IsValid());
946 --iterator;
947
948 offset -= Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
949 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
950 EXPECT_EQ(iterator.current_index(), 5);
951 EXPECT_EQ(iterator.current_offset(), offset);
952 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
953 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
954 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
955 ASSERT_TRUE(iterator.IsValid());
956 --iterator;
957
958 offset -= Bytecodes::Size(Bytecode::kLdaZero, OperandScale::kSingle);
959 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaZero);
960 EXPECT_EQ(iterator.current_index(), 4);
961 EXPECT_EQ(iterator.current_offset(), offset);
962 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
963 ASSERT_TRUE(iterator.IsValid());
964 --iterator;
965
966 offset -= Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
967 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
968 EXPECT_EQ(iterator.current_index(), 3);
969 EXPECT_EQ(iterator.current_offset(), offset);
970 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
971 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
972 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
973 ASSERT_TRUE(iterator.IsValid());
974 --iterator;
975
976 offset -= Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
977 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
978 EXPECT_EQ(iterator.current_index(), 2);
979 EXPECT_EQ(iterator.current_offset(), offset);
980 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
981 EXPECT_TRUE(
982 iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1));
983 ASSERT_TRUE(iterator.IsValid());
984 --iterator;
985
986 offset -= Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
987 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
988 EXPECT_EQ(iterator.current_index(), 1);
989 EXPECT_EQ(iterator.current_offset(), offset);
990 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
991 EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
992 EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
993 ASSERT_TRUE(iterator.IsValid());
994 --iterator;
995
996 offset -= Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
997 EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
998 EXPECT_EQ(iterator.current_index(), 0);
999 EXPECT_EQ(iterator.current_offset(), offset);
1000 EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
1001 EXPECT_TRUE(
1002 iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0));
1003 ASSERT_TRUE(iterator.IsValid());
1004 --iterator;
1005 ASSERT_FALSE(iterator.IsValid());
1006 }
1007
1008 } // namespace interpreter
1009 } // namespace internal
1010 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/BUILD.gn ('k') | test/unittests/interpreter/bytecode-array-reverse-iterator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698