OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_DBC) | 6 #if defined(TARGET_ARCH_DBC) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/stack_frame.h" | 9 #include "vm/stack_frame.h" |
10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 static RawObject* ExecuteTest(const Code& code) { | 14 static RawObject* ExecuteTest(const Code& code) { |
15 Thread* thread = Thread::Current(); | 15 Thread* thread = Thread::Current(); |
16 TransitionToGenerated transition(thread); | 16 TransitionToGenerated transition(thread); |
17 return Simulator::Current()->Call( | 17 return Simulator::Current()->Call(code, |
18 code, | 18 Array::Handle(ArgumentsDescriptor::New(0)), |
19 Array::Handle(ArgumentsDescriptor::New(0)), | 19 Array::Handle(Array::New(0)), thread); |
20 Array::Handle(Array::New(0)), | |
21 thread); | |
22 } | 20 } |
23 | 21 |
24 | 22 |
25 #define EXECUTE_TEST_CODE_INTPTR(code) \ | 23 #define EXECUTE_TEST_CODE_INTPTR(code) \ |
26 Smi::Value(Smi::RawCast(ExecuteTest(code))) | 24 Smi::Value(Smi::RawCast(ExecuteTest(code))) |
27 #define EXECUTE_TEST_CODE_BOOL(code) \ | 25 #define EXECUTE_TEST_CODE_BOOL(code) \ |
28 (Bool::RawCast(ExecuteTest(code)) == Bool::True().raw()) | 26 (Bool::RawCast(ExecuteTest(code)) == Bool::True().raw()) |
29 #define EXECUTE_TEST_CODE_OBJECT(code) \ | 27 #define EXECUTE_TEST_CODE_OBJECT(code) Object::Handle(ExecuteTest(code)) |
30 Object::Handle(ExecuteTest(code)) | |
31 #define EXECUTE_TEST_CODE_DOUBLE(code) \ | 28 #define EXECUTE_TEST_CODE_DOUBLE(code) \ |
32 bit_cast<double, RawObject*>(ExecuteTest(code)) | 29 bit_cast<double, RawObject*>(ExecuteTest(code)) |
33 | 30 |
34 #define __ assembler-> | 31 #define __ assembler-> |
35 | 32 |
36 | 33 |
37 static RawClass* CreateDummyClass(const String& class_name, | 34 static RawClass* CreateDummyClass(const String& class_name, |
38 const Script& script) { | 35 const Script& script) { |
39 const Class& cls = Class::Handle(Class::New( | 36 const Class& cls = Class::Handle(Class::New( |
40 Library::Handle(), class_name, script, TokenPosition::kNoSource)); | 37 Library::Handle(), class_name, script, TokenPosition::kNoSource)); |
41 cls.set_is_synthesized_class(); // Dummy class for testing. | 38 cls.set_is_synthesized_class(); // Dummy class for testing. |
42 return cls.raw(); | 39 return cls.raw(); |
43 } | 40 } |
44 | 41 |
45 | 42 |
46 static RawLibrary* CreateDummyLibrary(const String& library_name) { | 43 static RawLibrary* CreateDummyLibrary(const String& library_name) { |
47 return Library::New(library_name); | 44 return Library::New(library_name); |
48 } | 45 } |
49 | 46 |
50 | 47 |
51 static RawFunction* CreateFunction(const char* name) { | 48 static RawFunction* CreateFunction(const char* name) { |
52 Thread* thread = Thread::Current(); | 49 Thread* thread = Thread::Current(); |
53 const String& class_name = String::Handle(Symbols::New(thread, "ownerClass")); | 50 const String& class_name = String::Handle(Symbols::New(thread, "ownerClass")); |
54 const String& lib_name = String::Handle(Symbols::New(thread, "ownerLibrary")); | 51 const String& lib_name = String::Handle(Symbols::New(thread, "ownerLibrary")); |
55 const Script& script = Script::Handle(); | 52 const Script& script = Script::Handle(); |
56 const Class& owner_class = | 53 const Class& owner_class = |
57 Class::Handle(CreateDummyClass(class_name, script)); | 54 Class::Handle(CreateDummyClass(class_name, script)); |
58 const Library& owner_library = | 55 const Library& owner_library = Library::Handle(CreateDummyLibrary(lib_name)); |
59 Library::Handle(CreateDummyLibrary(lib_name)); | |
60 owner_class.set_library(owner_library); | 56 owner_class.set_library(owner_library); |
61 const String& function_name = String::ZoneHandle(Symbols::New(thread, name)); | 57 const String& function_name = String::ZoneHandle(Symbols::New(thread, name)); |
62 return Function::New(function_name, RawFunction::kRegularFunction, | 58 return Function::New(function_name, RawFunction::kRegularFunction, true, |
63 true, false, false, false, false, owner_class, | 59 false, false, false, false, owner_class, |
64 TokenPosition::kMinSource); | 60 TokenPosition::kMinSource); |
65 } | 61 } |
66 | 62 |
67 | 63 |
68 static void GenerateDummyCode(Assembler* assembler, const Object& result) { | 64 static void GenerateDummyCode(Assembler* assembler, const Object& result) { |
69 __ PushConstant(result); | 65 __ PushConstant(result); |
70 __ ReturnTOS(); | 66 __ ReturnTOS(); |
71 } | 67 } |
72 | 68 |
73 | 69 |
74 static void MakeDummyInstanceCall(Assembler* assembler, const Object& result) { | 70 static void MakeDummyInstanceCall(Assembler* assembler, const Object& result) { |
75 // Make a dummy function. | 71 // Make a dummy function. |
76 Assembler _assembler_; | 72 Assembler _assembler_; |
77 GenerateDummyCode(&_assembler_, result); | 73 GenerateDummyCode(&_assembler_, result); |
78 const char* dummy_function_name = "dummy_instance_function"; | 74 const char* dummy_function_name = "dummy_instance_function"; |
79 const Function& dummy_instance_function = | 75 const Function& dummy_instance_function = |
80 Function::Handle(CreateFunction(dummy_function_name)); | 76 Function::Handle(CreateFunction(dummy_function_name)); |
81 Code& code = | 77 Code& code = |
82 Code::Handle(Code::FinalizeCode(dummy_instance_function, &_assembler_)); | 78 Code::Handle(Code::FinalizeCode(dummy_instance_function, &_assembler_)); |
83 dummy_instance_function.AttachCode(code); | 79 dummy_instance_function.AttachCode(code); |
84 | 80 |
85 // Make a dummy ICData. | 81 // Make a dummy ICData. |
86 const Array& dummy_arguments_descriptor = | 82 const Array& dummy_arguments_descriptor = |
87 Array::Handle(ArgumentsDescriptor::New(2)); | 83 Array::Handle(ArgumentsDescriptor::New(2)); |
88 const ICData& ic_data = ICData::Handle(ICData::New( | 84 const ICData& ic_data = ICData::Handle(ICData::New( |
89 dummy_instance_function, | 85 dummy_instance_function, String::Handle(dummy_instance_function.name()), |
90 String::Handle(dummy_instance_function.name()), | 86 dummy_arguments_descriptor, Thread::kNoDeoptId, 2, |
91 dummy_arguments_descriptor, | |
92 Thread::kNoDeoptId, | |
93 2, | |
94 /* is_static_call= */ false)); | 87 /* is_static_call= */ false)); |
95 | 88 |
96 // Wire up the Function in the ICData. | 89 // Wire up the Function in the ICData. |
97 GrowableArray<intptr_t> cids(2); | 90 GrowableArray<intptr_t> cids(2); |
98 cids.Add(kSmiCid); | 91 cids.Add(kSmiCid); |
99 cids.Add(kSmiCid); | 92 cids.Add(kSmiCid); |
100 ic_data.AddCheck(cids, dummy_instance_function); | 93 ic_data.AddCheck(cids, dummy_instance_function); |
101 | 94 |
102 // For the non-Smi tests. | 95 // For the non-Smi tests. |
103 cids[0] = kBigintCid; | 96 cids[0] = kBigintCid; |
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 __ LoadConstant(1, Smi::Handle(Smi::New(2))); | 1722 __ LoadConstant(1, Smi::Handle(Smi::New(2))); |
1730 __ Return(1); | 1723 __ Return(1); |
1731 } | 1724 } |
1732 | 1725 |
1733 | 1726 |
1734 ASSEMBLER_TEST_RUN(TestCidsNoMatch, test) { | 1727 ASSEMBLER_TEST_RUN(TestCidsNoMatch, test) { |
1735 EXPECT_EQ(2, EXECUTE_TEST_CODE_INTPTR(test->code())); | 1728 EXPECT_EQ(2, EXECUTE_TEST_CODE_INTPTR(test->code())); |
1736 } | 1729 } |
1737 | 1730 |
1738 | 1731 |
1739 | |
1740 // - CheckSmi rA | 1732 // - CheckSmi rA |
1741 // | 1733 // |
1742 // If FP[rA] is a Smi, then skip the next instruction. | 1734 // If FP[rA] is a Smi, then skip the next instruction. |
1743 ASSEMBLER_TEST_GENERATE(CheckSmiPass, assembler) { | 1735 ASSEMBLER_TEST_GENERATE(CheckSmiPass, assembler) { |
1744 __ Frame(1); | 1736 __ Frame(1); |
1745 __ PushConstant(Smi::Handle(Smi::New(42))); | 1737 __ PushConstant(Smi::Handle(Smi::New(42))); |
1746 __ LoadConstant(0, Smi::Handle(Smi::New(0))); | 1738 __ LoadConstant(0, Smi::Handle(Smi::New(0))); |
1747 __ CheckSmi(0); | 1739 __ CheckSmi(0); |
1748 __ PushConstant(Smi::Handle(Smi::New(-1))); | 1740 __ PushConstant(Smi::Handle(Smi::New(-1))); |
1749 __ ReturnTOS(); | 1741 __ ReturnTOS(); |
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2820 | 2812 |
2821 ASSEMBLER_TEST_RUN(DMax, test) { | 2813 ASSEMBLER_TEST_RUN(DMax, test) { |
2822 EXPECT_EQ(42.0, EXECUTE_TEST_CODE_DOUBLE(test->code())); | 2814 EXPECT_EQ(42.0, EXECUTE_TEST_CODE_DOUBLE(test->code())); |
2823 } | 2815 } |
2824 | 2816 |
2825 #endif // defined(ARCH_IS_64_BIT) | 2817 #endif // defined(ARCH_IS_64_BIT) |
2826 | 2818 |
2827 } // namespace dart | 2819 } // namespace dart |
2828 | 2820 |
2829 #endif // defined(TARGET_ARCH_DBC) | 2821 #endif // defined(TARGET_ARCH_DBC) |
OLD | NEW |