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

Unified Diff: vm/stub_code_ia32_test.cc

Issue 10542123: Add support for leaf runtime calls (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: vm/stub_code_ia32_test.cc
===================================================================
--- vm/stub_code_ia32_test.cc (revision 8520)
+++ vm/stub_code_ia32_test.cc (working copy)
@@ -19,8 +19,16 @@
namespace dart {
DECLARE_RUNTIME_ENTRY(TestSmiSub);
+DECLARE_LEAF_RUNTIME_ENTRY(TestLeafSmiAdd);
+static Function* CreateFunction(const char* name) {
+ const String& function_name = String::ZoneHandle(String::NewSymbol(name));
+ Function& function = Function::ZoneHandle(
+ Function::New(function_name, RawFunction::kFunction, true, false, 0));
+ return &function;
+}
+
// Test calls to stub code which calls into the runtime.
static void GenerateCallToCallRuntimeStub(Assembler* assembler,
int value1, int value2) {
@@ -44,14 +52,6 @@
}
-static Function* CreateFunction(const char* name) {
- const String& function_name = String::ZoneHandle(String::NewSymbol(name));
- Function& function = Function::ZoneHandle(
- Function::New(function_name, RawFunction::kFunction, true, false, 0));
- return &function;
-}
-
-
TEST_CASE(CallRuntimeStubCode) {
extern const Function& RegisterFakeFunction(const char* name,
const Code& code);
@@ -71,6 +71,49 @@
}
+// Test calls to stub code which calls into a leaf runtime entry.
+static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler,
+ int value1,
+ int value2) {
+ const int argc = 2;
+ const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1));
+ const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2));
+ const Object& result = Object::ZoneHandle();
+ const Context& context = Context::ZoneHandle(Context::New(0));
+ ASSERT(context.isolate() == Isolate::Current());
+ __ enter(Immediate(0));
+ __ LoadObject(CTX, context);
+ __ PushObject(result); // Push Null object for return value.
+ __ PushObject(smi1); // Push argument 1 smi1.
+ __ PushObject(smi2); // Push argument 2 smi2.
+ ASSERT(kTestLeafSmiAddRuntimeEntry.argument_count() == argc);
+ __ CallRuntime(kTestLeafSmiAddRuntimeEntry); // Call SmiAdd runtime func.
+ __ AddImmediate(ESP, Immediate(argc * kWordSize));
+ __ popl(EAX); // Pop return value from return slot.
+ __ leave();
+ __ ret();
+}
+
+
+TEST_CASE(CallLeafRuntimeStubCode) {
+ extern const Function& RegisterFakeFunction(const char* name,
+ const Code& code);
+ const int value1 = 10;
+ const int value2 = 20;
+ const char* kName = "Test_CallLeafRuntimeStubCode";
+ Assembler _assembler_;
+ GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2);
+ const Code& code = Code::Handle(Code::FinalizeCode(
+ *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_));
+ const Function& function = RegisterFakeFunction(kName, code);
+ GrowableArray<const Object*> arguments;
+ const Array& kNoArgumentNames = Array::Handle();
+ Smi& result = Smi::Handle();
+ result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames);
+ EXPECT_EQ((value1 + value2), result.Value());
+}
+
+
// Test calls to stub code which calls a native C function.
static void GenerateCallToCallNativeCFunctionStub(Assembler* assembler,
int value1, int value2) {
« vm/stub_code_ia32.cc ('K') | « vm/stub_code_ia32.cc ('k') | vm/stub_code_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698