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 26 matching lines...) Expand all Loading... |
37 __ PushObject(smi2); // Push argument 2 smi2. | 37 __ PushObject(smi2); // Push argument 2 smi2. |
38 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc); | 38 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc); |
39 __ CallRuntime(kTestSmiSubRuntimeEntry); // Call SmiSub runtime func. | 39 __ CallRuntime(kTestSmiSubRuntimeEntry); // Call SmiSub runtime func. |
40 __ AddImmediate(RSP, Immediate(argc * kWordSize)); | 40 __ AddImmediate(RSP, Immediate(argc * kWordSize)); |
41 __ popq(RAX); // Pop return value from return slot. | 41 __ popq(RAX); // Pop return value from return slot. |
42 __ leave(); | 42 __ leave(); |
43 __ ret(); | 43 __ ret(); |
44 } | 44 } |
45 | 45 |
46 | 46 |
| 47 static Function* CreateFunction(const char* name) { |
| 48 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); |
| 49 Function& function = Function::ZoneHandle( |
| 50 Function::New(function_name, RawFunction::kFunction, true, false, 0)); |
| 51 return &function; |
| 52 } |
| 53 |
| 54 |
47 TEST_CASE(CallRuntimeStubCode) { | 55 TEST_CASE(CallRuntimeStubCode) { |
48 extern const Function& RegisterFakeFunction(const char* name, | 56 extern const Function& RegisterFakeFunction(const char* name, |
49 const Code& code); | 57 const Code& code); |
50 const int value1 = 10; | 58 const int value1 = 10; |
51 const int value2 = 20; | 59 const int value2 = 20; |
52 const char* kName = "Test_CallRuntimeStubCode"; | 60 const char* kName = "Test_CallRuntimeStubCode"; |
53 Assembler _assembler_; | 61 Assembler _assembler_; |
54 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); | 62 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); |
55 const Code& code = Code::Handle( | 63 const Code& code = Code::Handle(Code::FinalizeCode( |
56 Code::FinalizeCode("Test_CallRuntimeStubCode", &_assembler_)); | 64 *CreateFunction("Test_CallRuntimeStubCode"), &_assembler_)); |
57 const Function& function = RegisterFakeFunction(kName, code); | 65 const Function& function = RegisterFakeFunction(kName, code); |
58 GrowableArray<const Object*> arguments; | 66 GrowableArray<const Object*> arguments; |
59 const Array& kNoArgumentNames = Array::Handle(); | 67 const Array& kNoArgumentNames = Array::Handle(); |
60 Smi& result = Smi::Handle(); | 68 Smi& result = Smi::Handle(); |
61 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 69 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
62 EXPECT_EQ((value1 - value2), result.Value()); | 70 EXPECT_EQ((value1 - value2), result.Value()); |
63 } | 71 } |
64 | 72 |
65 | 73 |
66 // Test calls to stub code which calls a native C function. | 74 // Test calls to stub code which calls a native C function. |
(...skipping 26 matching lines...) Expand all Loading... |
93 | 101 |
94 | 102 |
95 TEST_CASE(CallNativeCFunctionStubCode) { | 103 TEST_CASE(CallNativeCFunctionStubCode) { |
96 extern const Function& RegisterFakeFunction(const char* name, | 104 extern const Function& RegisterFakeFunction(const char* name, |
97 const Code& code); | 105 const Code& code); |
98 const int value1 = 15; | 106 const int value1 = 15; |
99 const int value2 = 20; | 107 const int value2 = 20; |
100 const char* kName = "Test_CallNativeCFunctionStubCode"; | 108 const char* kName = "Test_CallNativeCFunctionStubCode"; |
101 Assembler _assembler_; | 109 Assembler _assembler_; |
102 GenerateCallToCallNativeCFunctionStub(&_assembler_, value1, value2); | 110 GenerateCallToCallNativeCFunctionStub(&_assembler_, value1, value2); |
103 const Code& code = Code::Handle( | 111 const Code& code = Code::Handle(Code::FinalizeCode( |
104 Code::FinalizeCode(kName, &_assembler_)); | 112 *CreateFunction(kName), &_assembler_)); |
105 const Function& function = RegisterFakeFunction(kName, code); | 113 const Function& function = RegisterFakeFunction(kName, code); |
106 GrowableArray<const Object*> arguments; | 114 GrowableArray<const Object*> arguments; |
107 const Array& kNoArgumentNames = Array::Handle(); | 115 const Array& kNoArgumentNames = Array::Handle(); |
108 Smi& result = Smi::Handle(); | 116 Smi& result = Smi::Handle(); |
109 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 117 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
110 EXPECT_EQ((value1 - value2), result.Value()); | 118 EXPECT_EQ((value1 - value2), result.Value()); |
111 } | 119 } |
112 | 120 |
113 } // namespace dart | 121 } // namespace dart |
114 | 122 |
115 #endif // defined TARGET_ARCH_X64 | 123 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |