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

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1392933002: [Interpreter] Reduce temporary register usage in generated bytecode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove dead code. Created 5 years, 2 months 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
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/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-generator.h" 9 #include "src/interpreter/bytecode-generator.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 SNPrintF(program, "%s\n%s();", function, kFunctionName); 68 SNPrintF(program, "%s\n%s();", function, kFunctionName);
69 return MakeBytecode(program.start(), kFunctionName); 69 return MakeBytecode(program.start(), kFunctionName);
70 } 70 }
71 }; 71 };
72 72
73 73
74 // Helper macros for handcrafting bytecode sequences. 74 // Helper macros for handcrafting bytecode sequences.
75 #define B(x) static_cast<uint8_t>(Bytecode::k##x) 75 #define B(x) static_cast<uint8_t>(Bytecode::k##x)
76 #define U8(x) static_cast<uint8_t>((x) & 0xff) 76 #define U8(x) static_cast<uint8_t>((x) & 0xff)
77 #define R(x) static_cast<uint8_t>(-(x) & 0xff) 77 #define R(x) static_cast<uint8_t>(-(x) & 0xff)
78 #define A(x, n) R(helper.kLastParamIndex - (n) + 1 + (x))
79 #define THIS(n) A(0, n)
78 #define _ static_cast<uint8_t>(0x5a) 80 #define _ static_cast<uint8_t>(0x5a)
79 #if defined(V8_TARGET_LITTLE_ENDIAN) 81 #if defined(V8_TARGET_LITTLE_ENDIAN)
80 #define U16(x) static_cast<uint8_t>((x) & 0xff), \ 82 #define U16(x) static_cast<uint8_t>((x) & 0xff), \
81 static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff) 83 static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff)
82 #elif defined(V8_TARGET_BIG_ENDIAN) 84 #elif defined(V8_TARGET_BIG_ENDIAN)
83 #define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ 85 #define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \
84 static_cast<uint8_t>((x) & 0xff) 86 static_cast<uint8_t>((x) & 0xff)
85 #else 87 #else
86 #error Unknown byte ordering 88 #error Unknown byte ordering
87 #endif 89 #endif
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 CHECK(actual == *expected || expected->StrictEquals(actual)); 123 CHECK(actual == *expected || expected->StrictEquals(actual));
122 } 124 }
123 125
124 126
125 static void CheckConstant(InstanceType expected, Object* actual) { 127 static void CheckConstant(InstanceType expected, Object* actual) {
126 CHECK_EQ(expected, HeapObject::cast(actual)->map()->instance_type()); 128 CHECK_EQ(expected, HeapObject::cast(actual)->map()->instance_type());
127 } 129 }
128 130
129 131
130 template <typename T> 132 template <typename T>
131 static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected, 133 static void CheckBytecodeArrayEqual(const ExpectedSnippet<T>& expected,
132 Handle<BytecodeArray> actual, 134 Handle<BytecodeArray> actual,
133 bool has_unknown = false) { 135 bool has_unknown = false) {
134 CHECK_EQ(actual->frame_size(), expected.frame_size); 136 CHECK_EQ(actual->frame_size(), expected.frame_size);
135 CHECK_EQ(actual->parameter_count(), expected.parameter_count); 137 CHECK_EQ(actual->parameter_count(), expected.parameter_count);
136 CHECK_EQ(actual->length(), expected.bytecode_length); 138 CHECK_EQ(actual->length(), expected.bytecode_length);
137 if (expected.constant_count == 0) { 139 if (expected.constant_count == 0) {
138 CHECK_EQ(actual->constant_pool(), CcTest::heap()->empty_fixed_array()); 140 CHECK_EQ(actual->constant_pool(), CcTest::heap()->empty_fixed_array());
139 } else { 141 } else {
140 CHECK_EQ(actual->constant_pool()->length(), expected.constant_count); 142 CHECK_EQ(actual->constant_pool()->length(), expected.constant_count);
141 for (int i = 0; i < expected.constant_count; i++) { 143 for (int i = 0; i < expected.constant_count; i++) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 224 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
223 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 225 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
224 } 226 }
225 } 227 }
226 228
227 229
228 TEST(PrimitiveExpressions) { 230 TEST(PrimitiveExpressions) {
229 InitializedHandleScope handle_scope; 231 InitializedHandleScope handle_scope;
230 BytecodeGeneratorHelper helper; 232 BytecodeGeneratorHelper helper;
231 233
232 ExpectedSnippet<int> snippets[] = { 234 ExpectedSnippet<int> snippets[] = {{"var x = 0; return x;",
233 {"var x = 0; return x;", 235 kPointerSize,
234 kPointerSize, 236 1,
235 1, 237 6,
236 6, 238 {B(LdaZero), //
237 {B(LdaZero), // 239 B(Star), R(0), //
238 B(Star), R(0), // 240 B(Ldar), R(0), //
239 B(Ldar), R(0), // 241 B(Return)},
240 B(Return)}, 242 0},
241 0}, 243 {"var x = 0; return x + 3;",
242 {"var x = 0; return x + 3;", 244 kPointerSize,
243 2 * kPointerSize, 245 1,
244 1, 246 8,
245 12, 247 {B(LdaZero), //
246 {B(LdaZero), // 248 B(Star), R(0), //
247 B(Star), R(0), // 249 B(LdaSmi8), U8(3), //
248 B(Ldar), R(0), // Easy to spot r1 not really needed here. 250 B(Add), R(0), //
249 B(Star), R(1), // Dead store. 251 B(Return)},
250 B(LdaSmi8), U8(3), // 252 0},
251 B(Add), R(1), // 253 {"var x = 0; return x - 3;",
252 B(Return)}, 254 kPointerSize,
253 0}, 255 1,
254 {"var x = 0; return x - 3;", 256 8,
255 2 * kPointerSize, 257 {B(LdaZero), //
256 1, 258 B(Star), R(0), //
257 12, 259 B(LdaSmi8), U8(3), //
258 {B(LdaZero), // 260 B(Sub), R(0), //
259 B(Star), R(0), // 261 B(Return)},
260 B(Ldar), R(0), // Easy to spot r1 not really needed here. 262 0},
261 B(Star), R(1), // Dead store. 263 {"var x = 4; return x * 3;",
262 B(LdaSmi8), U8(3), // 264 kPointerSize,
263 B(Sub), R(1), // 265 1,
264 B(Return)}, 266 9,
265 0}, 267 {B(LdaSmi8), U8(4), //
266 {"var x = 4; return x * 3;", 268 B(Star), R(0), //
267 2 * kPointerSize, 269 B(LdaSmi8), U8(3), //
268 1, 270 B(Mul), R(0), //
269 13, 271 B(Return)},
270 {B(LdaSmi8), U8(4), // 272 0},
271 B(Star), R(0), // 273 {"var x = 4; return x / 3;",
272 B(Ldar), R(0), // Easy to spot r1 not really needed here. 274 kPointerSize,
273 B(Star), R(1), // Dead store. 275 1,
274 B(LdaSmi8), U8(3), // 276 9,
275 B(Mul), R(1), // 277 {B(LdaSmi8), U8(4), //
276 B(Return)}, 278 B(Star), R(0), //
277 0}, 279 B(LdaSmi8), U8(3), //
278 {"var x = 4; return x / 3;", 280 B(Div), R(0), //
279 2 * kPointerSize, 281 B(Return)},
280 1, 282 0},
281 13, 283 {"var x = 4; return x % 3;",
282 {B(LdaSmi8), U8(4), // 284 kPointerSize,
283 B(Star), R(0), // 285 1,
284 B(Ldar), R(0), // Easy to spot r1 not really needed here. 286 9,
285 B(Star), R(1), // Dead store. 287 {B(LdaSmi8), U8(4), //
286 B(LdaSmi8), U8(3), // 288 B(Star), R(0), //
287 B(Div), R(1), // 289 B(LdaSmi8), U8(3), //
288 B(Return)}, 290 B(Mod), R(0), //
289 0}, 291 B(Return)},
290 {"var x = 4; return x % 3;", 292 0},
291 2 * kPointerSize, 293 {"var x = 1; return x | 2;",
292 1, 294 kPointerSize,
293 13, 295 1,
294 {B(LdaSmi8), U8(4), // 296 9,
295 B(Star), R(0), // 297 {B(LdaSmi8), U8(1), //
296 B(Ldar), R(0), // Easy to spot r1 not really needed here. 298 B(Star), R(0), //
297 B(Star), R(1), // Dead store. 299 B(LdaSmi8), U8(2), //
298 B(LdaSmi8), U8(3), // 300 B(BitwiseOr), R(0), //
299 B(Mod), R(1), // 301 B(Return)},
300 B(Return)}, 302 0},
301 0}, 303 {"var x = 1; return x ^ 2;",
302 {"var x = 1; return x | 2;", 304 kPointerSize,
303 2 * kPointerSize, 305 1,
304 1, 306 9,
305 13, 307 {B(LdaSmi8), U8(1), //
306 {B(LdaSmi8), U8(1), // 308 B(Star), R(0), //
307 B(Star), R(0), // 309 B(LdaSmi8), U8(2), //
308 B(Ldar), R(0), // Easy to spot r1 not really needed here. 310 B(BitwiseXor), R(0), //
309 B(Star), R(1), // Dead store. 311 B(Return)},
310 B(LdaSmi8), U8(2), // 312 0},
311 B(BitwiseOr), R(1), // 313 {"var x = 1; return x & 2;",
312 B(Return)}, 314 kPointerSize,
313 0}, 315 1,
314 {"var x = 1; return x ^ 2;", 316 9,
315 2 * kPointerSize, 317 {B(LdaSmi8), U8(1), //
316 1, 318 B(Star), R(0), //
317 13, 319 B(LdaSmi8), U8(2), //
318 {B(LdaSmi8), U8(1), // 320 B(BitwiseAnd), R(0), //
319 B(Star), R(0), // 321 B(Return)},
320 B(Ldar), R(0), // Easy to spot r1 not really needed here. 322 0},
321 B(Star), R(1), // Dead store. 323 {"var x = 10; return x << 3;",
322 B(LdaSmi8), U8(2), // 324 kPointerSize,
323 B(BitwiseXor), R(1), // 325 1,
324 B(Return)}, 326 9,
325 0}, 327 {B(LdaSmi8), U8(10), //
326 {"var x = 1; return x & 2;", 328 B(Star), R(0), //
327 2 * kPointerSize, 329 B(LdaSmi8), U8(3), //
328 1, 330 B(ShiftLeft), R(0), //
329 13, 331 B(Return)},
330 {B(LdaSmi8), U8(1), // 332 0},
331 B(Star), R(0), // 333 {"var x = 10; return x >> 3;",
332 B(Ldar), R(0), // Easy to spot r1 not really needed here. 334 kPointerSize,
333 B(Star), R(1), // Dead store. 335 1,
334 B(LdaSmi8), U8(2), // 336 9,
335 B(BitwiseAnd), R(1), // 337 {B(LdaSmi8), U8(10), //
336 B(Return)}, 338 B(Star), R(0), //
337 0}, 339 B(LdaSmi8), U8(3), //
338 {"var x = 10; return x << 3;", 340 B(ShiftRight), R(0), //
339 2 * kPointerSize, 341 B(Return)},
340 1, 342 0},
341 13, 343 {"var x = 10; return x >>> 3;",
342 {B(LdaSmi8), U8(10), // 344 kPointerSize,
343 B(Star), R(0), // 345 1,
344 B(Ldar), R(0), // Easy to spot r1 not really needed here. 346 9,
345 B(Star), R(1), // Dead store. 347 {B(LdaSmi8), U8(10), //
346 B(LdaSmi8), U8(3), // 348 B(Star), R(0), //
347 B(ShiftLeft), R(1), // 349 B(LdaSmi8), U8(3), //
348 B(Return)}, 350 B(ShiftRightLogical), R(0), //
349 0}, 351 B(Return)},
350 {"var x = 10; return x >> 3;", 352 0},
351 2 * kPointerSize, 353 {"var x = 0; return (x, 3);",
352 1, 354 kPointerSize,
353 13, 355 1,
354 {B(LdaSmi8), U8(10), // 356 8,
355 B(Star), R(0), // 357 {B(LdaZero), //
356 B(Ldar), R(0), // Easy to spot r1 not really needed here. 358 B(Star), R(0), //
357 B(Star), R(1), // Dead store. 359 B(Ldar), R(0), //
358 B(LdaSmi8), U8(3), // 360 B(LdaSmi8), U8(3), //
359 B(ShiftRight), R(1), // 361 B(Return)},
360 B(Return)}, 362 0}};
361 0},
362 {"var x = 10; return x >>> 3;",
363 2 * kPointerSize,
364 1,
365 13,
366 {B(LdaSmi8), U8(10), //
367 B(Star), R(0), //
368 B(Ldar), R(0), // Easy to spot r1 not really needed here.
369 B(Star), R(1), // Dead store.
370 B(LdaSmi8), U8(3), //
371 B(ShiftRightLogical), R(1), //
372 B(Return)},
373 0},
374 {"var x = 0; return (x, 3);",
375 1 * kPointerSize,
376 1,
377 8,
378 {B(LdaZero), //
379 B(Star), R(0), //
380 B(Ldar), R(0), //
381 B(LdaSmi8), U8(3), //
382 B(Return)},
383 0}};
384 363
385 for (size_t i = 0; i < arraysize(snippets); i++) { 364 for (size_t i = 0; i < arraysize(snippets); i++) {
386 Handle<BytecodeArray> bytecode_array = 365 Handle<BytecodeArray> bytecode_array =
387 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 366 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
388 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 367 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
389 } 368 }
390 } 369 }
391 370
392 371
393 TEST(LogicalExpressions) { 372 TEST(LogicalExpressions) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 } 479 }
501 } 480 }
502 481
503 482
504 TEST(Parameters) { 483 TEST(Parameters) {
505 InitializedHandleScope handle_scope; 484 InitializedHandleScope handle_scope;
506 BytecodeGeneratorHelper helper; 485 BytecodeGeneratorHelper helper;
507 486
508 ExpectedSnippet<int> snippets[] = { 487 ExpectedSnippet<int> snippets[] = {
509 {"function f() { return this; }", 488 {"function f() { return this; }",
510 0, 1, 3, {B(Ldar), R(helper.kLastParamIndex), B(Return)}, 0}, 489 0,
490 1,
491 3,
492 {B(Ldar), THIS(1), B(Return)},
493 0},
511 {"function f(arg1) { return arg1; }", 494 {"function f(arg1) { return arg1; }",
512 0, 2, 3, {B(Ldar), R(helper.kLastParamIndex), B(Return)}, 0}, 495 0,
496 2,
497 3,
498 {B(Ldar), A(1, 2), B(Return)},
499 0},
513 {"function f(arg1) { return this; }", 500 {"function f(arg1) { return this; }",
514 0, 2, 3, {B(Ldar), R(helper.kLastParamIndex - 1), B(Return)}, 0}, 501 0,
502 2,
503 3,
504 {B(Ldar), THIS(2), B(Return)},
505 0},
515 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }", 506 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }",
516 0, 8, 3, {B(Ldar), R(helper.kLastParamIndex - 3), B(Return)}, 0}, 507 0,
508 8,
509 3,
510 {B(Ldar), A(4, 8), B(Return)},
511 0},
517 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }", 512 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }",
518 0, 8, 3, {B(Ldar), R(helper.kLastParamIndex - 7), B(Return)}, 0}, 513 0,
514 8,
515 3,
516 {B(Ldar), THIS(8), B(Return)},
517 0},
519 {"function f(arg1) { arg1 = 1; }", 518 {"function f(arg1) { arg1 = 1; }",
520 0, 2, 6, 519 0,
521 {B(LdaSmi8), U8(1), // 520 2,
522 B(Star), R(helper.kLastParamIndex), // 521 6,
523 B(LdaUndefined), // 522 {B(LdaSmi8), U8(1), //
523 B(Star), A(1, 2), //
524 B(LdaUndefined), //
524 B(Return)}, 525 B(Return)},
525 0}, 526 0},
526 {"function f(arg1, arg2, arg3, arg4) { arg2 = 1; }", 527 {"function f(arg1, arg2, arg3, arg4) { arg2 = 1; }",
527 0, 5, 6, 528 0,
528 {B(LdaSmi8), U8(1), // 529 5,
529 B(Star), R(helper.kLastParamIndex - 2), // 530 6,
530 B(LdaUndefined), // 531 {B(LdaSmi8), U8(1), //
532 B(Star), A(2, 5), //
533 B(LdaUndefined), //
531 B(Return)}, 534 B(Return)},
532 0}, 535 0},
533 }; 536 };
534 537
535 for (size_t i = 0; i < arraysize(snippets); i++) { 538 for (size_t i = 0; i < arraysize(snippets); i++) {
536 Handle<BytecodeArray> bytecode_array = 539 Handle<BytecodeArray> bytecode_array =
537 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 540 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
538 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 541 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
539 } 542 }
540 } 543 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 693
691 FeedbackVectorSpec feedback_spec(&zone); 694 FeedbackVectorSpec feedback_spec(&zone);
692 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); 695 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
693 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); 696 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot();
694 697
695 Handle<i::TypeFeedbackVector> vector = 698 Handle<i::TypeFeedbackVector> vector =
696 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); 699 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
697 700
698 ExpectedSnippet<const char*> snippets[] = { 701 ExpectedSnippet<const char*> snippets[] = {
699 {"function f(a) { return a.name; }\nf({name : \"test\"})", 702 {"function f(a) { return a.name; }\nf({name : \"test\"})",
700 1 * kPointerSize, 703 0,
701 2, 704 2,
702 10, 705 6,
703 { 706 {
704 B(Ldar), R(helper.kLastParamIndex), // 707 B(LdaConstant), U8(0), //
705 B(Star), R(0), // 708 B(LoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), //
706 B(LdaConstant), U8(0), // 709 B(Return), //
707 B(LoadICSloppy), R(0), U8(vector->GetIndex(slot1)), //
708 B(Return) //
709 }, 710 },
710 1, 711 1,
711 {"name"}}, 712 {"name"}},
712 {"function f(a) { return a[\"key\"]; }\nf({key : \"test\"})", 713 {"function f(a) { return a[\"key\"]; }\nf({key : \"test\"})",
713 1 * kPointerSize, 714 0,
714 2, 715 2,
715 10, 716 6,
716 { 717 {
717 B(Ldar), R(helper.kLastParamIndex), // 718 B(LdaConstant), U8(0), //
718 B(Star), R(0), // 719 B(LoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), //
719 B(LdaConstant), U8(0), // 720 B(Return) //
720 B(LoadICSloppy), R(0), U8(vector->GetIndex(slot1)), //
721 B(Return) //
722 }, 721 },
723 1, 722 1,
724 {"key"}}, 723 {"key"}},
725 {"function f(a) { return a[100]; }\nf({100 : \"test\"})", 724 {"function f(a) { return a[100]; }\nf({100 : \"test\"})",
726 1 * kPointerSize, 725 0,
727 2, 726 2,
728 10, 727 6,
729 { 728 {
730 B(Ldar), R(helper.kLastParamIndex), // 729 B(LdaSmi8), U8(100), //
731 B(Star), R(0), // 730 B(KeyedLoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), //
732 B(LdaSmi8), U8(100), // 731 B(Return) //
733 B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), //
734 B(Return) //
735 }, 732 },
736 0}, 733 0},
737 {"function f(a, b) { return a[b]; }\nf({arg : \"test\"}, \"arg\")", 734 {"function f(a, b) { return a[b]; }\nf({arg : \"test\"}, \"arg\")",
738 1 * kPointerSize, 735 0,
739 3, 736 3,
740 10, 737 6,
741 { 738 {
742 B(Ldar), R(helper.kLastParamIndex - 1), // 739 B(Ldar), A(1, 2), //
743 B(Star), R(0), // 740 B(KeyedLoadICSloppy), A(1, 3), U8(vector->GetIndex(slot1)), //
744 B(Ldar), R(helper.kLastParamIndex), // 741 B(Return) //
745 B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), //
746 B(Return) //
747 }, 742 },
748 0}, 743 0},
749 {"function f(a) { var b = a.name; return a[-124]; }\n" 744 {"function f(a) { var b = a.name; return a[-124]; }\n"
750 "f({\"-124\" : \"test\", name : 123 })", 745 "f({\"-124\" : \"test\", name : 123 })",
751 2 * kPointerSize, 746 kPointerSize,
752 2, 747 2,
753 21, 748 13,
754 { 749 {
755 B(Ldar), R(helper.kLastParamIndex), // 750 B(LdaConstant), U8(0), //
756 B(Star), R(1), // 751 B(LoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), //
757 B(LdaConstant), U8(0), // 752 B(Star), R(0), //
758 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot1)), // 753 B(LdaSmi8), U8(-124), //
759 B(Star), R(0), // 754 B(KeyedLoadICSloppy), A(1, 2), U8(vector->GetIndex(slot2)), //
760 B(Ldar), R(helper.kLastParamIndex), // 755 B(Return), //
761 B(Star), R(1), //
762 B(LdaSmi8), U8(-124), //
763 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot2)), //
764 B(Return) //
765 }, 756 },
766 1, 757 1,
767 {"name"}}, 758 {"name"}},
768 {"function f(a) { \"use strict\"; return a.name; }\nf({name : \"test\"})", 759 {"function f(a) { \"use strict\"; return a.name; }\nf({name : \"test\"})",
769 1 * kPointerSize, 760 0,
770 2, 761 2,
771 12, 762 8,
772 { 763 {
773 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" 764 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict"
774 // expression, or any other unused literal expression. 765 // expression, or any other unused literal expression.
775 B(LdaConstant), U8(0), // 766 B(LdaConstant), U8(0), //
776 B(Ldar), R(helper.kLastParamIndex), // 767 B(LdaConstant), U8(1), //
777 B(Star), R(0), // 768 B(LoadICStrict), A(1, 2), U8(vector->GetIndex(slot1)), //
778 B(LdaConstant), U8(1), // 769 B(Return), //
779 B(LoadICStrict), R(0), U8(vector->GetIndex(slot1)), //
780 B(Return) //
781 }, 770 },
782 2, 771 2,
783 {"use strict", "name"}}, 772 {"use strict", "name"}},
784 {"function f(a, b) { \"use strict\"; return a[b]; }\n" 773 {"function f(a, b) { \"use strict\"; return a[b]; }\n"
785 "f({arg : \"test\"}, \"arg\")", 774 "f({arg : \"test\"}, \"arg\")",
786 1 * kPointerSize, 775 0,
787 3, 776 3,
788 12, 777 8,
789 { 778 {
790 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" 779 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict"
791 // expression, or any other unused literal expression. 780 // expression, or any other unused literal expression.
792 B(LdaConstant), U8(0), // 781 B(LdaConstant), U8(0), //
793 B(Ldar), R(helper.kLastParamIndex - 1), // 782 B(Ldar), A(2, 3), //
794 B(Star), R(0), // 783 B(KeyedLoadICStrict), A(1, 3), U8(vector->GetIndex(slot1)), //
795 B(Ldar), R(helper.kLastParamIndex), // 784 B(Return), //
796 B(KeyedLoadICStrict), R(0), U8(vector->GetIndex(slot1)), //
797 B(Return) //
798 }, 785 },
799 1, 786 1,
800 {"use strict"}}}; 787 {"use strict"}}};
801 for (size_t i = 0; i < arraysize(snippets); i++) { 788 for (size_t i = 0; i < arraysize(snippets); i++) {
802 Handle<BytecodeArray> bytecode_array = 789 Handle<BytecodeArray> bytecode_array =
803 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 790 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
804 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 791 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
805 } 792 }
806 } 793 }
807 794
808 795
809 TEST(PropertyStores) { 796 TEST(PropertyStores) {
810 InitializedHandleScope handle_scope; 797 InitializedHandleScope handle_scope;
811 BytecodeGeneratorHelper helper; 798 BytecodeGeneratorHelper helper;
812 Zone zone; 799 Zone zone;
813 800
814 FeedbackVectorSpec feedback_spec(&zone); 801 FeedbackVectorSpec feedback_spec(&zone);
815 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot(); 802 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot();
816 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); 803 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
817 804
818 Handle<i::TypeFeedbackVector> vector = 805 Handle<i::TypeFeedbackVector> vector =
819 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); 806 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
820 807
821 ExpectedSnippet<const char*> snippets[] = { 808 ExpectedSnippet<const char*> snippets[] = {
822 {"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})", 809 {"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})",
823 2 * kPointerSize, 810 kPointerSize,
824 2, 811 2,
825 16, 812 12,
826 { 813 {
827 B(Ldar), R(helper.kLastParamIndex), // 814 B(LdaConstant), U8(0), //
828 B(Star), R(0), // 815 B(Star), R(0), //
829 B(LdaConstant), U8(0), // 816 B(LdaConstant), U8(1), //
830 B(Star), R(1), // 817 B(StoreICSloppy), A(1, 2), R(0), U8(vector->GetIndex(slot1)), //
831 B(LdaConstant), U8(1), // 818 B(LdaUndefined), //
832 B(StoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), // 819 B(Return), //
833 B(LdaUndefined), //
834 B(Return) //
835 }, 820 },
836 2, 821 2,
837 {"name", "val"}}, 822 {"name", "val"}},
838 {"function f(a) { a[\"key\"] = \"val\"; }\nf({key : \"test\"})", 823 {"function f(a) { a[\"key\"] = \"val\"; }\nf({key : \"test\"})",
839 2 * kPointerSize, 824 kPointerSize,
840 2, 825 2,
841 16, 826 12,
842 { 827 {
843 B(Ldar), R(helper.kLastParamIndex), // 828 B(LdaConstant), U8(0), //
844 B(Star), R(0), // 829 B(Star), R(0), //
845 B(LdaConstant), U8(0), // 830 B(LdaConstant), U8(1), //
846 B(Star), R(1), // 831 B(StoreICSloppy), A(1, 2), R(0), U8(vector->GetIndex(slot1)), //
847 B(LdaConstant), U8(1), // 832 B(LdaUndefined), //
848 B(StoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), // 833 B(Return), //
849 B(LdaUndefined), //
850 B(Return) //
851 }, 834 },
852 2, 835 2,
853 {"key", "val"}}, 836 {"key", "val"}},
854 {"function f(a) { a[100] = \"val\"; }\nf({100 : \"test\"})", 837 {"function f(a) { a[100] = \"val\"; }\nf({100 : \"test\"})",
855 2 * kPointerSize, 838 kPointerSize,
856 2, 839 2,
857 16, 840 12,
858 { 841 {
859 B(Ldar), R(helper.kLastParamIndex), // 842 B(LdaSmi8), U8(100), //
860 B(Star), R(0), // 843 B(Star), R(0), //
861 B(LdaSmi8), U8(100), // 844 B(LdaConstant), U8(0), //
862 B(Star), R(1), // 845 B(KeyedStoreICSloppy), A(1, 2), R(0), //
863 B(LdaConstant), U8(0), // 846 U8(vector->GetIndex(slot1)), //
rmcilroy 2015/10/19 12:56:23 nit - indent operands (and below) - I can't find a
oth 2015/10/20 15:28:53 Done.
864 B(KeyedStoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), // 847 B(LdaUndefined), //
865 B(LdaUndefined), // 848 B(Return), //
866 B(Return) //
867 }, 849 },
868 1, 850 1,
869 {"val"}}, 851 {"val"}},
870 {"function f(a, b) { a[b] = \"val\"; }\nf({arg : \"test\"}, \"arg\")", 852 {"function f(a, b) { a[b] = \"val\"; }\nf({arg : \"test\"}, \"arg\")",
871 2 * kPointerSize, 853 0,
872 3, 854 3,
873 16, 855 8,
874 { 856 {
875 B(Ldar), R(helper.kLastParamIndex - 1), // 857 B(LdaConstant), U8(0), //
876 B(Star), R(0), // 858 B(KeyedStoreICSloppy), A(1, 3), A(2, 3), //
877 B(Ldar), R(helper.kLastParamIndex), // 859 U8(vector->GetIndex(slot1)), //
878 B(Star), R(1), // 860 B(LdaUndefined), //
879 B(LdaConstant), U8(0), // 861 B(Return), //
880 B(KeyedStoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), //
881 B(LdaUndefined), //
882 B(Return) //
883 }, 862 },
884 1, 863 1,
885 {"val"}}, 864 {"val"}},
886 {"function f(a) { a.name = a[-124]; }\n" 865 {"function f(a) { a.name = a[-124]; }\n"
887 "f({\"-124\" : \"test\", name : 123 })", 866 "f({\"-124\" : \"test\", name : 123 })",
888 3 * kPointerSize, 867 kPointerSize,
889 2, 868 2,
890 23, 869 15,
891 { 870 {
892 B(Ldar), R(helper.kLastParamIndex), // 871 B(LdaConstant), U8(0), //
893 B(Star), R(0), // 872 B(Star), R(0), //
894 B(LdaConstant), U8(0), // 873 B(LdaSmi8), U8(-124), //
895 B(Star), R(1), // 874 B(KeyedLoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), //
896 B(Ldar), R(helper.kLastParamIndex), // 875 B(StoreICSloppy), A(1, 2), R(0), U8(vector->GetIndex(slot2)), //
897 B(Star), R(2), // 876 B(LdaUndefined), //
898 B(LdaSmi8), U8(-124), // 877 B(Return), //
899 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot1)), //
900 B(StoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot2)), //
901 B(LdaUndefined), //
902 B(Return) //
903 }, 878 },
904 1, 879 1,
905 {"name"}}, 880 {"name"}},
906 {"function f(a) { \"use strict\"; a.name = \"val\"; }\n" 881 {"function f(a) { \"use strict\"; a.name = \"val\"; }\n"
907 "f({name : \"test\"})", 882 "f({name : \"test\"})",
908 2 * kPointerSize, 883 kPointerSize,
909 2, 884 2,
910 18, 885 14,
911 { 886 {
912 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" 887 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict"
913 // expression, or any other unused literal expression. 888 // expression, or any other unused literal expression.
914 B(LdaConstant), U8(0), // 889 B(LdaConstant), U8(0), //
915 B(Ldar), R(helper.kLastParamIndex), // 890 B(LdaConstant), U8(1), //
916 B(Star), R(0), // 891 B(Star), R(0), //
917 B(LdaConstant), U8(1), // 892 B(LdaConstant), U8(2), //
918 B(Star), R(1), // 893 B(StoreICStrict), A(1, 2), R(0), U8(vector->GetIndex(slot1)), //
919 B(LdaConstant), U8(2), // 894 B(LdaUndefined), //
920 B(StoreICStrict), R(0), R(1), U8(vector->GetIndex(slot1)), // 895 B(Return), //
921 B(LdaUndefined), //
922 B(Return) //
923 }, 896 },
924 3, 897 3,
925 {"use strict", "name", "val"}}, 898 {"use strict", "name", "val"}},
926 {"function f(a, b) { \"use strict\"; a[b] = \"val\"; }\n" 899 {"function f(a, b) { \"use strict\"; a[b] = \"val\"; }\n"
927 "f({arg : \"test\"}, \"arg\")", 900 "f({arg : \"test\"}, \"arg\")",
928 2 * kPointerSize, 901 0,
929 3, 902 3,
930 18, 903 10,
931 { 904 {
932 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" 905 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict"
933 // expression, or any other unused literal expression. 906 // expression, or any other unused literal expression.
934 B(LdaConstant), U8(0), // 907 B(LdaConstant), U8(0), //
935 B(Ldar), R(helper.kLastParamIndex - 1), // 908 B(LdaConstant), U8(1), //
936 B(Star), R(0), // 909 B(KeyedStoreICStrict), A(1, 3), A(2, 3), //
937 B(Ldar), R(helper.kLastParamIndex), // 910 U8(vector->GetIndex(slot1)), //
938 B(Star), R(1), // 911 B(LdaUndefined), //
939 B(LdaConstant), U8(1), // 912 B(Return), //
940 B(KeyedStoreICStrict), R(0), R(1), U8(vector->GetIndex(slot1)), //
941 B(LdaUndefined), //
942 B(Return) //
943 }, 913 },
944 2, 914 2,
945 {"use strict", "val"}}}; 915 {"use strict", "val"}}};
946 for (size_t i = 0; i < arraysize(snippets); i++) { 916 for (size_t i = 0; i < arraysize(snippets); i++) {
947 Handle<BytecodeArray> bytecode_array = 917 Handle<BytecodeArray> bytecode_array =
948 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 918 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
949 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 919 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
950 } 920 }
951 } 921 }
952 922
(...skipping 13 matching lines...) Expand all
966 936
967 Handle<i::TypeFeedbackVector> vector = 937 Handle<i::TypeFeedbackVector> vector =
968 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); 938 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
969 939
970 ExpectedSnippet<const char*> snippets[] = { 940 ExpectedSnippet<const char*> snippets[] = {
971 {"function f(a) { return a.func(); }\nf(" FUNC_ARG ")", 941 {"function f(a) { return a.func(); }\nf(" FUNC_ARG ")",
972 2 * kPointerSize, 942 2 * kPointerSize,
973 2, 943 2,
974 16, 944 16,
975 { 945 {
976 B(Ldar), R(helper.kLastParamIndex), // 946 B(Ldar), A(1, 2), //
977 B(Star), R(1), // 947 B(Star), R(1), //
978 B(LdaConstant), U8(0), // 948 B(LdaConstant), U8(0), //
979 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // 949 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), //
980 B(Star), R(0), // 950 B(Star), R(0), //
981 B(Call), R(0), R(1), U8(0), // 951 B(Call), R(0), R(1), U8(0), //
982 B(Return) // 952 B(Return), //
983 }, 953 },
984 1, 954 1,
985 {"func"}}, 955 {"func"}},
986 {"function f(a, b, c) { return a.func(b, c); }\nf(" FUNC_ARG ", 1, 2)", 956 {"function f(a, b, c) { return a.func(b, c); }\nf(" FUNC_ARG ", 1, 2)",
987 4 * kPointerSize, 957 4 * kPointerSize,
988 4, 958 4,
989 24, 959 24,
990 { 960 {
991 B(Ldar), R(helper.kLastParamIndex - 2), // 961 B(Ldar), A(1, 4), //
992 B(Star), R(1), // 962 B(Star), R(1), //
993 B(LdaConstant), U8(0), // 963 B(LdaConstant), U8(0), //
994 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // 964 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), //
995 B(Star), R(0), // 965 B(Star), R(0), //
996 B(Ldar), R(helper.kLastParamIndex - 1), // 966 B(Ldar), A(2, 4), //
997 B(Star), R(2), // 967 B(Star), R(2), //
998 B(Ldar), R(helper.kLastParamIndex), // 968 B(Ldar), A(3, 4), //
999 B(Star), R(3), // 969 B(Star), R(3), //
1000 B(Call), R(0), R(1), U8(2), // 970 B(Call), R(0), R(1), U8(2), //
1001 B(Return) // 971 B(Return) //
1002 }, 972 },
1003 1, 973 1,
1004 {"func"}}, 974 {"func"}},
1005 {"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)", 975 {"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)",
1006 4 * kPointerSize, 976 4 * kPointerSize,
1007 3, 977 3,
1008 30, 978 26,
1009 { 979 {
1010 B(Ldar), R(helper.kLastParamIndex - 1), // 980 B(Ldar), A(1, 3), //
1011 B(Star), R(1), // 981 B(Star), R(1), //
1012 B(LdaConstant), U8(0), // 982 B(LdaConstant), U8(0), //
1013 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // 983 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), //
1014 B(Star), R(0), // 984 B(Star), R(0), //
1015 B(Ldar), R(helper.kLastParamIndex), // 985 B(Ldar), A(2, 3), //
1016 B(Star), R(3), // 986 B(Add), A(2, 3), //
1017 B(Ldar), R(helper.kLastParamIndex), //
1018 B(Add), R(3), //
1019 B(Star), R(2), // 987 B(Star), R(2), //
1020 B(Ldar), R(helper.kLastParamIndex), // 988 B(Ldar), A(2, 3), //
1021 B(Star), R(3), // 989 B(Star), R(3), //
1022 B(Call), R(0), R(1), U8(2), // 990 B(Call), R(0), R(1), U8(2), //
1023 B(Return), // 991 B(Return), //
1024 }, 992 },
1025 1, 993 1,
1026 {"func"}}}; 994 {"func"}}};
1027 for (size_t i = 0; i < arraysize(snippets); i++) { 995 for (size_t i = 0; i < arraysize(snippets); i++) {
1028 Handle<BytecodeArray> bytecode_array = 996 Handle<BytecodeArray> bytecode_array =
1029 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 997 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
1030 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 998 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 B(LdaUndefined), // 1255 B(LdaUndefined), //
1288 B(Return) // 1256 B(Return) //
1289 }, 1257 },
1290 }, 1258 },
1291 { 1259 {
1292 "function f(a) { return %IsArray(a) }\nf(undefined)", 1260 "function f(a) { return %IsArray(a) }\nf(undefined)",
1293 1 * kPointerSize, 1261 1 * kPointerSize,
1294 2, 1262 2,
1295 10, 1263 10,
1296 { 1264 {
1297 B(Ldar), R(helper.kLastParamIndex), // 1265 B(Ldar), A(1, 2), //
1298 B(Star), R(0), // 1266 B(Star), R(0), //
1299 B(CallRuntime), U16(Runtime::kIsArray), R(0), U8(1), // 1267 B(CallRuntime), U16(Runtime::kIsArray), R(0), U8(1), //
1300 B(Return) // 1268 B(Return) //
1301 }, 1269 },
1302 }, 1270 },
1303 { 1271 {
1304 "function f() { return %Add(1, 2) }\nf()", 1272 "function f() { return %Add(1, 2) }\nf()",
1305 2 * kPointerSize, 1273 2 * kPointerSize,
1306 1, 1274 1,
1307 14, 1275 14,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 B(Return), // 1342 B(Return), //
1375 B(Jump), U8(5), // 1343 B(Jump), U8(5), //
1376 B(LdaSmi8), U8(-1), // 1344 B(LdaSmi8), U8(-1), //
1377 B(Return), // 1345 B(Return), //
1378 B(LdaUndefined), // 1346 B(LdaUndefined), //
1379 B(Return)}, // 1347 B(Return)}, //
1380 0, 1348 0,
1381 {unused, unused, unused, unused, unused, unused}}, 1349 {unused, unused, unused, unused, unused, unused}},
1382 {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }" 1350 {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }"
1383 "f(99);", 1351 "f(99);",
1384 kPointerSize, 1352 0,
1385 2, 1353 2,
1386 19, 1354 15,
1387 {B(Ldar), R(helper.kLastParamIndex), // 1355 {B(LdaZero), //
1388 B(Star), R(0), // 1356 B(TestLessThanOrEqual), A(1, 2), //
1389 B(LdaZero), // 1357 B(JumpIfFalse), U8(7), //
1390 B(TestLessThanOrEqual), R(0), // 1358 B(LdaConstant), U8(0), //
1391 B(JumpIfFalse), U8(7), // 1359 B(Return), //
1392 B(LdaConstant), U8(0), // 1360 B(Jump), U8(5), //
1393 B(Return), // 1361 B(LdaConstant), U8(1), //
1394 B(Jump), U8(5), // 1362 B(Return), //
1395 B(LdaConstant), U8(1), // 1363 B(LdaUndefined), //
1396 B(Return), // 1364 B(Return)}, //
1397 B(LdaUndefined), //
1398 B(Return)}, //
1399 2, 1365 2,
1400 {helper.factory()->NewNumberFromInt(200), 1366 {helper.factory()->NewNumberFromInt(200),
1401 helper.factory()->NewNumberFromInt(-200), unused, unused, unused, 1367 helper.factory()->NewNumberFromInt(-200), unused, unused, unused,
1402 unused}}, 1368 unused}},
1403 {"function f(a, b) { if (a in b) { return 200; } }" 1369 {"function f(a, b) { if (a in b) { return 200; } }"
1404 "f('prop', { prop: 'yes'});", 1370 "f('prop', { prop: 'yes'});",
1405 kPointerSize, 1371 0,
1406 3, 1372 3,
1407 15, 1373 11,
1408 {B(Ldar), R(helper.kLastParamIndex - 1), // 1374 {B(Ldar), A(2, 3), //
1409 B(Star), R(0), // 1375 B(TestIn), A(1, 3), //
1410 B(Ldar), R(helper.kLastParamIndex), // 1376 B(JumpIfFalse), U8(5), //
1411 B(TestIn), R(0), // 1377 B(LdaConstant), U8(0), //
1412 B(JumpIfFalse), U8(5), // 1378 B(Return), //
1413 B(LdaConstant), U8(0), // 1379 B(LdaUndefined), //
1414 B(Return), // 1380 B(Return)}, //
1415 B(LdaUndefined), //
1416 B(Return)}, //
1417 1, 1381 1,
1418 {helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused, 1382 {helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused,
1419 unused}}, 1383 unused}},
1420 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " 1384 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { "
1421 #define X "b = a; a = b; " 1385 #define X "b = a; a = b; "
1422 X X X X X X X X X X X X X X X X X X X X X X X X 1386 X X X X X X X X X X X X X X X X X X X X X X X X
1423 #undef X 1387 #undef X
1424 " return 200; } else { return -200; } } f(0.001)", 1388 " return 200; } else { return -200; } } f(0.001)",
1425 3 * kPointerSize, 1389 2 * kPointerSize,
1426 2, 1390 2,
1427 218, 1391 214,
1428 {B(LdaZero), // 1392 {
1429 B(Star), R(0), // 1393 #define X B(Ldar), R(0), B(Star), R(1), B(Ldar), R(1), B(Star), R(0)
1430 B(LdaZero), // 1394 B(LdaZero), //
1431 B(Star), R(1), // 1395 B(Star), R(0), //
1432 B(Ldar), R(0), // 1396 B(LdaZero), //
1433 B(Star), R(2), // 1397 B(Star), R(1), //
1434 B(LdaConstant), U8(0), // 1398 B(LdaConstant), U8(0), //
1435 B(TestEqualStrict), R(2), // 1399 B(TestEqualStrict), R(0), //
1436 B(JumpIfFalseConstant), U8(2), // 1400 B(JumpIfFalseConstant), U8(2), //
1437 #define X B(Ldar), R(0), B(Star), R(1), B(Ldar), R(1), B(Star), R(0), 1401 X, X, X, X, X, X, X, X, X, X, //
1438 X X X X X X X X X X X X X X X X X X X X X X X X 1402 X, X, X, X, X, X, X, X, X, X, //
1403 X, X, X, X, //
1404 B(LdaConstant), U8(1), //
1405 B(Return), //
1406 B(Jump), U8(5), //
1407 B(LdaConstant), U8(3), //
1408 B(Return), //
1409 B(LdaUndefined), //
1410 B(Return)}, //
1439 #undef X 1411 #undef X
1440 B(LdaConstant), U8(1), //
1441 B(Return), //
1442 B(Jump), U8(5), //
1443 B(LdaConstant), U8(3), //
1444 B(Return), //
1445 B(LdaUndefined), //
1446 B(Return)}, //
1447 4, 1412 4,
1448 {helper.factory()->NewHeapNumber(0.01), 1413 {helper.factory()->NewHeapNumber(0.01),
1449 helper.factory()->NewNumberFromInt(200), 1414 helper.factory()->NewNumberFromInt(200),
1450 helper.factory()->NewNumberFromInt(199), 1415 helper.factory()->NewNumberFromInt(199),
1451 helper.factory()->NewNumberFromInt(-200), 1416 helper.factory()->NewNumberFromInt(-200), unused, unused}},
1452 unused, unused}},
1453 {"function f(a, b) {\n" 1417 {"function f(a, b) {\n"
1454 " if (a == b) { return 1; }\n" 1418 " if (a == b) { return 1; }\n"
1455 " if (a === b) { return 1; }\n" 1419 " if (a === b) { return 1; }\n"
1456 " if (a < b) { return 1; }\n" 1420 " if (a < b) { return 1; }\n"
1457 " if (a > b) { return 1; }\n" 1421 " if (a > b) { return 1; }\n"
1458 " if (a <= b) { return 1; }\n" 1422 " if (a <= b) { return 1; }\n"
1459 " if (a >= b) { return 1; }\n" 1423 " if (a >= b) { return 1; }\n"
1460 " if (a in b) { return 1; }\n" 1424 " if (a in b) { return 1; }\n"
1461 " if (a instanceof b) { return 1; }\n" 1425 " if (a instanceof b) { return 1; }\n"
1462 " /* if (a != b) { return 1; } */" // TODO(oth) Ast visitor yields
1463 " /* if (a !== b) { return 1; } */" // UNARY NOT, rather than !=/!==.
1464 " return 0;\n" 1426 " return 0;\n"
1465 "} f(1, 1);", 1427 "} f(1, 1);",
1466 kPointerSize, 1428 0,
1467 3, 1429 3,
1468 106, 1430 74,
1469 { 1431 {
1470 #define IF_CONDITION_RETURN(condition) \ 1432 #define IF_CONDITION_RETURN(condition) \
1471 B(Ldar), R(helper.kLastParamIndex - 1), \ 1433 B(Ldar), A(2, 3), \
1472 B(Star), R(0), \ 1434 B(condition), A(1, 3), \
1473 B(Ldar), R(helper.kLastParamIndex), \ 1435 B(JumpIfFalse), U8(5), \
1474 B(condition), R(0), \ 1436 B(LdaSmi8), U8(1), \
1475 B(JumpIfFalse), U8(5), \ 1437 B(Return),
1476 B(LdaSmi8), U8(1), \
1477 B(Return),
1478 IF_CONDITION_RETURN(TestEqual) // 1438 IF_CONDITION_RETURN(TestEqual) //
1479 IF_CONDITION_RETURN(TestEqualStrict) // 1439 IF_CONDITION_RETURN(TestEqualStrict) //
1480 IF_CONDITION_RETURN(TestLessThan) // 1440 IF_CONDITION_RETURN(TestLessThan) //
1481 IF_CONDITION_RETURN(TestGreaterThan) // 1441 IF_CONDITION_RETURN(TestGreaterThan) //
1482 IF_CONDITION_RETURN(TestLessThanOrEqual) // 1442 IF_CONDITION_RETURN(TestLessThanOrEqual) //
1483 IF_CONDITION_RETURN(TestGreaterThanOrEqual) // 1443 IF_CONDITION_RETURN(TestGreaterThanOrEqual) //
1484 IF_CONDITION_RETURN(TestIn) // 1444 IF_CONDITION_RETURN(TestIn) //
1485 IF_CONDITION_RETURN(TestInstanceOf) // 1445 IF_CONDITION_RETURN(TestInstanceOf) //
1446 B(LdaZero), //
1447 B(Return)}, //
1486 #undef IF_CONDITION_RETURN 1448 #undef IF_CONDITION_RETURN
1487 B(LdaZero), //
1488 B(Return)}, //
1489 0, 1449 0,
1490 {unused, unused, unused, unused, unused, unused}}, 1450 {unused, unused, unused, unused, unused, unused}},
1491 }; 1451 };
1492 1452
1493 for (size_t i = 0; i < arraysize(snippets); i++) { 1453 for (size_t i = 0; i < arraysize(snippets); i++) {
1494 Handle<BytecodeArray> bytecode_array = 1454 Handle<BytecodeArray> bytecode_array =
1495 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 1455 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
1496 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1456 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1497 } 1457 }
1498 } 1458 }
1499 1459
1500 1460
1501 TEST(DeclareGlobals) { 1461 TEST(DeclareGlobals) {
1502 InitializedHandleScope handle_scope; 1462 InitializedHandleScope handle_scope;
1503 BytecodeGeneratorHelper helper; 1463 BytecodeGeneratorHelper helper;
1504 1464
1505 ExpectedSnippet<InstanceType> snippets[] = { 1465 ExpectedSnippet<InstanceType> snippets[] = {
1506 {"var a = 1;", 1466 {"var a = 1;",
1507 5 * kPointerSize, 1467 5 * kPointerSize,
1508 1, 1468 1,
1509 45, 1469 45,
1510 { 1470 {
1511 B(Ldar), R(Register::function_closure().index()), // 1471 B(Ldar), R(Register::function_closure().index()), //
1512 B(Star), R(2), // 1472 B(Star), R(2), //
1513 B(LdaConstant), U8(0), // 1473 B(LdaConstant), U8(0), //
1514 B(Star), R(3), // 1474 B(Star), R(3), //
1515 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // 1475 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), //
1516 B(PushContext), R(1), // 1476 B(PushContext), R(1), //
1517 B(LdaConstant), U8(1), // 1477 B(LdaConstant), U8(1), //
1518 B(Star), R(2), // 1478 B(Star), R(2), //
1519 B(LdaZero), // 1479 B(LdaZero), //
1520 B(Star), R(3), // 1480 B(Star), R(3), //
1521 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // 1481 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), //
1522 B(LdaConstant), U8(2), // 1482 B(LdaConstant), U8(2), //
1523 B(Star), R(2), // 1483 B(Star), R(2), //
1524 B(LdaZero), // 1484 B(LdaZero), //
1525 B(Star), R(3), // 1485 B(Star), R(3), //
1526 B(LdaSmi8), U8(1), // 1486 B(LdaSmi8), U8(1), //
1527 B(Star), R(4), // 1487 B(Star), R(4), //
1528 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), // 1488 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), U8(3), //
1529 U8(3), // 1489 B(LdaUndefined), //
1530 B(LdaUndefined), // 1490 B(Return), //
1531 B(Return) //
1532 }, 1491 },
1533 3, 1492 3,
1534 {InstanceType::FIXED_ARRAY_TYPE, 1493 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE,
1535 InstanceType::FIXED_ARRAY_TYPE,
1536 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, 1494 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
1537 {"function f() {}", 1495 {"function f() {}",
1538 3 * kPointerSize, 1496 3 * kPointerSize,
1539 1, 1497 1,
1540 29, 1498 29,
1541 { 1499 {
1542 B(Ldar), R(Register::function_closure().index()), // 1500 B(Ldar), R(Register::function_closure().index()), //
1543 B(Star), R(1), // 1501 B(Star), R(1), //
1544 B(LdaConstant), U8(0), // 1502 B(LdaConstant), U8(0), //
1545 B(Star), R(2), // 1503 B(Star), R(2), //
(...skipping 25 matching lines...) Expand all
1571 B(LdaZero), // 1529 B(LdaZero), //
1572 B(Star), R(3), // 1530 B(Star), R(3), //
1573 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // 1531 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), //
1574 B(LdaConstant), U8(2), // 1532 B(LdaConstant), U8(2), //
1575 B(Star), R(2), // 1533 B(Star), R(2), //
1576 B(LdaZero), // 1534 B(LdaZero), //
1577 B(Star), R(3), // 1535 B(Star), R(3), //
1578 B(LdaSmi8), U8(1), // 1536 B(LdaSmi8), U8(1), //
1579 B(Star), R(4), // 1537 B(Star), R(4), //
1580 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), // 1538 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), //
1581 U8(3), // 1539 U8(3), //
1582 B(LdaSmi8), U8(2), // 1540 B(LdaSmi8), U8(2), //
1583 B(StaGlobalSloppy), _, // 1541 B(StaGlobalSloppy), _, //
1584 B(Star), R(0), // 1542 B(Star), R(0), //
1585 B(Ldar), R(0), // 1543 B(Ldar), R(0), //
1586 B(Return) // 1544 B(Return) //
1587 }, 1545 },
1588 3, 1546 3,
1589 {InstanceType::FIXED_ARRAY_TYPE, 1547 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE,
1590 InstanceType::FIXED_ARRAY_TYPE,
1591 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, 1548 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
1592 {"function f() {}\nf();", 1549 {"function f() {}\nf();",
1593 4 * kPointerSize, 1550 4 * kPointerSize,
1594 1, 1551 1,
1595 43, 1552 43,
1596 { 1553 {
1597 B(Ldar), R(Register::function_closure().index()), // 1554 B(Ldar), R(Register::function_closure().index()), //
1598 B(Star), R(2), // 1555 B(Star), R(2), //
1599 B(LdaConstant), U8(0), // 1556 B(LdaConstant), U8(0), //
1600 B(Star), R(3), // 1557 B(Star), R(3), //
(...skipping 26 matching lines...) Expand all
1627 1584
1628 1585
1629 TEST(BasicLoops) { 1586 TEST(BasicLoops) {
1630 InitializedHandleScope handle_scope; 1587 InitializedHandleScope handle_scope;
1631 BytecodeGeneratorHelper helper; 1588 BytecodeGeneratorHelper helper;
1632 1589
1633 ExpectedSnippet<int> snippets[] = { 1590 ExpectedSnippet<int> snippets[] = {
1634 {"var x = 0;" 1591 {"var x = 0;"
1635 "var y = 1;" 1592 "var y = 1;"
1636 "while (x < 10) {" 1593 "while (x < 10) {"
1637 " y = y * 10;" 1594 " y = y * 12;"
1638 " x = x + 1;" 1595 " x = x + 1;"
1639 "}" 1596 "}"
1640 "return y;", 1597 "return y;",
1641 3 * kPointerSize, 1598 2 * kPointerSize,
1642 1, 1599 1,
1643 42, 1600 30,
1644 { 1601 {
1645 B(LdaZero), // 1602 B(LdaZero), //
1646 B(Star), R(0), // 1603 B(Star), R(0), //
1647 B(LdaSmi8), U8(1), // 1604 B(LdaSmi8), U8(1), //
1648 B(Star), R(1), // 1605 B(Star), R(1), //
1649 B(Jump), U8(22), // 1606 B(Jump), U8(14), //
1650 B(Ldar), R(1), // 1607 B(LdaSmi8), U8(12), //
1651 B(Star), R(2), // 1608 B(Mul), R(1), //
1609 B(Star), R(1), //
1610 B(LdaSmi8), U8(1), //
1611 B(Add), R(0), //
1612 B(Star), R(0), //
1652 B(LdaSmi8), U8(10), // 1613 B(LdaSmi8), U8(10), //
1653 B(Mul), R(2), // 1614 B(TestLessThan), R(0), //
1654 B(Star), R(1), // 1615 B(JumpIfTrue), U8(-16), //
1655 B(Ldar), R(0), //
1656 B(Star), R(2), //
1657 B(LdaSmi8), U8(1), //
1658 B(Add), R(2), //
1659 B(Star), R(0), //
1660 B(Ldar), R(0), //
1661 B(Star), R(2), //
1662 B(LdaSmi8), U8(10), //
1663 B(TestLessThan), R(2), //
1664 B(JumpIfTrue), U8(-28), //
1665 B(Ldar), R(1), // 1616 B(Ldar), R(1), //
1666 B(Return), // 1617 B(Return), //
1667 }, 1618 },
1668 0}, 1619 0},
1669 {"var i = 0;" 1620 {"var i = 0;"
1670 "while(true) {" 1621 "while(true) {"
1671 " if (i < 0) continue;" 1622 " if (i < 0) continue;"
1672 " if (i == 3) break;" 1623 " if (i == 3) break;"
1673 " if (i == 4) break;" 1624 " if (i == 4) break;"
1674 " if (i == 10) continue;" 1625 " if (i == 10) continue;"
1675 " if (i == 5) break;" 1626 " if (i == 5) break;"
1676 " i = i + 1;" 1627 " i = i + 1;"
1677 "}" 1628 "}"
1678 "return i;", 1629 "return i;",
1679 2 * kPointerSize, 1630 1 * kPointerSize,
1680 1, 1631 1,
1681 80, 1632 56,
1682 { 1633 {
1683 B(LdaZero), // 1634 B(LdaZero), //
1684 B(Star), R(0), // 1635 B(Star), R(0), //
1685 B(Jump), U8(71), // 1636 B(Jump), U8(47), //
1686 B(Ldar), R(0), //
1687 B(Star), R(1), //
1688 B(LdaZero), // 1637 B(LdaZero), //
1689 B(TestLessThan), R(1), // 1638 B(TestLessThan), R(0), //
1690 B(JumpIfFalse), U8(4), // 1639 B(JumpIfFalse), U8(4), //
1691 B(Jump), U8(60), // 1640 B(Jump), U8(40), //
1692 B(Ldar), R(0), //
1693 B(Star), R(1), //
1694 B(LdaSmi8), U8(3), // 1641 B(LdaSmi8), U8(3), //
1695 B(TestEqual), R(1), // 1642 B(TestEqual), R(0), //
1696 B(JumpIfFalse), U8(4), // 1643 B(JumpIfFalse), U8(4), //
1697 B(Jump), U8(51), // 1644 B(Jump), U8(35), //
1698 B(Ldar), R(0), //
1699 B(Star), R(1), //
1700 B(LdaSmi8), U8(4), // 1645 B(LdaSmi8), U8(4), //
1701 B(TestEqual), R(1), // 1646 B(TestEqual), R(0), //
1702 B(JumpIfFalse), U8(4), // 1647 B(JumpIfFalse), U8(4), //
1703 B(Jump), U8(39), // 1648 B(Jump), U8(27), //
1704 B(Ldar), R(0), //
1705 B(Star), R(1), //
1706 B(LdaSmi8), U8(10), // 1649 B(LdaSmi8), U8(10), //
1707 B(TestEqual), R(1), // 1650 B(TestEqual), R(0), //
1708 B(JumpIfFalse), U8(4), // 1651 B(JumpIfFalse), U8(4), //
1709 B(Jump), U8(24), // 1652 B(Jump), U8(16), //
1710 B(Ldar), R(0), //
1711 B(Star), R(1), //
1712 B(LdaSmi8), U8(5), // 1653 B(LdaSmi8), U8(5), //
1713 B(TestEqual), R(1), // 1654 B(TestEqual), R(0), //
1714 B(JumpIfFalse), U8(4), // 1655 B(JumpIfFalse), U8(4), //
1715 B(Jump), U8(15), // 1656 B(Jump), U8(11), //
1716 B(Ldar), R(0), //
1717 B(Star), R(1), //
1718 B(LdaSmi8), U8(1), // 1657 B(LdaSmi8), U8(1), //
1719 B(Add), R(1), // 1658 B(Add), R(0), //
1720 B(Star), R(0), // 1659 B(Star), R(0), //
1721 B(LdaTrue), // 1660 B(LdaTrue), //
1722 B(JumpIfTrue), U8(-70), // 1661 B(JumpIfTrue), U8(-46), //
1723 B(Ldar), R(0), // 1662 B(Ldar), R(0), //
1724 B(Return) // 1663 B(Return), //
1725 }, 1664 },
1726 0}, 1665 0},
1727 {"var x = 0; var y = 1;" 1666 {"var x = 0; var y = 1;"
1728 "do {" 1667 "do {"
1729 " y = y * 10;" 1668 " y = y * 10;"
1730 " if (x == 5) break;" 1669 " if (x == 5) break;"
1731 " if (x == 6) continue;" 1670 " if (x == 6) continue;"
1732 " x = x + 1;" 1671 " x = x + 1;"
1733 "} while (x < 10);" 1672 "} while (x < 10);"
1734 "return y;", 1673 "return y;",
1735 3 * kPointerSize, 1674 2 * kPointerSize,
1736 1, 1675 1,
1737 64, 1676 44,
1738 { 1677 {
1739 B(LdaZero), // 1678 B(LdaZero), //
1740 B(Star), R(0), // 1679 B(Star), R(0), //
1741 B(LdaSmi8), U8(1), // 1680 B(LdaSmi8), U8(1), //
1742 B(Star), R(1), // 1681 B(Star), R(1), //
1682 B(LdaSmi8), U8(10), //
1683 B(Mul), R(1), //
1684 B(Star), R(1), //
1685 B(LdaSmi8), U8(5), //
1686 B(TestEqual), R(0), //
1687 B(JumpIfFalse), U8(4), //
1688 B(Jump), U8(22), //
1689 B(LdaSmi8), U8(6), //
1690 B(TestEqual), R(0), //
1691 B(JumpIfFalse), U8(4), //
1692 B(Jump), U8(8), //
1693 B(LdaSmi8), U8(1), //
1694 B(Add), R(0), //
1695 B(Star), R(0), //
1696 B(LdaSmi8), U8(10), //
1697 B(TestLessThan), R(0), //
1698 B(JumpIfTrue), U8(-32), //
1743 B(Ldar), R(1), // 1699 B(Ldar), R(1), //
1744 B(Star), R(2), // 1700 B(Return), //
1745 B(LdaSmi8), U8(10), //
1746 B(Mul), R(2), //
1747 B(Star), R(1), //
1748 B(Ldar), R(0), //
1749 B(Star), R(2), //
1750 B(LdaSmi8), U8(5), //
1751 B(TestEqual), R(2), //
1752 B(JumpIfFalse), U8(4), //
1753 B(Jump), U8(34), //
1754 B(Ldar), R(0), //
1755 B(Star), R(2), //
1756 B(LdaSmi8), U8(6), //
1757 B(TestEqual), R(2), //
1758 B(JumpIfFalse), U8(4), //
1759 B(Jump), U8(12), //
1760 B(Ldar), R(0), //
1761 B(Star), R(2), //
1762 B(LdaSmi8), U8(1), //
1763 B(Add), R(2), //
1764 B(Star), R(0), //
1765 B(Ldar), R(0), //
1766 B(Star), R(2), //
1767 B(LdaSmi8), U8(10), //
1768 B(TestLessThan), R(2), //
1769 B(JumpIfTrue), U8(-52), //
1770 B(Ldar), R(1), //
1771 B(Return) //
1772 }, 1701 },
1773 0}, 1702 0},
1774 {"var x = 0; " 1703 {"var x = 0; "
1775 "for(;;) {" 1704 "for(;;) {"
1776 " if (x == 1) break;" 1705 " if (x == 1) break;"
1777 " x = x + 1;" 1706 " x = x + 1;"
1778 "}", 1707 "}",
1779 2 * kPointerSize, 1708 1 * kPointerSize,
1780 1, 1709 1,
1781 29, 1710 21,
1782 { 1711 {
1783 B(LdaZero), // 1712 B(LdaZero), //
1784 B(Star), R(0), // 1713 B(Star), R(0), //
1785 B(Ldar), R(0), //
1786 B(Star), R(1), //
1787 B(LdaSmi8), U8(1), // 1714 B(LdaSmi8), U8(1), //
1788 B(TestEqual), R(1), // 1715 B(TestEqual), R(0), //
1789 B(JumpIfFalse), U8(4), // 1716 B(JumpIfFalse), U8(4), //
1790 B(Jump), U8(14), // 1717 B(Jump), U8(10), //
1791 B(Ldar), R(0), //
1792 B(Star), R(1), //
1793 B(LdaSmi8), U8(1), // 1718 B(LdaSmi8), U8(1), //
1794 B(Add), R(1), // 1719 B(Add), R(0), //
1795 B(Star), R(0), // 1720 B(Star), R(0), //
1796 B(Jump), U8(-22), // 1721 B(Jump), U8(-14), //
1797 B(LdaUndefined), // 1722 B(LdaUndefined), //
1798 B(Return), // 1723 B(Return), //
1799 }, 1724 },
1800 0}, 1725 0},
1801 {"var u = 0;" 1726 {"var u = 0;"
1802 "for(var i = 0; i < 100; i = i + 1) {" 1727 "for(var i = 0; i < 100; i = i + 1) {"
1803 " u = u + 1;" 1728 " u = u + 1;"
1804 " continue;" 1729 " continue;"
1805 "}", 1730 "}",
1806 3 * kPointerSize, 1731 2 * kPointerSize,
1807 1, 1732 1,
1808 42, 1733 30,
1809 { 1734 {
1810 B(LdaZero), // 1735 B(LdaZero), //
1811 B(Star), R(0), // 1736 B(Star), R(0), //
1812 B(LdaZero), // 1737 B(LdaZero), //
1813 B(Star), R(1), // 1738 B(Star), R(1), //
1814 B(Jump), U8(24), // 1739 B(Jump), U8(16), //
1815 B(Ldar), R(0), //
1816 B(Star), R(2), //
1817 B(LdaSmi8), U8(1), // 1740 B(LdaSmi8), U8(1), //
1818 B(Add), R(2), // 1741 B(Add), R(0), //
1819 B(Star), R(0), // 1742 B(Star), R(0), //
1820 B(Jump), U8(2), // 1743 B(Jump), U8(2), //
1821 B(Ldar), R(1), //
1822 B(Star), R(2), //
1823 B(LdaSmi8), U8(1), // 1744 B(LdaSmi8), U8(1), //
1824 B(Add), R(2), // 1745 B(Add), R(1), //
1825 B(Star), R(1), // 1746 B(Star), R(1), //
1826 B(Ldar), R(1), //
1827 B(Star), R(2), //
1828 B(LdaSmi8), U8(100), // 1747 B(LdaSmi8), U8(100), //
1829 B(TestLessThan), R(2), // 1748 B(TestLessThan), R(1), //
1830 B(JumpIfTrue), U8(-30), // 1749 B(JumpIfTrue), U8(-18), //
1831 B(LdaUndefined), // 1750 B(LdaUndefined), //
1832 B(Return), // 1751 B(Return), //
1833 }, 1752 },
1834 0}, 1753 0},
1835 {"var i = 0;" 1754 {"var i = 0;"
1836 "while(true) {" 1755 "while(true) {"
1837 " while (i < 3) {" 1756 " while (i < 3) {"
1838 " if (i == 2) break;" 1757 " if (i == 2) break;"
1839 " i = i + 1;" 1758 " i = i + 1;"
1840 " }" 1759 " }"
1841 " i = i + 1;" 1760 " i = i + 1;"
1842 " break;" 1761 " break;"
1843 "}" 1762 "}"
1844 "return i;", 1763 "return i;",
1845 2 * kPointerSize, 1764 1 * kPointerSize,
1846 1, 1765 1,
1847 57, 1766 41,
1848 { 1767 {
1849 B(LdaZero), // 1768 B(LdaZero), //
1850 B(Star), R(0), // 1769 B(Star), R(0), //
1851 B(Jump), U8(48), // 1770 B(Jump), U8(32), //
1852 B(Jump), U8(24), // 1771 B(Jump), U8(16), //
1853 B(Ldar), R(0), //
1854 B(Star), R(1), //
1855 B(LdaSmi8), U8(2), // 1772 B(LdaSmi8), U8(2), //
1856 B(TestEqual), R(1), // 1773 B(TestEqual), R(0), //
1857 B(JumpIfFalse), U8(4), // 1774 B(JumpIfFalse), U8(4), //
1858 B(Jump), U8(22), // 1775 B(Jump), U8(14), //
1859 B(Ldar), R(0), //
1860 B(Star), R(1), //
1861 B(LdaSmi8), U8(1), // 1776 B(LdaSmi8), U8(1), //
1862 B(Add), R(1), // 1777 B(Add), R(0), //
1863 B(Star), R(0), // 1778 B(Star), R(0), //
1864 B(Ldar), R(0), //
1865 B(Star), R(1), //
1866 B(LdaSmi8), U8(3), // 1779 B(LdaSmi8), U8(3), //
1867 B(TestLessThan), R(1), // 1780 B(TestLessThan), R(0), //
1868 B(JumpIfTrue), U8(-30), // 1781 B(JumpIfTrue), U8(-18), //
1869 B(Ldar), R(0), //
1870 B(Star), R(1), //
1871 B(LdaSmi8), U8(1), // 1782 B(LdaSmi8), U8(1), //
1872 B(Add), R(1), // 1783 B(Add), R(0), //
1873 B(Star), R(0), // 1784 B(Star), R(0), //
1874 B(Jump), U8(5), // 1785 B(Jump), U8(5), //
1875 B(LdaTrue), // 1786 B(LdaTrue), //
1876 B(JumpIfTrue), U8(-47), // 1787 B(JumpIfTrue), U8(-31), //
1877 B(Ldar), R(0), // 1788 B(Ldar), R(0), //
1878 B(Return), // 1789 B(Return), //
1879 }, 1790 },
1880 0}, 1791 0},
1881 }; 1792 };
1882 1793
1883 for (size_t i = 0; i < arraysize(snippets); i++) { 1794 for (size_t i = 0; i < arraysize(snippets); i++) {
1884 Handle<BytecodeArray> bytecode_array = 1795 Handle<BytecodeArray> bytecode_array =
1885 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 1796 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
1886 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1797 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1887 } 1798 }
1888 } 1799 }
1889 1800
1890 1801
1891 TEST(UnaryOperators) { 1802 TEST(UnaryOperators) {
1892 InitializedHandleScope handle_scope; 1803 InitializedHandleScope handle_scope;
1893 BytecodeGeneratorHelper helper; 1804 BytecodeGeneratorHelper helper;
1894 1805
1895 ExpectedSnippet<int> snippets[] = { 1806 ExpectedSnippet<int> snippets[] = {
1896 {"var x = 0;" 1807 {"var x = 0;"
1897 "while (x != 10) {" 1808 "while (x != 10) {"
1898 " x = x + 10;" 1809 " x = x + 10;"
1899 "}" 1810 "}"
1900 "return x;", 1811 "return x;",
1901 2 * kPointerSize, 1812 kPointerSize,
1902 1, 1813 1,
1903 29, 1814 21,
1904 { 1815 {
1905 B(LdaZero), // 1816 B(LdaZero), //
1906 B(Star), R(0), // 1817 B(Star), R(0), //
1907 B(Jump), U8(12), // 1818 B(Jump), U8(8), //
1908 B(Ldar), R(0), //
1909 B(Star), R(1), //
1910 B(LdaSmi8), U8(10), // 1819 B(LdaSmi8), U8(10), //
1911 B(Add), R(1), // 1820 B(Add), R(0), //
1912 B(Star), R(0), // 1821 B(Star), R(0), //
1913 B(Ldar), R(0), //
1914 B(Star), R(1), //
1915 B(LdaSmi8), U8(10), // 1822 B(LdaSmi8), U8(10), //
1916 B(TestEqual), R(1), // 1823 B(TestEqual), R(0), //
1917 B(LogicalNot), // 1824 B(LogicalNot), //
1918 B(JumpIfTrue), U8(-19), // 1825 B(JumpIfTrue), U8(-11), //
1919 B(Ldar), R(0), // 1826 B(Ldar), R(0), //
1920 B(Return), // 1827 B(Return), //
1921 }, 1828 },
1922 0}, 1829 0},
1923 {"var x = false;" 1830 {"var x = false;"
1924 "do {" 1831 "do {"
1925 " x = !x;" 1832 " x = !x;"
1926 "} while(x == false);" 1833 "} while(x == false);"
1927 "return x;", 1834 "return x;",
1928 2 * kPointerSize, 1835 kPointerSize,
1929 1, 1836 1,
1930 20, 1837 16,
1931 { 1838 {
1932 B(LdaFalse), // 1839 B(LdaFalse), //
1933 B(Star), R(0), // 1840 B(Star), R(0), //
1934 B(Ldar), R(0), // 1841 B(Ldar), R(0), //
1935 B(LogicalNot), // 1842 B(LogicalNot), //
1936 B(Star), R(0), // 1843 B(Star), R(0), //
1937 B(Ldar), R(0), // 1844 B(LdaFalse), //
1938 B(Star), R(1), // 1845 B(TestEqual), R(0), //
1939 B(LdaFalse), // 1846 B(JumpIfTrue), U8(-8), //
1940 B(TestEqual), R(1), // 1847 B(Ldar), R(0), //
1941 B(JumpIfTrue), U8(-12), // 1848 B(Return), //
1942 B(Ldar), R(0), //
1943 B(Return), //
1944 }, 1849 },
1945 0}, 1850 0},
1946 {"var x = 101;" 1851 {"var x = 101;"
1947 "return void(x * 3);", 1852 "return void(x * 3);",
1948 2 * kPointerSize, 1853 kPointerSize,
1949 1, 1854 1,
1950 14, 1855 10,
1951 { 1856 {
1952 B(LdaSmi8), U8(101), // 1857 B(LdaSmi8), U8(101), //
1953 B(Star), R(0), // 1858 B(Star), R(0), //
1954 B(Ldar), R(0), //
1955 B(Star), R(1), //
1956 B(LdaSmi8), U8(3), // 1859 B(LdaSmi8), U8(3), //
1957 B(Mul), R(1), // 1860 B(Mul), R(0), //
1958 B(LdaUndefined), // 1861 B(LdaUndefined), //
1959 B(Return), // 1862 B(Return), //
1960 }, 1863 },
1961 0}, 1864 0},
1962 {"var x = 1234;" 1865 {"var x = 1234;"
1963 "var y = void (x * x - 1);" 1866 "var y = void (x * x - 1);"
1964 "return y;", 1867 "return y;",
1965 4 * kPointerSize, 1868 3 * kPointerSize,
1966 1, 1869 1,
1967 24, 1870 20,
1968 { 1871 {
1969 B(LdaConstant), U8(0), // 1872 B(LdaConstant), U8(0), //
1970 B(Star), R(0), // 1873 B(Star), R(0), //
1971 B(Ldar), R(0), // 1874 B(Ldar), R(0), //
1972 B(Star), R(3), // 1875 B(Mul), R(0), //
1973 B(Ldar), R(0), //
1974 B(Mul), R(3), //
1975 B(Star), R(2), // 1876 B(Star), R(2), //
1976 B(LdaSmi8), U8(1), // 1877 B(LdaSmi8), U8(1), //
1977 B(Sub), R(2), // 1878 B(Sub), R(2), //
1978 B(LdaUndefined), // 1879 B(LdaUndefined), //
1979 B(Star), R(1), // 1880 B(Star), R(1), //
1980 B(Ldar), R(1), // 1881 B(Ldar), R(1), //
1981 B(Return), // 1882 B(Return), //
1982 }, 1883 },
1983 1, 1884 1,
1984 {1234}}, 1885 {1234}},
1985 {"var x = 13;" 1886 {"var x = 13;"
1986 "return typeof(x);", 1887 "return typeof(x);",
1987 1 * kPointerSize, 1888 kPointerSize,
1988 1, 1889 1,
1989 8, 1890 8,
1990 { 1891 {
1991 B(LdaSmi8), U8(13), // 1892 B(LdaSmi8), U8(13), //
1992 B(Star), R(0), // 1893 B(Star), R(0), //
1993 B(Ldar), R(0), // 1894 B(Ldar), R(0), // TODO(oth): Ldar R(X) following Star R(X)
1994 B(TypeOf), // 1895 B(TypeOf), // could be culled in bytecode array builder.
rmcilroy 2015/10/19 12:56:23 nit - move comment up one line (on Star and Ldar)
oth 2015/10/20 15:28:53 Done.
1995 B(Return), // 1896 B(Return), //
1996 }, 1897 },
1997 0}, 1898 0},
1998 }; 1899 };
1999 1900
2000 for (size_t i = 0; i < arraysize(snippets); i++) { 1901 for (size_t i = 0; i < arraysize(snippets); i++) {
2001 Handle<BytecodeArray> bytecode_array = 1902 Handle<BytecodeArray> bytecode_array =
2002 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 1903 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2003 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1904 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2004 } 1905 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2154 1, 2055 1,
2155 6, 2056 6,
2156 { 2057 {
2157 B(LdaConstant), U8(0), // 2058 B(LdaConstant), U8(0), //
2158 B(CreateArrayLiteral), U8(0), U8(simple_flags), // 2059 B(CreateArrayLiteral), U8(0), U8(simple_flags), //
2159 B(Return) // 2060 B(Return) //
2160 }, 2061 },
2161 1, 2062 1,
2162 {InstanceType::FIXED_ARRAY_TYPE}}, 2063 {InstanceType::FIXED_ARRAY_TYPE}},
2163 {"var a = 1; return [ a, a + 1 ];", 2064 {"var a = 1; return [ a, a + 1 ];",
2164 4 * kPointerSize, 2065 3 * kPointerSize,
2165 1, 2066 1,
2166 39, 2067 35,
2167 { 2068 {
2168 B(LdaSmi8), U8(1), // 2069 B(LdaSmi8), U8(1), //
2169 B(Star), R(0), // 2070 B(Star), R(0), //
2170 B(LdaConstant), U8(0), // 2071 B(LdaConstant), U8(0), //
2171 B(CreateArrayLiteral), U8(0), U8(3), // 2072 B(CreateArrayLiteral), U8(0), U8(3), //
2172 B(Star), R(2), // 2073 B(Star), R(2), //
2173 B(LdaZero), // 2074 B(LdaZero), //
2174 B(Star), R(1), // 2075 B(Star), R(1), //
2175 B(Ldar), R(0), // 2076 B(Ldar), R(0), //
2176 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot1)), // 2077 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot1)), //
2177 B(LdaSmi8), U8(1), // 2078 B(LdaSmi8), U8(1), //
2178 B(Star), R(1), // 2079 B(Star), R(1), //
2179 B(Ldar), R(0), //
2180 B(Star), R(3), //
2181 B(LdaSmi8), U8(1), // 2080 B(LdaSmi8), U8(1), //
2182 B(Add), R(3), // 2081 B(Add), R(0), //
2183 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot1)), // 2082 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot1)), //
2184 B(Ldar), R(2), // 2083 B(Ldar), R(2), //
2185 B(Return) // 2084 B(Return), //
2186 }, 2085 },
2187 1, 2086 1,
2188 {InstanceType::FIXED_ARRAY_TYPE}}, 2087 {InstanceType::FIXED_ARRAY_TYPE}},
2189 {"return [ [ 1, 2 ], [ 3 ] ];", 2088 {"return [ [ 1, 2 ], [ 3 ] ];",
2190 0, 2089 0,
2191 1, 2090 1,
2192 6, 2091 6,
2193 { 2092 {
2194 B(LdaConstant), U8(0), // 2093 B(LdaConstant), U8(0), //
2195 B(CreateArrayLiteral), U8(2), U8(deep_elements_flags), // 2094 B(CreateArrayLiteral), U8(2), U8(deep_elements_flags), //
2196 B(Return) // 2095 B(Return) //
2197 }, 2096 },
2198 1, 2097 1,
2199 {InstanceType::FIXED_ARRAY_TYPE}}, 2098 {InstanceType::FIXED_ARRAY_TYPE}},
2200 {"var a = 1; return [ [ a, 2 ], [ a + 2 ] ];", 2099 {"var a = 1; return [ [ a, 2 ], [ a + 2 ] ];",
2201 6 * kPointerSize, 2100 5 * kPointerSize,
2202 1, 2101 1,
2203 71, 2102 67,
2204 { 2103 {
2205 B(LdaSmi8), U8(1), // 2104 B(LdaSmi8), U8(1), //
2206 B(Star), R(0), // 2105 B(Star), R(0), //
2207 B(LdaConstant), U8(0), // 2106 B(LdaConstant), U8(0), //
2208 B(CreateArrayLiteral), U8(2), U8(deep_elements_flags), // 2107 B(CreateArrayLiteral), U8(2), U8(deep_elements_flags), //
2209 B(Star), R(2), // 2108 B(Star), R(2), //
2210 B(LdaZero), // 2109 B(LdaZero), //
2211 B(Star), R(1), // 2110 B(Star), R(1), //
2212 B(LdaConstant), U8(1), // 2111 B(LdaConstant), U8(1), //
2213 B(CreateArrayLiteral), U8(0), U8(simple_flags), // 2112 B(CreateArrayLiteral), U8(0), U8(simple_flags), //
2214 B(Star), R(4), // 2113 B(Star), R(4), //
2215 B(LdaZero), // 2114 B(LdaZero), //
2216 B(Star), R(3), // 2115 B(Star), R(3), //
2217 B(Ldar), R(0), // 2116 B(Ldar), R(0), //
2218 B(KeyedStoreICSloppy), R(4), R(3), U8(vector->GetIndex(slot1)), // 2117 B(KeyedStoreICSloppy), R(4), R(3), U8(vector->GetIndex(slot1)), //
2219 B(Ldar), R(4), // 2118 B(Ldar), R(4), //
2220 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot3)), // 2119 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot3)), //
2221 B(LdaSmi8), U8(1), // 2120 B(LdaSmi8), U8(1), //
2222 B(Star), R(1), // 2121 B(Star), R(1), //
2223 B(LdaConstant), U8(2), // 2122 B(LdaConstant), U8(2), //
2224 B(CreateArrayLiteral), U8(1), U8(simple_flags), // 2123 B(CreateArrayLiteral), U8(1), U8(simple_flags), //
2225 B(Star), R(4), // 2124 B(Star), R(4), //
2226 B(LdaZero), // 2125 B(LdaZero), //
2227 B(Star), R(3), // 2126 B(Star), R(3), //
2228 B(Ldar), R(0), //
2229 B(Star), R(5), //
2230 B(LdaSmi8), U8(2), // 2127 B(LdaSmi8), U8(2), //
2231 B(Add), R(5), // 2128 B(Add), R(0), //
2232 B(KeyedStoreICSloppy), R(4), R(3), U8(vector->GetIndex(slot2)), // 2129 B(KeyedStoreICSloppy), R(4), R(3), U8(vector->GetIndex(slot2)), //
2233 B(Ldar), R(4), // 2130 B(Ldar), R(4), //
2234 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot3)), // 2131 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot3)), //
2235 B(Ldar), R(2), // 2132 B(Ldar), R(2), //
2236 B(Return), // 2133 B(Return), //
2237 }, 2134 },
2238 3, 2135 3,
2239 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE, 2136 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE,
2240 InstanceType::FIXED_ARRAY_TYPE}}, 2137 InstanceType::FIXED_ARRAY_TYPE}},
2241 }; 2138 };
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2294 B(Star), R(2), // 2191 B(Star), R(2), //
2295 B(Ldar), R(0), // 2192 B(Ldar), R(0), //
2296 B(StoreICSloppy), R(1), R(2), U8(3), // 2193 B(StoreICSloppy), R(1), R(2), U8(3), //
2297 B(Ldar), R(1), // 2194 B(Ldar), R(1), //
2298 B(Return), // 2195 B(Return), //
2299 }, 2196 },
2300 2, 2197 2,
2301 {InstanceType::FIXED_ARRAY_TYPE, 2198 {InstanceType::FIXED_ARRAY_TYPE,
2302 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, 2199 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2303 {"var a = 1; return { val: a, val: a + 1 };", 2200 {"var a = 1; return { val: a, val: a + 1 };",
2304 4 * kPointerSize, 2201 3 * kPointerSize,
2305 1, 2202 1,
2306 32, 2203 28,
2307 { 2204 {
2308 B(LdaSmi8), U8(1), // 2205 B(LdaSmi8), U8(1), //
2309 B(Star), R(0), // 2206 B(Star), R(0), //
2310 B(LdaConstant), U8(0), // 2207 B(LdaConstant), U8(0), //
2311 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // 2208 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2312 B(Star), R(1), // 2209 B(Star), R(1), //
2313 B(Ldar), R(0), // 2210 B(Ldar), R(0), //
2314 B(LdaConstant), U8(1), // 2211 B(LdaConstant), U8(1), //
2315 B(Star), R(2), // 2212 B(Star), R(2), //
2316 B(Ldar), R(0), //
2317 B(Star), R(3), //
2318 B(LdaSmi8), U8(1), // 2213 B(LdaSmi8), U8(1), //
2319 B(Add), R(3), // 2214 B(Add), R(0), //
2320 B(StoreICSloppy), R(1), R(2), U8(3), // 2215 B(StoreICSloppy), R(1), R(2), U8(3), //
2321 B(Ldar), R(1), // 2216 B(Ldar), R(1), //
2322 B(Return), // 2217 B(Return), //
2323 }, 2218 },
2324 2, 2219 2,
2325 {InstanceType::FIXED_ARRAY_TYPE, 2220 {InstanceType::FIXED_ARRAY_TYPE,
2326 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, 2221 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2327 {"return { func: function() { } };", 2222 {"return { func: function() { } };",
2328 2 * kPointerSize, 2223 2 * kPointerSize,
2329 1, 2224 1,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2375 B(LdaConstant), U8(1), // 2270 B(LdaConstant), U8(1), //
2376 B(Star), R(1), // 2271 B(Star), R(1), //
2377 B(LdaConstant), U8(2), // 2272 B(LdaConstant), U8(2), //
2378 B(CreateClosure), U8(0), // 2273 B(CreateClosure), U8(0), //
2379 B(Star), R(2), // 2274 B(Star), R(2), //
2380 B(LdaNull), // 2275 B(LdaNull), //
2381 B(Star), R(3), // 2276 B(Star), R(3), //
2382 B(LdaZero), // 2277 B(LdaZero), //
2383 B(Star), R(4), // 2278 B(Star), R(4), //
2384 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // 2279 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), //
2385 R(0), U8(5), // 2280 R(0), U8(5), //
2386 B(Ldar), R(0), // 2281 B(Ldar), R(0), //
2387 B(Return), // 2282 B(Return), //
2388 }, 2283 },
2389 3, 2284 3,
2390 {InstanceType::FIXED_ARRAY_TYPE, 2285 {InstanceType::FIXED_ARRAY_TYPE,
2391 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2286 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2392 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2287 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2393 {"return { get a() { return this.x; }, set a(val) { this.x = val } };", 2288 {"return { get a() { return this.x; }, set a(val) { this.x = val } };",
2394 5 * kPointerSize, 2289 5 * kPointerSize,
2395 1, 2290 1,
2396 34, 2291 34,
2397 { 2292 {
2398 B(LdaConstant), U8(0), // 2293 B(LdaConstant), U8(0), //
2399 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // 2294 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2400 B(Star), R(0), // 2295 B(Star), R(0), //
2401 B(LdaConstant), U8(1), // 2296 B(LdaConstant), U8(1), //
2402 B(Star), R(1), // 2297 B(Star), R(1), //
2403 B(LdaConstant), U8(2), // 2298 B(LdaConstant), U8(2), //
2404 B(CreateClosure), U8(0), // 2299 B(CreateClosure), U8(0), //
2405 B(Star), R(2), // 2300 B(Star), R(2), //
2406 B(LdaConstant), U8(3), // 2301 B(LdaConstant), U8(3), //
2407 B(CreateClosure), U8(0), // 2302 B(CreateClosure), U8(0), //
2408 B(Star), R(3), // 2303 B(Star), R(3), //
2409 B(LdaZero), // 2304 B(LdaZero), //
2410 B(Star), R(4), // 2305 B(Star), R(4), //
2411 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // 2306 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), //
2412 R(0), U8(5), // 2307 R(0), U8(5), //
2413 B(Ldar), R(0), // 2308 B(Ldar), R(0), //
2414 B(Return), // 2309 B(Return), //
2415 }, 2310 },
2416 4, 2311 4,
2417 {InstanceType::FIXED_ARRAY_TYPE, 2312 {InstanceType::FIXED_ARRAY_TYPE,
2418 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2313 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2419 InstanceType::SHARED_FUNCTION_INFO_TYPE, 2314 InstanceType::SHARED_FUNCTION_INFO_TYPE,
2420 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2315 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2421 {"return { set b(val) { this.y = val } };", 2316 {"return { set b(val) { this.y = val } };",
2422 5 * kPointerSize, 2317 5 * kPointerSize,
2423 1, 2318 1,
2424 31, 2319 31,
2425 { 2320 {
2426 B(LdaConstant), U8(0), // 2321 B(LdaConstant), U8(0), //
2427 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // 2322 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2428 B(Star), R(0), // 2323 B(Star), R(0), //
2429 B(LdaConstant), U8(1), // 2324 B(LdaConstant), U8(1), //
2430 B(Star), R(1), // 2325 B(Star), R(1), //
2431 B(LdaNull), // 2326 B(LdaNull), //
2432 B(Star), R(2), // 2327 B(Star), R(2), //
2433 B(LdaConstant), U8(2), // 2328 B(LdaConstant), U8(2), //
2434 B(CreateClosure), U8(0), // 2329 B(CreateClosure), U8(0), //
2435 B(Star), R(3), // 2330 B(Star), R(3), //
2436 B(LdaZero), // 2331 B(LdaZero), //
2437 B(Star), R(4), // 2332 B(Star), R(4), //
2438 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // 2333 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), //
2439 R(0), U8(5), // 2334 R(0), U8(5), //
2440 B(Ldar), R(0), // 2335 B(Ldar), R(0), //
2441 B(Return), // 2336 B(Return), //
2442 }, 2337 },
2443 3, 2338 3,
2444 {InstanceType::FIXED_ARRAY_TYPE, 2339 {InstanceType::FIXED_ARRAY_TYPE,
2445 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2340 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2446 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2341 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2447 {"var a = 1; return { 1: a };", 2342 {"var a = 1; return { 1: a };",
2448 5 * kPointerSize, 2343 5 * kPointerSize,
2449 1, 2344 1,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 B(CreateObjectLiteral), U8(0), U8(simple_flags), // 2387 B(CreateObjectLiteral), U8(0), U8(simple_flags), //
2493 B(Star), R(1), // 2388 B(Star), R(1), //
2494 B(Ldar), R(0), // 2389 B(Ldar), R(0), //
2495 B(ToName), // 2390 B(ToName), //
2496 B(Star), R(2), // 2391 B(Star), R(2), //
2497 B(LdaSmi8), U8(1), // 2392 B(LdaSmi8), U8(1), //
2498 B(Star), R(3), // 2393 B(Star), R(3), //
2499 B(LdaZero), // 2394 B(LdaZero), //
2500 B(Star), R(4), // 2395 B(Star), R(4), //
2501 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), // 2396 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
2502 U8(4), // 2397 U8(4), //
2503 B(Ldar), R(1), // 2398 B(Ldar), R(1), //
2504 B(Return), // 2399 B(Return), //
2505 }, 2400 },
2506 2, 2401 2,
2507 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2402 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2508 InstanceType::FIXED_ARRAY_TYPE}}, 2403 InstanceType::FIXED_ARRAY_TYPE}},
2509 {"var a = 'test'; return { val: a, [a]: 1 }", 2404 {"var a = 'test'; return { val: a, [a]: 1 }",
2510 5 * kPointerSize, 2405 5 * kPointerSize,
2511 1, 2406 1,
2512 41, 2407 41,
2513 { 2408 {
2514 B(LdaConstant), U8(0), // 2409 B(LdaConstant), U8(0), //
2515 B(Star), R(0), // 2410 B(Star), R(0), //
2516 B(LdaConstant), U8(1), // 2411 B(LdaConstant), U8(1), //
2517 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // 2412 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
2518 B(Star), R(1), // 2413 B(Star), R(1), //
2519 B(LdaConstant), U8(2), // 2414 B(LdaConstant), U8(2), //
2520 B(Star), R(2), // 2415 B(Star), R(2), //
2521 B(Ldar), R(0), // 2416 B(Ldar), R(0), //
2522 B(StoreICSloppy), R(1), R(2), U8(3), // 2417 B(StoreICSloppy), R(1), R(2), U8(3), //
2523 B(Ldar), R(0), // 2418 B(Ldar), R(0), //
2524 B(ToName), // 2419 B(ToName), //
2525 B(Star), R(2), // 2420 B(Star), R(2), //
2526 B(LdaSmi8), U8(1), // 2421 B(LdaSmi8), U8(1), //
2527 B(Star), R(3), // 2422 B(Star), R(3), //
2528 B(LdaZero), // 2423 B(LdaZero), //
2529 B(Star), R(4), // 2424 B(Star), R(4), //
2530 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), // 2425 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
2531 U8(4), // 2426 U8(4), //
2532 B(Ldar), R(1), // 2427 B(Ldar), R(1), //
2533 B(Return), // 2428 B(Return), //
2534 }, 2429 },
2535 3, 2430 3,
2536 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2431 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2537 InstanceType::FIXED_ARRAY_TYPE, 2432 InstanceType::FIXED_ARRAY_TYPE,
2538 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, 2433 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2539 {"var a = 'test'; return { [a]: 1, __proto__: {} }", 2434 {"var a = 'test'; return { [a]: 1, __proto__: {} }",
2540 5 * kPointerSize, 2435 5 * kPointerSize,
2541 1, 2436 1,
2542 43, 2437 43,
2543 { 2438 {
2544 B(LdaConstant), U8(0), // 2439 B(LdaConstant), U8(0), //
2545 B(Star), R(0), // 2440 B(Star), R(0), //
2546 B(LdaConstant), U8(1), // 2441 B(LdaConstant), U8(1), //
2547 B(CreateObjectLiteral), U8(1), U8(simple_flags), // 2442 B(CreateObjectLiteral), U8(1), U8(simple_flags), //
2548 B(Star), R(1), // 2443 B(Star), R(1), //
2549 B(Ldar), R(0), // 2444 B(Ldar), R(0), //
2550 B(ToName), // 2445 B(ToName), //
2551 B(Star), R(2), // 2446 B(Star), R(2), //
2552 B(LdaSmi8), U8(1), // 2447 B(LdaSmi8), U8(1), //
2553 B(Star), R(3), // 2448 B(Star), R(3), //
2554 B(LdaZero), // 2449 B(LdaZero), //
2555 B(Star), R(4), // 2450 B(Star), R(4), //
2556 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), // 2451 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
2557 U8(4), // 2452 U8(4), //
2558 B(LdaConstant), U8(1), // 2453 B(LdaConstant), U8(1), //
2559 B(CreateObjectLiteral), U8(0), U8(13), // 2454 B(CreateObjectLiteral), U8(0), U8(13), //
2560 B(Star), R(2), // 2455 B(Star), R(2), //
2561 B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(1), U8(2), // 2456 B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(1), U8(2), //
2562 B(Ldar), R(1), // 2457 B(Ldar), R(1), //
2563 B(Return), // 2458 B(Return), //
2564 }, 2459 },
2565 2, 2460 2,
2566 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2461 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2567 InstanceType::FIXED_ARRAY_TYPE}}, 2462 InstanceType::FIXED_ARRAY_TYPE}},
2568 {"var n = 'name'; return { [n]: 'val', get a() { }, set a(b) {} };", 2463 {"var n = 'name'; return { [n]: 'val', get a() { }, set a(b) {} };",
2569 5 * kPointerSize, 2464 5 * kPointerSize,
2570 1, 2465 1,
2571 69, 2466 69,
2572 { 2467 {
2573 B(LdaConstant), U8(0), // 2468 B(LdaConstant), U8(0), //
2574 B(Star), R(0), // 2469 B(Star), R(0), //
2575 B(LdaConstant), U8(1), // 2470 B(LdaConstant), U8(1), //
2576 B(CreateObjectLiteral), U8(0), U8(simple_flags), // 2471 B(CreateObjectLiteral), U8(0), U8(simple_flags), //
2577 B(Star), R(1), // 2472 B(Star), R(1), //
2578 B(Ldar), R(0), // 2473 B(Ldar), R(0), //
2579 B(ToName), // 2474 B(ToName), //
2580 B(Star), R(2), // 2475 B(Star), R(2), //
2581 B(LdaConstant), U8(2), // 2476 B(LdaConstant), U8(2), //
2582 B(Star), R(3), // 2477 B(Star), R(3), //
2583 B(LdaZero), // 2478 B(LdaZero), //
2584 B(Star), R(4), // 2479 B(Star), R(4), //
2585 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), // 2480 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
2586 U8(4), // 2481 U8(4), //
2587 B(LdaConstant), U8(3), // 2482 B(LdaConstant), U8(3), //
2588 B(ToName), // 2483 B(ToName), //
2589 B(Star), R(2), // 2484 B(Star), R(2), //
2590 B(LdaConstant), U8(4), // 2485 B(LdaConstant), U8(4), //
2591 B(CreateClosure), U8(0), // 2486 B(CreateClosure), U8(0), //
2592 B(Star), R(3), // 2487 B(Star), R(3), //
2593 B(LdaZero), // 2488 B(LdaZero), //
2594 B(Star), R(4), // 2489 B(Star), R(4), //
2595 B(CallRuntime), U16(Runtime::kDefineGetterPropertyUnchecked), // 2490 B(CallRuntime), U16(Runtime::kDefineGetterPropertyUnchecked), //
2596 R(1), U8(4), // 2491 R(1), U8(4), //
2597 B(LdaConstant), U8(3), // 2492 B(LdaConstant), U8(3), //
2598 B(ToName), // 2493 B(ToName), //
2599 B(Star), R(2), // 2494 B(Star), R(2), //
2600 B(LdaConstant), U8(5), // 2495 B(LdaConstant), U8(5), //
2601 B(CreateClosure), U8(0), // 2496 B(CreateClosure), U8(0), //
2602 B(Star), R(3), // 2497 B(Star), R(3), //
2603 B(LdaZero), // 2498 B(LdaZero), //
2604 B(Star), R(4), // 2499 B(Star), R(4), //
2605 B(CallRuntime), U16(Runtime::kDefineSetterPropertyUnchecked), // 2500 B(CallRuntime), U16(Runtime::kDefineSetterPropertyUnchecked), //
2606 R(1), U8(4), // 2501 R(1), U8(4), //
2607 B(Ldar), R(1), // 2502 B(Ldar), R(1), //
2608 B(Return), // 2503 B(Return), //
2609 }, 2504 },
2610 6, 2505 6,
2611 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2506 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2612 InstanceType::FIXED_ARRAY_TYPE, 2507 InstanceType::FIXED_ARRAY_TYPE,
2613 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2508 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2614 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2509 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2615 InstanceType::SHARED_FUNCTION_INFO_TYPE, 2510 InstanceType::SHARED_FUNCTION_INFO_TYPE,
2616 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2511 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 B(LdaConstant), U8(4), // 2553 B(LdaConstant), U8(4), //
2659 B(Star), R(6), // 2554 B(Star), R(6), //
2660 B(LdaConstant), U8(5), // 2555 B(LdaConstant), U8(5), //
2661 B(CreateClosure), U8(1), // 2556 B(CreateClosure), U8(1), //
2662 B(StoreICSloppy), R(5), R(6), U8(3), // 2557 B(StoreICSloppy), R(5), R(6), U8(3), //
2663 B(CallRuntime), U16(Runtime::kToFastProperties), R(5), U8(1), // 2558 B(CallRuntime), U16(Runtime::kToFastProperties), R(5), U8(1), //
2664 B(Ldar), R(5), // 2559 B(Ldar), R(5), //
2665 B(Star), R(4), // 2560 B(Star), R(4), //
2666 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), U8(3), // 2561 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), U8(3), //
2667 B(LdaUndefined), // 2562 B(LdaUndefined), //
2668 B(Return), // 2563 B(Return),
2669 }, 2564 },
2670 6, 2565 6,
2671 {InstanceType::FIXED_ARRAY_TYPE, 2566 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE,
2672 InstanceType::FIXED_ARRAY_TYPE,
2673 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2567 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2674 InstanceType::FIXED_ARRAY_TYPE, 2568 InstanceType::FIXED_ARRAY_TYPE,
2675 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, 2569 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2676 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2570 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2677 }; 2571 };
2678 2572
2679 for (size_t i = 0; i < arraysize(snippets); i++) { 2573 for (size_t i = 0; i < arraysize(snippets); i++) {
2680 Handle<BytecodeArray> bytecode_array = 2574 Handle<BytecodeArray> bytecode_array =
2681 helper.MakeTopLevelBytecode(snippets[i].code_snippet); 2575 helper.MakeTopLevelBytecode(snippets[i].code_snippet);
2682 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2576 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2683 } 2577 }
2684 } 2578 }
2685 2579
2686 2580
2687 TEST(TryCatch) { 2581 TEST(TryCatch) {
2688 InitializedHandleScope handle_scope; 2582 InitializedHandleScope handle_scope;
2689 BytecodeGeneratorHelper helper; 2583 BytecodeGeneratorHelper helper;
2690 2584
2691 // TODO(rmcilroy): modify tests when we have real try catch support. 2585 // TODO(rmcilroy): modify tests when we have real try catch support.
2692 ExpectedSnippet<int> snippets[] = { 2586 ExpectedSnippet<int> snippets[] = {
2693 {"try { return 1; } catch(e) { return 2; }", 2587 {"try { return 1; } catch(e) { return 2; }",
2694 1 * kPointerSize, 2588 kPointerSize,
2695 1, 2589 1,
2696 5, 2590 5,
2697 { 2591 {
2698 B(LdaSmi8), U8(1), // 2592 B(LdaSmi8), U8(1), //
2699 B(Return), // 2593 B(Return), //
2700 B(LdaUndefined), // 2594 B(LdaUndefined), //
2701 B(Return), // 2595 B(Return), //
2702 }, 2596 },
2703 0}, 2597 0},
2704 }; 2598 };
2705 2599
2706 for (size_t i = 0; i < arraysize(snippets); i++) { 2600 for (size_t i = 0; i < arraysize(snippets); i++) {
2707 Handle<BytecodeArray> bytecode_array = 2601 Handle<BytecodeArray> bytecode_array =
2708 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 2602 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2709 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2603 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2710 } 2604 }
2711 } 2605 }
2712 2606
2713 2607
2714 TEST(TryFinally) { 2608 TEST(TryFinally) {
2715 InitializedHandleScope handle_scope; 2609 InitializedHandleScope handle_scope;
2716 BytecodeGeneratorHelper helper; 2610 BytecodeGeneratorHelper helper;
2717 2611
2718 // TODO(rmcilroy): modify tests when we have real try finally support. 2612 // TODO(rmcilroy): modify tests when we have real try finally support.
2719 ExpectedSnippet<int> snippets[] = { 2613 ExpectedSnippet<int> snippets[] = {
2720 {"var a = 1; try { a = 2; } finally { a = 3; }", 2614 {"var a = 1; try { a = 2; } finally { a = 3; }",
2721 1 * kPointerSize, 2615 kPointerSize,
2722 1, 2616 1,
2723 14, 2617 14,
2724 { 2618 {
2725 B(LdaSmi8), U8(1), // 2619 B(LdaSmi8), U8(1), //
2726 B(Star), R(0), // 2620 B(Star), R(0), //
2727 B(LdaSmi8), U8(2), // 2621 B(LdaSmi8), U8(2), //
2728 B(Star), R(0), // 2622 B(Star), R(0), //
2729 B(LdaSmi8), U8(3), // 2623 B(LdaSmi8), U8(3), //
2730 B(Star), R(0), // 2624 B(Star), R(0), //
2731 B(LdaUndefined), // 2625 B(LdaUndefined), //
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
3023 for (size_t i = 0; i < arraysize(snippets); i++) { 2917 for (size_t i = 0; i < arraysize(snippets); i++) {
3024 Handle<BytecodeArray> bytecode_array = 2918 Handle<BytecodeArray> bytecode_array =
3025 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 2919 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
3026 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2920 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3027 } 2921 }
3028 } 2922 }
3029 2923
3030 } // namespace interpreter 2924 } // namespace interpreter
3031 } // namespace internal 2925 } // namespace internal
3032 } // namespace v8 2926 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698