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

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

Issue 1323463005: [Interpreter] Add support for JS calls. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add VisitCall to bytecode-generator Created 5 years, 3 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-generator.h" 8 #include "src/interpreter/bytecode-generator.h"
9 #include "src/interpreter/interpreter.h" 9 #include "src/interpreter/interpreter.h"
10 #include "test/cctest/cctest.h" 10 #include "test/cctest/cctest.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 }; 56 };
57 57
58 58
59 // Structure for containing expected bytecode snippets. 59 // Structure for containing expected bytecode snippets.
60 template<typename T> 60 template<typename T>
61 struct ExpectedSnippet { 61 struct ExpectedSnippet {
62 const char* code_snippet; 62 const char* code_snippet;
63 int frame_size; 63 int frame_size;
64 int parameter_count; 64 int parameter_count;
65 int bytecode_length; 65 int bytecode_length;
66 const uint8_t bytecode[24]; 66 const uint8_t bytecode[32];
67 int constant_count; 67 int constant_count;
68 T constants[16]; 68 T constants[16];
69 }; 69 };
70 70
71 71
72 // Helper macros for handcrafting bytecode sequences. 72 // Helper macros for handcrafting bytecode sequences.
73 #define B(x) static_cast<uint8_t>(Bytecode::k##x) 73 #define B(x) static_cast<uint8_t>(Bytecode::k##x)
74 #define U8(x) static_cast<uint8_t>((x) & 0xff) 74 #define U8(x) static_cast<uint8_t>((x) & 0xff)
75 #define R(x) static_cast<uint8_t>(-(x) & 0xff) 75 #define R(x) static_cast<uint8_t>(-(x) & 0xff)
76 76
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 330 }
331 } 331 }
332 } 332 }
333 333
334 334
335 TEST(PropertyLoads) { 335 TEST(PropertyLoads) {
336 InitializedHandleScope handle_scope; 336 InitializedHandleScope handle_scope;
337 BytecodeGeneratorHelper helper; 337 BytecodeGeneratorHelper helper;
338 338
339 Code::Kind ic_kinds[] = { i::Code::LOAD_IC, i::Code::LOAD_IC }; 339 Code::Kind ic_kinds[] = { i::Code::LOAD_IC, i::Code::LOAD_IC };
340 FeedbackVectorSpec feedback_spec(0, 1, ic_kinds); 340 FeedbackVectorSpec feedback_spec(0, 2, ic_kinds);
341 Handle<i::TypeFeedbackVector> vector = 341 Handle<i::TypeFeedbackVector> vector =
342 helper.factory()->NewTypeFeedbackVector(&feedback_spec); 342 helper.factory()->NewTypeFeedbackVector(&feedback_spec);
343 343
344 ExpectedSnippet<const char*> snippets[] = { 344 ExpectedSnippet<const char*> snippets[] = {
345 {"function f(a) { return a.name; }\nf({name : \"test\"})", 345 {"function f(a) { return a.name; }\nf({name : \"test\"})",
346 1 * kPointerSize, 2, 10, 346 1 * kPointerSize, 2, 10,
347 { 347 {
348 B(Ldar), R(helper.kLastParamIndex), 348 B(Ldar), R(helper.kLastParamIndex),
349 B(Star), R(0), 349 B(Star), R(0),
350 B(LdaConstant), U8(0), 350 B(LdaConstant), U8(0),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 419 }
420 } 420 }
421 } 421 }
422 422
423 423
424 TEST(PropertyStores) { 424 TEST(PropertyStores) {
425 InitializedHandleScope handle_scope; 425 InitializedHandleScope handle_scope;
426 BytecodeGeneratorHelper helper; 426 BytecodeGeneratorHelper helper;
427 427
428 Code::Kind ic_kinds[] = { i::Code::STORE_IC, i::Code::STORE_IC }; 428 Code::Kind ic_kinds[] = { i::Code::STORE_IC, i::Code::STORE_IC };
429 FeedbackVectorSpec feedback_spec(0, 1, ic_kinds); 429 FeedbackVectorSpec feedback_spec(0, 2, ic_kinds);
430 Handle<i::TypeFeedbackVector> vector = 430 Handle<i::TypeFeedbackVector> vector =
431 helper.factory()->NewTypeFeedbackVector(&feedback_spec); 431 helper.factory()->NewTypeFeedbackVector(&feedback_spec);
432 432
433 ExpectedSnippet<const char*> snippets[] = { 433 ExpectedSnippet<const char*> snippets[] = {
434 {"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})", 434 {"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})",
435 2 * kPointerSize, 2, 16, 435 2 * kPointerSize, 2, 16,
436 { 436 {
437 B(Ldar), R(helper.kLastParamIndex), 437 B(Ldar), R(helper.kLastParamIndex),
438 B(Star), R(0), 438 B(Star), R(0),
439 B(LdaConstant), U8(0), 439 B(LdaConstant), U8(0),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 ba->length())); 517 ba->length()));
518 CHECK_EQ(ba->constant_pool()->length(), snippets[i].constant_count); 518 CHECK_EQ(ba->constant_pool()->length(), snippets[i].constant_count);
519 for (int j = 0; j < snippets[i].constant_count; j++) { 519 for (int j = 0; j < snippets[i].constant_count; j++) {
520 Handle<String> expected = 520 Handle<String> expected =
521 helper.factory()->NewStringFromAsciiChecked(snippets[i].constants[j]); 521 helper.factory()->NewStringFromAsciiChecked(snippets[i].constants[j]);
522 CHECK(String::cast(ba->constant_pool()->get(j))->Equals(*expected)); 522 CHECK(String::cast(ba->constant_pool()->get(j))->Equals(*expected));
523 } 523 }
524 } 524 }
525 } 525 }
526 526
527
528 #define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()"
529
530
531 TEST(PropertyCall) {
532 InitializedHandleScope handle_scope;
533 BytecodeGeneratorHelper helper;
534
535 Code::Kind ic_kinds[] = { i::Code::LOAD_IC, i::Code::LOAD_IC };
536 FeedbackVectorSpec feedback_spec(0, 2, ic_kinds);
537 Handle<i::TypeFeedbackVector> vector =
538 helper.factory()->NewTypeFeedbackVector(&feedback_spec);
539
540 ExpectedSnippet<const char*> snippets[] = {
541 {"function f(a) { return a.func(); }\nf(" FUNC_ARG ")",
542 2 * kPointerSize, 2, 16,
543 {
544 B(Ldar), R(helper.kLastParamIndex),
545 B(Star), R(1),
546 B(LdaConstant), U8(0),
547 B(LoadIC), R(1), U8(vector->first_ic_slot_index() + 2),
548 B(Star), R(0),
549 B(Call), R(0), R(1), U8(0),
550 B(Return)
551 },
552 1, { "func" }
553 },
554 {"function f(a, b, c) { return a.func(b, c); }\nf(" FUNC_ARG ", 1, 2)",
555 4 * kPointerSize, 4, 24,
556 {
557 B(Ldar), R(helper.kLastParamIndex - 2),
558 B(Star), R(1),
559 B(LdaConstant), U8(0),
560 B(LoadIC), R(1), U8(vector->first_ic_slot_index() + 2),
561 B(Star), R(0),
562 B(Ldar), R(helper.kLastParamIndex - 1),
563 B(Star), R(2),
564 B(Ldar), R(helper.kLastParamIndex),
565 B(Star), R(3),
566 B(Call), R(0), R(1), U8(2),
567 B(Return)
568 },
569 1, { "func" }
570 },
571 {"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)",
572 4 * kPointerSize, 3, 30,
573 {
574 B(Ldar), R(helper.kLastParamIndex - 1),
575 B(Star), R(1),
576 B(LdaConstant), U8(0),
577 B(LoadIC), R(1), U8(vector->first_ic_slot_index() + 2),
578 B(Star), R(0),
579 B(Ldar), R(helper.kLastParamIndex),
580 B(Star), R(2),
581 B(Ldar), R(helper.kLastParamIndex),
582 B(Add), R(2),
583 B(Star), R(2),
584 B(Ldar), R(helper.kLastParamIndex),
585 B(Star), R(3),
586 B(Call), R(0), R(1), U8(2),
587 B(Return)
588 },
589 1, { "func" }
590 }
591 };
592 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
593 for (size_t i = 0; i < num_snippets; i++) {
594 Handle<BytecodeArray> ba =
595 helper.MakeBytecode(snippets[i].code_snippet, "f");
596 CHECK_EQ(ba->frame_size(), snippets[i].frame_size);
597 CHECK_EQ(ba->parameter_count(), snippets[i].parameter_count);
598 CHECK_EQ(ba->length(), snippets[i].bytecode_length);
599 CHECK(!memcmp(ba->GetFirstBytecodeAddress(), snippets[i].bytecode,
600 ba->length()));
601 CHECK_EQ(ba->constant_pool()->length(), snippets[i].constant_count);
602 for (int j = 0; j < snippets[i].constant_count; j++) {
603 Handle<String> expected =
604 helper.factory()->NewStringFromAsciiChecked(snippets[i].constants[j]);
605 CHECK(String::cast(ba->constant_pool()->get(j))->Equals(*expected));
606 }
607 }
608 }
609
527 } // namespace interpreter 610 } // namespace interpreter
528 } // namespace internal 611 } // namespace internal
529 } // namespance v8 612 } // namespance v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698