| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 const Code& code = Code::Handle(Code::FinalizeCode( | 105 const Code& code = Code::Handle(Code::FinalizeCode( |
| 106 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); | 106 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); |
| 107 const Function& function = RegisterFakeFunction(kName, code); | 107 const Function& function = RegisterFakeFunction(kName, code); |
| 108 GrowableArray<const Object*> arguments; | 108 GrowableArray<const Object*> arguments; |
| 109 const Array& kNoArgumentNames = Array::Handle(); | 109 const Array& kNoArgumentNames = Array::Handle(); |
| 110 Smi& result = Smi::Handle(); | 110 Smi& result = Smi::Handle(); |
| 111 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 111 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
| 112 EXPECT_EQ((value1 + value2), result.Value()); | 112 EXPECT_EQ((value1 + value2), result.Value()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 | |
| 116 // Test calls to stub code which calls a native C function. | |
| 117 static void GenerateCallToCallNativeCFunctionStub(Assembler* assembler, | |
| 118 int value1, int value2) { | |
| 119 const int argc = 2; | |
| 120 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); | |
| 121 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); | |
| 122 const Object& result = Object::ZoneHandle(); | |
| 123 const String& native_name = String::ZoneHandle(String::New("TestSmiSub")); | |
| 124 Dart_NativeFunction native_function = | |
| 125 NativeTestEntry_Lookup(native_name, argc); | |
| 126 ASSERT(native_function != NULL); | |
| 127 const Context& context = Context::ZoneHandle(Context::New(0, Heap::kOld)); | |
| 128 ASSERT(context.isolate() == Isolate::Current()); | |
| 129 __ enter(Immediate(0)); | |
| 130 __ LoadObject(CTX, context); | |
| 131 __ PushObject(smi1); // Push argument 1 smi1. | |
| 132 __ PushObject(smi2); // Push argument 2 smi2. | |
| 133 __ PushObject(result); // Push Null object for return value. | |
| 134 // Pass a pointer to the first argument in RAX. | |
| 135 __ leaq(RAX, Address(RSP, 2 * kWordSize)); | |
| 136 __ movq(RBX, Immediate(reinterpret_cast<uword>(native_function))); | |
| 137 __ movq(R10, Immediate(argc)); | |
| 138 __ call(&StubCode::CallNativeCFunctionLabel()); | |
| 139 __ popq(RAX); // Pop return value from return slot. | |
| 140 __ AddImmediate(RSP, Immediate(argc * kWordSize)); | |
| 141 __ leave(); | |
| 142 __ ret(); | |
| 143 } | |
| 144 | |
| 145 | |
| 146 TEST_CASE(CallNativeCFunctionStubCode) { | |
| 147 extern const Function& RegisterFakeFunction(const char* name, | |
| 148 const Code& code); | |
| 149 const int value1 = 15; | |
| 150 const int value2 = 20; | |
| 151 const char* kName = "Test_CallNativeCFunctionStubCode"; | |
| 152 Assembler _assembler_; | |
| 153 GenerateCallToCallNativeCFunctionStub(&_assembler_, value1, value2); | |
| 154 const Code& code = Code::Handle(Code::FinalizeCode( | |
| 155 *CreateFunction(kName), &_assembler_)); | |
| 156 const Function& function = RegisterFakeFunction(kName, code); | |
| 157 GrowableArray<const Object*> arguments; | |
| 158 const Array& kNoArgumentNames = Array::Handle(); | |
| 159 Smi& result = Smi::Handle(); | |
| 160 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | |
| 161 EXPECT_EQ((value1 - value2), result.Value()); | |
| 162 } | |
| 163 | |
| 164 } // namespace dart | 115 } // namespace dart |
| 165 | 116 |
| 166 #endif // defined TARGET_ARCH_X64 | 117 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |