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

Side by Side Diff: runtime/vm/stub_code_x64_test.cc

Issue 8818001: Add 64-bit stubs to call into the runtime and to call native functions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "vm/globals.h"
6 #if defined(TARGET_ARCH_X64)
7
8 #include "vm/isolate.h"
9 #include "vm/dart_entry.h"
10 #include "vm/native_entry.h"
11 #include "vm/native_entry_test.h"
12 #include "vm/object.h"
13 #include "vm/runtime_entry.h"
14 #include "vm/stub_code.h"
15 #include "vm/unit_test.h"
16
17 #define __ assembler->
18
19 namespace dart {
20
21 DECLARE_RUNTIME_ENTRY(TestSmiSub);
22
23
24 // Test calls to stub code which calls into the runtime.
25 static void GenerateCallToCallRuntimeStub(Assembler* assembler,
26 int value1, int value2) {
27 const int argc = 2;
28 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1));
29 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2));
30 const Object& result = Object::ZoneHandle();
31 const Context& context = Context::ZoneHandle(Context::New(0));
32 ASSERT(context.isolate() == Isolate::Current());
33 __ enter(Immediate(0));
34 __ LoadObject(CTX, context);
35 __ PushObject(result); // Push Null object for return value.
36 __ PushObject(smi1); // Push argument 1 smi1.
37 __ PushObject(smi2); // Push argument 2 smi2.
38 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc);
39 __ CallRuntimeFromStub(kTestSmiSubRuntimeEntry); // Call SmiSub runtime func.
40 __ AddImmediate(RSP, Immediate(argc * kWordSize));
41 __ popq(RAX); // Pop return value from return slot.
42 __ leave();
43 __ ret();
44 }
45
46
47 TEST_CASE(CallRuntimeStubCode) {
48 const int value1 = 10;
49 const int value2 = 20;
50 const char* kName = "Test_CallRuntimeStubCode";
51 Assembler _assembler_;
52 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2);
53 const Code& code = Code::Handle(
54 Code::FinalizeCode("Test_CallRuntimeStubCode", &_assembler_));
55 const Function& function = RuntimeEntry::RegisterFakeFunction(kName, code);
56 GrowableArray<const Object*> arguments;
57 const Array& kNoArgumentNames = Array::Handle();
58 Smi& result = Smi::Handle();
59 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames);
60 EXPECT_EQ((value1 - value2), result.Value());
61 }
62
63
64 // Test calls to stub code which calls a native C function.
65 static void GenerateCallToCallNativeCFunctionStub(Assembler* assembler,
66 int value1, int value2) {
67 const int argc = 2;
68 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1));
69 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2));
70 const Object& result = Object::ZoneHandle();
71 const String& native_name = String::ZoneHandle(String::New("TestSmiSub"));
72 Dart_NativeFunction native_function =
73 NativeTestEntry_Lookup(native_name, argc);
74 const Context& context = Context::ZoneHandle(Context::New(0));
75 ASSERT(context.isolate() == Isolate::Current());
76 __ enter(Immediate(0));
77 __ LoadObject(CTX, context);
78 __ PushObject(smi1); // Push argument 1 smi1.
79 __ PushObject(smi2); // Push argument 2 smi2.
80 __ PushObject(result); // Push Null object for return value.
81 // Pass a pointer to the first argument in RAX.
82 __ leaq(RAX, Address(RSP, 2 * kWordSize));
83 __ movq(RBX, Immediate(reinterpret_cast<uword>(native_function)));
84 __ movq(R10, Immediate(argc));
85 __ call(&StubCode::CallNativeCFunctionLabel());
86 __ popq(RAX); // Pop return value from return slot.
87 __ AddImmediate(RSP, Immediate(argc * kWordSize));
88 __ leave();
89 __ ret();
90 }
91
92
93 TEST_CASE(CallNativeCFunctionStubCode) {
94 const int value1 = 15;
95 const int value2 = 20;
96 const char* kName = "Test_CallNativeCFunctionStubCode";
97 Assembler _assembler_;
98 GenerateCallToCallNativeCFunctionStub(&_assembler_, value1, value2);
99 const Code& code = Code::Handle(
100 Code::FinalizeCode(kName, &_assembler_));
101 const Function& function = RuntimeEntry::RegisterFakeFunction(kName, code);
102 GrowableArray<const Object*> arguments;
103 const Array& kNoArgumentNames = Array::Handle();
104 Smi& result = Smi::Handle();
105 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames);
106 EXPECT_EQ((value1 - value2), result.Value());
107 }
108
109 } // namespace dart
110
111 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698