| 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_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 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" |
| 11 #include "vm/native_entry_test.h" | 11 #include "vm/native_entry_test.h" |
| 12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 #include "vm/runtime_entry.h" | 13 #include "vm/runtime_entry.h" |
| 14 #include "vm/stub_code.h" | 14 #include "vm/stub_code.h" |
| 15 #include "vm/unit_test.h" | 15 #include "vm/unit_test.h" |
| 16 | 16 |
| 17 #define __ assembler-> | 17 #define __ assembler-> |
| 18 | 18 |
| 19 namespace dart { | 19 namespace dart { |
| 20 | 20 |
| 21 DECLARE_RUNTIME_ENTRY(TestSmiSub); | 21 DECLARE_RUNTIME_ENTRY(TestSmiSub); |
| 22 DECLARE_LEAF_RUNTIME_ENTRY(TestLeafSmiAdd); |
| 22 | 23 |
| 23 | 24 |
| 25 static Function* CreateFunction(const char* name) { |
| 26 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); |
| 27 Function& function = Function::ZoneHandle( |
| 28 Function::New(function_name, RawFunction::kFunction, true, false, 0)); |
| 29 return &function; |
| 30 } |
| 31 |
| 24 // Test calls to stub code which calls into the runtime. | 32 // Test calls to stub code which calls into the runtime. |
| 25 static void GenerateCallToCallRuntimeStub(Assembler* assembler, | 33 static void GenerateCallToCallRuntimeStub(Assembler* assembler, |
| 26 int value1, int value2) { | 34 int value1, int value2) { |
| 27 const int argc = 2; | 35 const int argc = 2; |
| 28 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); | 36 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); |
| 29 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); | 37 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); |
| 30 const Object& result = Object::ZoneHandle(); | 38 const Object& result = Object::ZoneHandle(); |
| 31 const Context& context = Context::ZoneHandle(Context::New(0)); | 39 const Context& context = Context::ZoneHandle(Context::New(0)); |
| 32 ASSERT(context.isolate() == Isolate::Current()); | 40 ASSERT(context.isolate() == Isolate::Current()); |
| 33 __ enter(Immediate(0)); | 41 __ enter(Immediate(0)); |
| 34 __ LoadObject(CTX, context); | 42 __ LoadObject(CTX, context); |
| 35 __ PushObject(result); // Push Null object for return value. | 43 __ PushObject(result); // Push Null object for return value. |
| 36 __ PushObject(smi1); // Push argument 1 smi1. | 44 __ PushObject(smi1); // Push argument 1 smi1. |
| 37 __ PushObject(smi2); // Push argument 2 smi2. | 45 __ PushObject(smi2); // Push argument 2 smi2. |
| 38 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc); | 46 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc); |
| 39 __ CallRuntime(kTestSmiSubRuntimeEntry); // Call SmiSub runtime func. | 47 __ CallRuntime(kTestSmiSubRuntimeEntry); // Call SmiSub runtime func. |
| 40 __ AddImmediate(ESP, Immediate(argc * kWordSize)); | 48 __ AddImmediate(ESP, Immediate(argc * kWordSize)); |
| 41 __ popl(EAX); // Pop return value from return slot. | 49 __ popl(EAX); // Pop return value from return slot. |
| 42 __ leave(); | 50 __ leave(); |
| 43 __ ret(); | 51 __ ret(); |
| 44 } | 52 } |
| 45 | 53 |
| 46 | 54 |
| 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 | |
| 55 TEST_CASE(CallRuntimeStubCode) { | 55 TEST_CASE(CallRuntimeStubCode) { |
| 56 extern const Function& RegisterFakeFunction(const char* name, | 56 extern const Function& RegisterFakeFunction(const char* name, |
| 57 const Code& code); | 57 const Code& code); |
| 58 const int value1 = 10; | 58 const int value1 = 10; |
| 59 const int value2 = 20; | 59 const int value2 = 20; |
| 60 const char* kName = "Test_CallRuntimeStubCode"; | 60 const char* kName = "Test_CallRuntimeStubCode"; |
| 61 Assembler _assembler_; | 61 Assembler _assembler_; |
| 62 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); | 62 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); |
| 63 const Code& code = Code::Handle(Code::FinalizeCode( | 63 const Code& code = Code::Handle(Code::FinalizeCode( |
| 64 *CreateFunction("Test_CallRuntimeStubCode"), &_assembler_)); | 64 *CreateFunction("Test_CallRuntimeStubCode"), &_assembler_)); |
| 65 const Function& function = RegisterFakeFunction(kName, code); | 65 const Function& function = RegisterFakeFunction(kName, code); |
| 66 GrowableArray<const Object*> arguments; | 66 GrowableArray<const Object*> arguments; |
| 67 const Array& kNoArgumentNames = Array::Handle(); | 67 const Array& kNoArgumentNames = Array::Handle(); |
| 68 Smi& result = Smi::Handle(); | 68 Smi& result = Smi::Handle(); |
| 69 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 69 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
| 70 EXPECT_EQ((value1 - value2), result.Value()); | 70 EXPECT_EQ((value1 - value2), result.Value()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 // Test calls to stub code which calls into a leaf runtime entry. |
| 75 static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler, |
| 76 int value1, |
| 77 int value2) { |
| 78 const int argc = 2; |
| 79 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); |
| 80 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); |
| 81 const Object& result = Object::ZoneHandle(); |
| 82 const Context& context = Context::ZoneHandle(Context::New(0)); |
| 83 ASSERT(context.isolate() == Isolate::Current()); |
| 84 __ enter(Immediate(0)); |
| 85 __ LoadObject(CTX, context); |
| 86 __ PushObject(result); // Push Null object for return value. |
| 87 __ PushObject(smi1); // Push argument 1 smi1. |
| 88 __ PushObject(smi2); // Push argument 2 smi2. |
| 89 ASSERT(kTestLeafSmiAddRuntimeEntry.argument_count() == argc); |
| 90 __ CallRuntime(kTestLeafSmiAddRuntimeEntry); // Call SmiAdd runtime func. |
| 91 __ AddImmediate(ESP, Immediate(argc * kWordSize)); |
| 92 __ popl(EAX); // Pop return value from return slot. |
| 93 __ leave(); |
| 94 __ ret(); |
| 95 } |
| 96 |
| 97 |
| 98 TEST_CASE(CallLeafRuntimeStubCode) { |
| 99 extern const Function& RegisterFakeFunction(const char* name, |
| 100 const Code& code); |
| 101 const int value1 = 10; |
| 102 const int value2 = 20; |
| 103 const char* kName = "Test_CallLeafRuntimeStubCode"; |
| 104 Assembler _assembler_; |
| 105 GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2); |
| 106 const Code& code = Code::Handle(Code::FinalizeCode( |
| 107 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); |
| 108 const Function& function = RegisterFakeFunction(kName, code); |
| 109 GrowableArray<const Object*> arguments; |
| 110 const Array& kNoArgumentNames = Array::Handle(); |
| 111 Smi& result = Smi::Handle(); |
| 112 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
| 113 EXPECT_EQ((value1 + value2), result.Value()); |
| 114 } |
| 115 |
| 116 |
| 74 // Test calls to stub code which calls a native C function. | 117 // Test calls to stub code which calls a native C function. |
| 75 static void GenerateCallToCallNativeCFunctionStub(Assembler* assembler, | 118 static void GenerateCallToCallNativeCFunctionStub(Assembler* assembler, |
| 76 int value1, int value2) { | 119 int value1, int value2) { |
| 77 const int argc = 2; | 120 const int argc = 2; |
| 78 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); | 121 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); |
| 79 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); | 122 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); |
| 80 const Object& result = Object::ZoneHandle(); | 123 const Object& result = Object::ZoneHandle(); |
| 81 const String& native_name = String::ZoneHandle(String::New("TestSmiSub")); | 124 const String& native_name = String::ZoneHandle(String::New("TestSmiSub")); |
| 82 Dart_NativeFunction native_function = | 125 Dart_NativeFunction native_function = |
| 83 NativeTestEntry_Lookup(native_name, argc); | 126 NativeTestEntry_Lookup(native_name, argc); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 114 GrowableArray<const Object*> arguments; | 157 GrowableArray<const Object*> arguments; |
| 115 const Array& kNoArgumentNames = Array::Handle(); | 158 const Array& kNoArgumentNames = Array::Handle(); |
| 116 Smi& result = Smi::Handle(); | 159 Smi& result = Smi::Handle(); |
| 117 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 160 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
| 118 EXPECT_EQ((value1 - value2), result.Value()); | 161 EXPECT_EQ((value1 - value2), result.Value()); |
| 119 } | 162 } |
| 120 | 163 |
| 121 } // namespace dart | 164 } // namespace dart |
| 122 | 165 |
| 123 #endif // defined TARGET_ARCH_IA32 | 166 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |