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

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

Issue 1362383002: [Interpreter] Add CallRuntime support to the interpreter. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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"
11 #include "test/cctest/cctest.h" 11 #include "test/cctest/cctest.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 namespace interpreter { 15 namespace interpreter {
16 16
17 class BytecodeGeneratorHelper { 17 class BytecodeGeneratorHelper {
18 public: 18 public:
19 const char* kFunctionName = "f"; 19 const char* kFunctionName = "f";
20 20
21 const int kLastParamIndex = 21 const int kLastParamIndex =
22 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; 22 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
23 23
24 BytecodeGeneratorHelper() { 24 BytecodeGeneratorHelper() {
25 i::FLAG_vector_stores = true; 25 i::FLAG_vector_stores = true;
26 i::FLAG_ignition = true; 26 i::FLAG_ignition = true;
27 i::FLAG_ignition_filter = StrDup(kFunctionName); 27 i::FLAG_ignition_filter = StrDup(kFunctionName);
28 i::FLAG_always_opt = false; 28 i::FLAG_always_opt = false;
29 i::FLAG_allow_natives_syntax = true;
29 CcTest::i_isolate()->interpreter()->Initialize(); 30 CcTest::i_isolate()->interpreter()->Initialize();
30 } 31 }
31 32
32 33
33 Factory* factory() { return CcTest::i_isolate()->factory(); } 34 Factory* factory() { return CcTest::i_isolate()->factory(); }
34 35
35 36
36 Handle<BytecodeArray> MakeBytecode(const char* script, 37 Handle<BytecodeArray> MakeBytecode(const char* script,
37 const char* function_name) { 38 const char* function_name) {
38 CompileRun(script); 39 CompileRun(script);
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 helper.MakeBytecode(snippets[i].code_snippet, "f"); 652 helper.MakeBytecode(snippets[i].code_snippet, "f");
652 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 653 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
653 } 654 }
654 } 655 }
655 656
656 657
657 TEST(LoadGlobal) { 658 TEST(LoadGlobal) {
658 InitializedHandleScope handle_scope; 659 InitializedHandleScope handle_scope;
659 BytecodeGeneratorHelper helper; 660 BytecodeGeneratorHelper helper;
660 661
661 ExpectedSnippet<const char*> snippets[] = { 662 ExpectedSnippet<int> snippets[] = {
662 {"var a = 1;\nfunction f() { return a; }\nf()", 663 {
663 0, 1, 3, 664 "var a = 1;\nfunction f() { return a; }\nf()",
664 { 665 0,
665 B(LdaGlobal), _, 666 1,
666 B(Return) 667 3,
667 }, 668 {
669 B(LdaGlobal), _, //
670 B(Return) //
671 },
668 }, 672 },
669 {"function t() { }\nfunction f() { return t; }\nf()", 673 {
670 0, 1, 3, 674 "function t() { }\nfunction f() { return t; }\nf()",
671 { 675 0,
672 B(LdaGlobal), _, 676 1,
673 B(Return) 677 3,
674 }, 678 {
679 B(LdaGlobal), _, //
680 B(Return) //
681 },
675 }, 682 },
676 }; 683 };
677 684
678 for (size_t i = 0; i < arraysize(snippets); i++) { 685 for (size_t i = 0; i < arraysize(snippets); i++) {
679 Handle<BytecodeArray> bytecode_array = 686 Handle<BytecodeArray> bytecode_array =
680 helper.MakeBytecode(snippets[i].code_snippet, "f"); 687 helper.MakeBytecode(snippets[i].code_snippet, "f");
681 bytecode_array->Print(); 688 bytecode_array->Print();
682 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); 689 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true);
683 } 690 }
684 } 691 }
685 692
686 693
687 TEST(CallGlobal) { 694 TEST(CallGlobal) {
688 InitializedHandleScope handle_scope; 695 InitializedHandleScope handle_scope;
689 BytecodeGeneratorHelper helper; 696 BytecodeGeneratorHelper helper;
690 697
691 ExpectedSnippet<const char*> snippets[] = { 698 ExpectedSnippet<int> snippets[] = {
692 {"function t() { }\nfunction f() { return t(); }\nf()", 699 {
693 2 * kPointerSize, 1, 12, 700 "function t() { }\nfunction f() { return t(); }\nf()",
694 { 701 2 * kPointerSize,
695 B(LdaUndefined), 702 1,
696 B(Star), R(1), 703 12,
697 B(LdaGlobal), _, 704 {
698 B(Star), R(0), 705 B(LdaUndefined), //
699 B(Call), R(0), R(1), U8(0), 706 B(Star), R(1), //
700 B(Return) 707 B(LdaGlobal), _, //
701 }, 708 B(Star), R(0), //
709 B(Call), R(0), R(1), U8(0), //
710 B(Return) //
711 },
702 }, 712 },
703 {"function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()", 713 {
704 5 * kPointerSize, 1, 24, 714 "function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()",
705 { 715 5 * kPointerSize,
706 B(LdaUndefined), 716 1,
707 B(Star), R(1), 717 24,
708 B(LdaGlobal), _, 718 {
709 B(Star), R(0), 719 B(LdaUndefined), //
710 B(LdaSmi8), U8(1), 720 B(Star), R(1), //
711 B(Star), R(2), 721 B(LdaGlobal), _, //
712 B(LdaSmi8), U8(2), 722 B(Star), R(0), //
713 B(Star), R(3), 723 B(LdaSmi8), U8(1), //
714 B(LdaSmi8), U8(3), 724 B(Star), R(2), //
715 B(Star), R(4), 725 B(LdaSmi8), U8(2), //
716 B(Call), R(0), R(1), U8(3), 726 B(Star), R(3), //
717 B(Return) 727 B(LdaSmi8), U8(3), //
718 }, 728 B(Star), R(4), //
729 B(Call), R(0), R(1), U8(3), //
730 B(Return) //
731 },
719 }, 732 },
720 }; 733 };
721 734
735 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
736 for (size_t i = 0; i < num_snippets; i++) {
737 Handle<BytecodeArray> bytecode_array =
738 helper.MakeBytecode(snippets[i].code_snippet, "f");
739 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true);
740 }
741 }
742
743
744 TEST(CallRuntime) {
745 InitializedHandleScope handle_scope;
746 BytecodeGeneratorHelper helper;
747
748 ExpectedSnippet<int> snippets[] = {
749 {
750 "function f() { %TheHole() }\nf()",
751 1 * kPointerSize,
752 1,
753 6,
754 {
755 B(CallRuntime), U8(Runtime::kTheHole), R(0), U8(0), //
756 B(LdaUndefined), //
757 B(Return) //
758 },
759 },
760 {
761 "function f(a) { return %IsArray(a) }\nf(undefined)",
762 1 * kPointerSize,
763 2,
764 9,
765 {
766 B(Ldar), R(helper.kLastParamIndex), //
767 B(Star), R(0), //
768 B(CallRuntime), U8(Runtime::kIsArray), R(0), U8(1), //
769 B(Return) //
770 },
771 },
772 {
773 "function f() { return %Add(1, 2) }\nf()",
774 2 * kPointerSize,
775 1,
776 13,
777 {
778 B(LdaSmi8), U8(1), //
779 B(Star), R(0), //
780 B(LdaSmi8), U8(2), //
781 B(Star), R(1), //
782 B(CallRuntime), U8(Runtime::kAdd), R(0), U8(2), //
783 B(Return) //
784 },
785 },
786 };
787
722 for (size_t i = 0; i < arraysize(snippets); i++) { 788 for (size_t i = 0; i < arraysize(snippets); i++) {
723 Handle<BytecodeArray> bytecode_array = 789 Handle<BytecodeArray> bytecode_array =
724 helper.MakeBytecode(snippets[i].code_snippet, "f"); 790 helper.MakeBytecode(snippets[i].code_snippet, "f");
725 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); 791 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true);
726 } 792 }
727 } 793 }
728 794
729 795
730 TEST(IfConditions) { 796 TEST(IfConditions) {
731 InitializedHandleScope handle_scope; 797 InitializedHandleScope handle_scope;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 Handle<BytecodeArray> bytecode_array = 937 Handle<BytecodeArray> bytecode_array =
872 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 938 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
873 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 939 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
874 } 940 }
875 } 941 }
876 942
877 943
878 } // namespace interpreter 944 } // namespace interpreter
879 } // namespace internal 945 } // namespace internal
880 } // namespance v8 946 } // namespance v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698