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/code_index_table.h" | |
9 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
10 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
11 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
12 #include "vm/native_entry_test.h" | 11 #include "vm/native_entry_test.h" |
13 #include "vm/object.h" | 12 #include "vm/object.h" |
14 #include "vm/runtime_entry.h" | 13 #include "vm/runtime_entry.h" |
15 #include "vm/stub_code.h" | 14 #include "vm/stub_code.h" |
16 #include "vm/unit_test.h" | 15 #include "vm/unit_test.h" |
17 | 16 |
18 #define __ assembler-> | 17 #define __ assembler-> |
19 | 18 |
20 namespace dart { | 19 namespace dart { |
21 | 20 |
22 DECLARE_RUNTIME_ENTRY(TestSmiSub); | 21 DECLARE_RUNTIME_ENTRY(TestSmiSub); |
23 | 22 |
24 | 23 |
25 // Add function to a class and that class to the class dictionary so that | |
26 // frame walking can be used. | |
27 static const Function& RegisterFakeFunction(const char* name, | |
28 const Code& code) { | |
29 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); | |
30 const Function& function = Function::ZoneHandle( | |
31 Function::New(function_name, RawFunction::kFunction, true, false, 0)); | |
32 Class& cls = Class::ZoneHandle(); | |
33 const Script& script = Script::Handle(); | |
34 cls = Class::New(function_name, script); | |
35 const Array& functions = Array::Handle(Array::New(1)); | |
36 functions.SetAt(0, function); | |
37 cls.SetFunctions(functions); | |
38 Library& lib = Library::Handle(Library::CoreLibrary()); | |
39 lib.AddClass(cls); | |
40 function.SetCode(code); | |
41 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table(); | |
42 ASSERT(code_index_table != NULL); | |
43 code_index_table->AddFunction(function); | |
44 return function; | |
45 } | |
46 | |
47 | |
48 // Test calls to stub code which calls into the runtime. | 24 // Test calls to stub code which calls into the runtime. |
49 static void GenerateCallToCallRuntimeStub(Assembler* assembler, | 25 static void GenerateCallToCallRuntimeStub(Assembler* assembler, |
50 int value1, int value2) { | 26 int value1, int value2) { |
51 const int argc = 2; | 27 const int argc = 2; |
52 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); | 28 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); |
53 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); | 29 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); |
54 const Object& result = Object::ZoneHandle(); | 30 const Object& result = Object::ZoneHandle(); |
55 const Context& context = Context::ZoneHandle(Context::New(0)); | 31 const Context& context = Context::ZoneHandle(Context::New(0)); |
56 ASSERT(context.isolate() == Isolate::Current()); | 32 ASSERT(context.isolate() == Isolate::Current()); |
57 __ enter(Immediate(0)); | 33 __ enter(Immediate(0)); |
(...skipping 11 matching lines...) Expand all Loading... |
69 | 45 |
70 | 46 |
71 TEST_CASE(CallRuntimeStubCode) { | 47 TEST_CASE(CallRuntimeStubCode) { |
72 const int value1 = 10; | 48 const int value1 = 10; |
73 const int value2 = 20; | 49 const int value2 = 20; |
74 const char* kName = "Test_CallRuntimeStubCode"; | 50 const char* kName = "Test_CallRuntimeStubCode"; |
75 Assembler _assembler_; | 51 Assembler _assembler_; |
76 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); | 52 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); |
77 const Code& code = Code::Handle( | 53 const Code& code = Code::Handle( |
78 Code::FinalizeCode("Test_CallRuntimeStubCode", &_assembler_)); | 54 Code::FinalizeCode("Test_CallRuntimeStubCode", &_assembler_)); |
79 const Function& function = RegisterFakeFunction(kName, code); | 55 const Function& function = RuntimeEntry::RegisterFakeFunction(kName, code); |
80 GrowableArray<const Object*> arguments; | 56 GrowableArray<const Object*> arguments; |
81 const Array& kNoArgumentNames = Array::Handle(); | 57 const Array& kNoArgumentNames = Array::Handle(); |
82 Smi& result = Smi::Handle(); | 58 Smi& result = Smi::Handle(); |
83 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 59 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
84 EXPECT_EQ((value1 - value2), result.Value()); | 60 EXPECT_EQ((value1 - value2), result.Value()); |
85 } | 61 } |
86 | 62 |
87 | 63 |
88 // Test calls to stub code which calls a native C function. | 64 // Test calls to stub code which calls a native C function. |
89 static void GenerateCallToCallNativeCFunctionStub(Assembler* assembler, | 65 static void GenerateCallToCallNativeCFunctionStub(Assembler* assembler, |
(...skipping 25 matching lines...) Expand all Loading... |
115 | 91 |
116 | 92 |
117 TEST_CASE(CallNativeCFunctionStubCode) { | 93 TEST_CASE(CallNativeCFunctionStubCode) { |
118 const int value1 = 15; | 94 const int value1 = 15; |
119 const int value2 = 20; | 95 const int value2 = 20; |
120 const char* kName = "Test_CallNativeCFunctionStubCode"; | 96 const char* kName = "Test_CallNativeCFunctionStubCode"; |
121 Assembler _assembler_; | 97 Assembler _assembler_; |
122 GenerateCallToCallNativeCFunctionStub(&_assembler_, value1, value2); | 98 GenerateCallToCallNativeCFunctionStub(&_assembler_, value1, value2); |
123 const Code& code = Code::Handle( | 99 const Code& code = Code::Handle( |
124 Code::FinalizeCode(kName, &_assembler_)); | 100 Code::FinalizeCode(kName, &_assembler_)); |
125 const Function& function = RegisterFakeFunction(kName, code); | 101 const Function& function = RuntimeEntry::RegisterFakeFunction(kName, code); |
126 GrowableArray<const Object*> arguments; | 102 GrowableArray<const Object*> arguments; |
127 const Array& kNoArgumentNames = Array::Handle(); | 103 const Array& kNoArgumentNames = Array::Handle(); |
128 Smi& result = Smi::Handle(); | 104 Smi& result = Smi::Handle(); |
129 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 105 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
130 EXPECT_EQ((value1 - value2), result.Value()); | 106 EXPECT_EQ((value1 - value2), result.Value()); |
131 } | 107 } |
132 | 108 |
133 } // namespace dart | 109 } // namespace dart |
134 | 110 |
135 #endif // defined TARGET_ARCH_IA32 | 111 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |