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

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

Powered by Google App Engine
This is Rietveld 408576698