2012-01-16 12:28:10 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 05:20:07 +00:00
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef VM_NATIVE_ARGUMENTS_H_
|
|
|
|
#define VM_NATIVE_ARGUMENTS_H_
|
|
|
|
|
2012-01-16 12:28:10 +00:00
|
|
|
#include "platform/assert.h"
|
|
|
|
#include "vm/globals.h"
|
2012-06-25 17:35:20 +00:00
|
|
|
#include "vm/stub_code.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
|
|
|
// Forward declarations.
|
2011-11-12 05:55:22 +00:00
|
|
|
class Isolate;
|
2011-10-05 05:20:07 +00:00
|
|
|
class Object;
|
|
|
|
class RawObject;
|
|
|
|
|
|
|
|
|
2012-06-25 17:35:20 +00:00
|
|
|
#if defined(TESTING) || defined(DEBUG)
|
|
|
|
|
|
|
|
#if defined(TARGET_OS_WINDOWS)
|
|
|
|
// The compiler may dynamically align the stack on Windows, so do not check.
|
|
|
|
#define CHECK_STACK_ALIGNMENT { }
|
|
|
|
#else
|
|
|
|
#define CHECK_STACK_ALIGNMENT { \
|
|
|
|
uword (*func)() = \
|
|
|
|
reinterpret_cast<uword (*)()>(StubCode::GetStackPointerEntryPoint()); \
|
|
|
|
uword current_sp = func(); \
|
|
|
|
ASSERT((OS::ActivationFrameAlignment() == 0) || \
|
|
|
|
(Utils::IsAligned(current_sp, OS::ActivationFrameAlignment()))); \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define CHECK_STACK_ALIGNMENT { }
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
// Class NativeArguments is used to access arguments passed in from
|
|
|
|
// generated dart code to a runtime function or a dart library native
|
|
|
|
// function. It is also used to set the return value if any at the slot
|
|
|
|
// reserved for return values.
|
|
|
|
// All runtime function/dart library native functions have the
|
|
|
|
// following signature:
|
|
|
|
// void function_name(NativeArguments arguments);
|
|
|
|
// Inside the function, arguments are accessed as follows:
|
|
|
|
// const Type& arg1 = Type::CheckedHandle(arguments.GetArgument(0));
|
|
|
|
// const Type& arg2 = Type::CheckedHandle(arguments.GetArgument(1));
|
|
|
|
// The return value is set as follows:
|
2012-03-12 23:51:03 +00:00
|
|
|
// arguments.SetReturn(result);
|
2011-10-05 05:20:07 +00:00
|
|
|
// NOTE: Since we pass this as a pass by value argument in the stubs we don't
|
|
|
|
// have DISALLOW_COPY_AND_ASSIGN in the class definition and do not make it a
|
|
|
|
// subclass of ValueObject.
|
|
|
|
class NativeArguments {
|
|
|
|
public:
|
2011-11-12 05:55:22 +00:00
|
|
|
Isolate* isolate() const { return isolate_; }
|
2011-10-05 05:20:07 +00:00
|
|
|
int Count() const { return argc_; }
|
|
|
|
|
|
|
|
RawObject* At(int index) const {
|
|
|
|
ASSERT(index >=0 && index < argc_);
|
|
|
|
return (*argv_)[-index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetReturn(const Object& value) const;
|
|
|
|
|
2011-11-12 05:55:22 +00:00
|
|
|
static intptr_t isolate_offset() {
|
|
|
|
return OFFSET_OF(NativeArguments, isolate_);
|
|
|
|
}
|
2011-10-05 05:20:07 +00:00
|
|
|
static intptr_t argc_offset() { return OFFSET_OF(NativeArguments, argc_); }
|
|
|
|
static intptr_t argv_offset() { return OFFSET_OF(NativeArguments, argv_); }
|
|
|
|
static intptr_t retval_offset() {
|
|
|
|
return OFFSET_OF(NativeArguments, retval_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-11-12 05:55:22 +00:00
|
|
|
Isolate* isolate_; // Current isolate pointer.
|
2011-10-05 05:20:07 +00:00
|
|
|
int argc_; // Number of arguments passed to the runtime call.
|
|
|
|
RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call.
|
|
|
|
RawObject** retval_; // Pointer to the return value area.
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dart
|
|
|
|
|
|
|
|
#endif // VM_NATIVE_ARGUMENTS_H_
|