OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
7 | 7 |
8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 Function& function = Function::ZoneHandle( | 32 Function& function = Function::ZoneHandle( |
33 Function::New(function_name, RawFunction::kRegularFunction, | 33 Function::New(function_name, RawFunction::kRegularFunction, |
34 true, false, false, false, owner_class, 0)); | 34 true, false, false, false, owner_class, 0)); |
35 return &function; | 35 return &function; |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 // Test calls to stub code which calls into the runtime. | 39 // Test calls to stub code which calls into the runtime. |
40 static void GenerateCallToCallRuntimeStub(Assembler* assembler, | 40 static void GenerateCallToCallRuntimeStub(Assembler* assembler, |
41 int value1, int value2) { | 41 int value1, int value2) { |
42 UNIMPLEMENTED(); | 42 const int argc = 2; |
| 43 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); |
| 44 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); |
| 45 const Object& result = Object::ZoneHandle(); |
| 46 const Context& context = Context::ZoneHandle(Context::New(0, Heap::kOld)); |
| 47 ASSERT(context.isolate() == Isolate::Current()); |
| 48 __ EnterDartFrame(0); |
| 49 __ LoadObject(CTX, context); |
| 50 __ PushObject(result); // Push Null object for return value. |
| 51 __ PushObject(smi1); // Push argument 1 smi1. |
| 52 __ PushObject(smi2); // Push argument 2 smi2. |
| 53 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc); |
| 54 __ CallRuntime(kTestSmiSubRuntimeEntry); // Call SmiSub runtime func. |
| 55 __ AddImmediate(SP, argc * kWordSize); |
| 56 __ Pop(R0); // Pop return value from return slot. |
| 57 __ LeaveDartFrame(); |
| 58 __ Ret(); |
43 } | 59 } |
44 | 60 |
45 | 61 |
46 TEST_CASE(CallRuntimeStubCode) { | 62 TEST_CASE(CallRuntimeStubCode) { |
47 extern const Function& RegisterFakeFunction(const char* name, | 63 extern const Function& RegisterFakeFunction(const char* name, |
48 const Code& code); | 64 const Code& code); |
49 const int value1 = 10; | 65 const int value1 = 10; |
50 const int value2 = 20; | 66 const int value2 = 20; |
51 const char* kName = "Test_CallRuntimeStubCode"; | 67 const char* kName = "Test_CallRuntimeStubCode"; |
52 Assembler _assembler_; | 68 Assembler _assembler_; |
53 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); | 69 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); |
54 const Code& code = Code::Handle(Code::FinalizeCode( | 70 const Code& code = Code::Handle(Code::FinalizeCode( |
55 *CreateFunction("Test_CallRuntimeStubCode"), &_assembler_)); | 71 *CreateFunction("Test_CallRuntimeStubCode"), &_assembler_)); |
56 const Function& function = RegisterFakeFunction(kName, code); | 72 const Function& function = RegisterFakeFunction(kName, code); |
57 Smi& result = Smi::Handle(); | 73 Smi& result = Smi::Handle(); |
58 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); | 74 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); |
59 EXPECT_EQ((value1 - value2), result.Value()); | 75 EXPECT_EQ((value1 - value2), result.Value()); |
60 } | 76 } |
61 | 77 |
62 | 78 |
63 // Test calls to stub code which calls into a leaf runtime entry. | 79 // Test calls to stub code which calls into a leaf runtime entry. |
64 static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler, | 80 static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler, |
65 int value1, | 81 int value1, |
66 int value2) { | 82 int value2) { |
67 UNIMPLEMENTED(); | 83 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); |
| 84 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); |
| 85 __ EnterDartFrame(0); |
| 86 __ ReserveAlignedFrameSpace(0); |
| 87 __ LoadObject(R0, smi1); // Set up argument 1 smi1. |
| 88 __ LoadObject(R1, smi2); // Set up argument 2 smi2. |
| 89 __ CallRuntime(kTestLeafSmiAddRuntimeEntry); // Call SmiAdd runtime func. |
| 90 __ LeaveDartFrame(); |
| 91 __ Ret(); // Return value is in R0. |
68 } | 92 } |
69 | 93 |
70 | 94 |
71 TEST_CASE(CallLeafRuntimeStubCode) { | 95 TEST_CASE(CallLeafRuntimeStubCode) { |
72 extern const Function& RegisterFakeFunction(const char* name, | 96 extern const Function& RegisterFakeFunction(const char* name, |
73 const Code& code); | 97 const Code& code); |
74 const int value1 = 10; | 98 const int value1 = 10; |
75 const int value2 = 20; | 99 const int value2 = 20; |
76 const char* kName = "Test_CallLeafRuntimeStubCode"; | 100 const char* kName = "Test_CallLeafRuntimeStubCode"; |
77 Assembler _assembler_; | 101 Assembler _assembler_; |
78 GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2); | 102 GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2); |
79 const Code& code = Code::Handle(Code::FinalizeCode( | 103 const Code& code = Code::Handle(Code::FinalizeCode( |
80 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); | 104 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); |
81 const Function& function = RegisterFakeFunction(kName, code); | 105 const Function& function = RegisterFakeFunction(kName, code); |
82 Smi& result = Smi::Handle(); | 106 Smi& result = Smi::Handle(); |
83 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); | 107 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); |
84 EXPECT_EQ((value1 + value2), result.Value()); | 108 EXPECT_EQ((value1 + value2), result.Value()); |
85 } | 109 } |
86 | 110 |
87 } // namespace dart | 111 } // namespace dart |
88 | 112 |
89 #endif // defined TARGET_ARCH_ARM | 113 #endif // defined TARGET_ARCH_ARM |
OLD | NEW |