Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
dart::compiler::ffi::CallbackMarshaller Class Reference

#include <marshaller.h>

Inheritance diagram for dart::compiler::ffi::CallbackMarshaller:
dart::compiler::ffi::BaseMarshaller dart::ZoneAllocated

Public Member Functions

 CallbackMarshaller (Zone *zone, const Function &dart_signature, const FunctionType &c_signature, const NativeCallingConvention &native_calling_convention, const NativeLocations &callback_locs)
 
virtual Representation RepInFfiCall (intptr_t def_index_global) const
 
virtual intptr_t NumDefinitions (intptr_t arg_index) const
 
virtual intptr_t NumReturnDefinitions () const
 
const NativeLocationNativeLocationOfNativeParameter (intptr_t def_index) const
 
dart::Location LocationOfNativeParameter (intptr_t def_index) const
 
- Public Member Functions inherited from dart::compiler::ffi::BaseMarshaller
intptr_t num_args () const
 
intptr_t NumArgumentDefinitions () const
 
virtual intptr_t NumDefinitions (intptr_t arg_index) const
 
virtual intptr_t NumReturnDefinitions () const =0
 
bool ArgumentIndexIsReturn (intptr_t arg_index) const
 
bool DefinitionIndexIsReturn (intptr_t def_index_global) const
 
intptr_t ArgumentIndex (intptr_t def_index_global) const
 
intptr_t FirstDefinitionIndex (intptr_t arg_index) const
 
intptr_t DefinitionInArgument (intptr_t def_index_global, intptr_t arg_index) const
 
intptr_t DefinitionIndex (intptr_t def_index_in_arg, intptr_t arg_index) const
 
const NativeLocationLocation (intptr_t arg_index) const
 
Representation RepInDart (intptr_t arg_index) const
 
virtual Representation RepInFfiCall (intptr_t def_index_global) const
 
void RepsInFfiCall (intptr_t arg_index, GrowableArray< Representation > *out) const
 
bool RequiresBitCast (intptr_t index) const
 
const NativeTypeSignExtendFrom (intptr_t arg_index) const
 
AbstractTypePtr CType (intptr_t arg_index) const
 
AbstractTypePtr DartType (intptr_t arg_index) const
 
bool IsPointerPointer (intptr_t arg_index) const
 
bool IsTypedDataPointer (intptr_t arg_index) const
 
bool IsCompoundPointer (intptr_t arg_index) const
 
bool IsHandleCType (intptr_t arg_index) const
 
bool IsBool (intptr_t arg_index) const
 
bool IsCompoundCType (intptr_t arg_index) const
 
bool IsVoid (intptr_t arg_index) const
 
bool ContainsHandles () const
 
bool contains_varargs () const
 
const Functiondart_signature () const
 
intptr_t dart_signature_params_start_at () const
 
const FunctionTypec_signature () const
 
StringPtr function_name () const
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Static Public Member Functions

static CallbackMarshallerFromFunction (Zone *zone, const Function &function, const char **error)
 

Protected Member Functions

 ~CallbackMarshaller ()
 
- Protected Member Functions inherited from dart::compiler::ffi::BaseMarshaller
bool IsPointerDartType (intptr_t arg_index) const
 
bool IsPointerCType (intptr_t arg_index) const
 
 BaseMarshaller (Zone *zone, const Function &dart_signature, intptr_t dart_signature_params_start_at, const FunctionType &c_signature, const NativeCallingConvention &native_calling_convention)
 
 ~BaseMarshaller ()
 

Protected Attributes

const NativeLocationscallback_locs_
 
- Protected Attributes inherited from dart::compiler::ffi::BaseMarshaller
Zonezone_
 
const Functiondart_signature_
 
const intptr_t dart_signature_params_start_at_
 
const FunctionTypec_signature_
 
const NativeCallingConventionnative_calling_convention_
 

Detailed Description

Definition at line 243 of file marshaller.h.

Constructor & Destructor Documentation

◆ CallbackMarshaller()

dart::compiler::ffi::CallbackMarshaller::CallbackMarshaller ( Zone zone,
const Function dart_signature,
const FunctionType c_signature,
const NativeCallingConvention native_calling_convention,
const NativeLocations callback_locs 
)
inline

Definition at line 249 of file marshaller.h.

254 : BaseMarshaller(zone,
256 /*dart_signature_params_start_at=*/0,
258 native_calling_convention),
259 callback_locs_(callback_locs) {}
BaseMarshaller(Zone *zone, const Function &dart_signature, intptr_t dart_signature_params_start_at, const FunctionType &c_signature, const NativeCallingConvention &native_calling_convention)
Definition: marshaller.h:176
const Function & dart_signature() const
Definition: marshaller.h:168
const FunctionType & c_signature() const
Definition: marshaller.h:172
const NativeLocations & callback_locs_
Definition: marshaller.h:282

◆ ~CallbackMarshaller()

dart::compiler::ffi::CallbackMarshaller::~CallbackMarshaller ( )
inlineprotected

Definition at line 280 of file marshaller.h.

280{}

Member Function Documentation

◆ FromFunction()

CallbackMarshaller * dart::compiler::ffi::CallbackMarshaller::FromFunction ( Zone zone,
const Function function,
const char **  error 
)
static

Definition at line 879 of file marshaller.cc.

881 {
882 DEBUG_ASSERT(function.IsNotTemporaryScopedHandle());
883 const auto& c_signature =
884 FunctionType::ZoneHandle(zone, function.FfiCSignature());
885 const auto native_function_signature =
887 if (*error != nullptr) {
888 return nullptr;
889 }
890 const auto& native_calling_convention =
891 NativeCallingConvention::FromSignature(zone, *native_function_signature);
892 const auto& callback_locs =
894 zone, native_calling_convention.argument_locations(),
895 native_calling_convention.return_location());
896 return new (zone) CallbackMarshaller(
897 zone, function, c_signature, native_calling_convention, callback_locs);
898}
#define DEBUG_ASSERT(cond)
Definition: assert.h:321
static Object & ZoneHandle()
Definition: object.h:419
static NativeLocations & TranslateArgumentLocations(Zone *zone, const NativeLocations &argument_locations, const NativeLocation &return_loc)
Definition: marshaller.cc:759
CallbackMarshaller(Zone *zone, const Function &dart_signature, const FunctionType &c_signature, const NativeCallingConvention &native_calling_convention, const NativeLocations &callback_locs)
Definition: marshaller.h:249
static const NativeCallingConvention & FromSignature(Zone *zone, const NativeFunctionType &signature)
const uint8_t uint32_t uint32_t GError ** error
Dart_NativeFunction function
Definition: fuchsia.cc:51
const NativeFunctionType * NativeFunctionTypeFromFunctionType(Zone *zone, const FunctionType &c_signature, const char **error)
Definition: marshaller.cc:34

◆ LocationOfNativeParameter()

dart::Location dart::compiler::ffi::CallbackMarshaller::LocationOfNativeParameter ( intptr_t  def_index) const
inline

Definition at line 271 of file marshaller.h.

271 {
272 const auto& native_loc = NativeLocationOfNativeParameter(def_index);
273 if (native_loc.IsPointerToMemory()) {
274 return native_loc.AsPointerToMemory().pointer_location().AsLocation();
275 }
276 return native_loc.AsLocation();
277 }
const NativeLocation & NativeLocationOfNativeParameter(intptr_t def_index) const
Definition: marshaller.cc:900

◆ NativeLocationOfNativeParameter()

const NativeLocation & dart::compiler::ffi::CallbackMarshaller::NativeLocationOfNativeParameter ( intptr_t  def_index) const

Definition at line 900 of file marshaller.cc.

901 {
902 const intptr_t arg_index = ArgumentIndex(def_index);
903 if (arg_index == kResultIndex) {
904 const auto& result_loc = Location(arg_index);
905 if (result_loc.IsPointerToMemory()) {
906 // If it's a pointer we return it in the last.
907 return *callback_locs_.At(callback_locs_.length() - 1);
908 }
909 // The other return types are not translated.
910 return result_loc;
911 }
912
913 // Check that we only have stack arguments.
914 const auto& loc = *callback_locs_.At(arg_index);
915 ASSERT(loc.IsStack() || loc.IsPointerToMemory() || loc.IsMultiple());
916 if (loc.IsStack()) {
917 ASSERT(loc.AsStack().base_register() == SPREG);
918 if (loc.payload_type().IsPrimitive()) {
919 return loc;
920 }
921 const intptr_t index = DefinitionInArgument(def_index, arg_index);
922 const intptr_t count = NumDefinitions(arg_index);
923 return loc.Split(zone_, count, index);
924 } else if (loc.IsPointerToMemory()) {
925 const auto& pointer_loc = loc.AsPointerToMemory().pointer_location();
926 ASSERT(pointer_loc.IsStack() &&
927 pointer_loc.AsStack().base_register() == SPREG);
928 return loc;
929 }
930 const auto& multiple = loc.AsMultiple();
931 const intptr_t index = DefinitionInArgument(def_index, arg_index);
932 const auto& multi_loc = *multiple.locations().At(index);
933 ASSERT(multi_loc.IsStack() && multi_loc.AsStack().base_register() == SPREG);
934 return multi_loc;
935}
int count
Definition: FontMgrTest.cpp:50
const T & At(intptr_t index) const
intptr_t length() const
intptr_t ArgumentIndex(intptr_t def_index_global) const
Definition: marshaller.cc:367
const NativeLocation & Location(intptr_t arg_index) const
Definition: marshaller.h:71
intptr_t DefinitionInArgument(intptr_t def_index_global, intptr_t arg_index) const
Definition: marshaller.cc:397
virtual intptr_t NumDefinitions(intptr_t arg_index) const
Definition: marshaller.cc:306
#define ASSERT(E)
const intptr_t kResultIndex
Definition: marshaller.h:28
const Register SPREG

◆ NumDefinitions()

intptr_t dart::compiler::ffi::CallbackMarshaller::NumDefinitions ( intptr_t  arg_index) const
virtual

Reimplemented from dart::compiler::ffi::BaseMarshaller.

Definition at line 306 of file marshaller.cc.

306 {
307 if (!ArgumentIndexIsReturn(arg_index)) {
308 const auto& loc = Location(arg_index);
309 const auto& type = loc.payload_type();
310 if (type.IsCompound() && loc.IsPointerToMemory()) {
311 // For FFI callbacks, get the pointer in a NativeParameter and construct
312 // the TypedDataBase in IL (always offset in bytes 0).
313 return 1;
314 }
315 }
316 return BaseMarshaller::NumDefinitions(arg_index);
317}
GLenum type
bool ArgumentIndexIsReturn(intptr_t arg_index) const
Definition: marshaller.cc:357
virtual intptr_t NumDefinitions(intptr_t arg_index) const
Definition: marshaller.cc:257

◆ NumReturnDefinitions()

intptr_t dart::compiler::ffi::CallbackMarshaller::NumReturnDefinitions ( ) const
virtual

Implements dart::compiler::ffi::BaseMarshaller.

Definition at line 331 of file marshaller.cc.

331 {
332 const auto& loc = Location(kResultIndex);
333
334 if (loc.IsMultiple()) {
335 const auto& type = loc.payload_type();
336 ASSERT(type.IsCompound());
337 // For multiple locations, some native locations cannot be expressed as
338 // Locations, which means the flow graph builder cannot generate appropriate
339 // IL for those cases.
340 //
341 // Instead, the flow graph builder generates IL to extract the
342 // _typedDataBase and _offsetInBytes fields of the Dart value and passes
343 // those into the NativeReturn instruction as separate arguments. The
344 // generated machine code for the NativeReturn instruction then
345 // appropriately copies the contents to a non-GC-managed block of memory. A
346 // pointer to that block of memory is returned to the C code.
347 return 2;
348 }
349
350 // If it's a compound and the native ABI is passing a pointer, copy to it in
351 // IL. If non-compound, also 1 definition. If it's a primitive, the flow graph
352 // builder generates IL to create an appropriate Dart value from the single
353 // value returned from C.
354 return 1;
355}

◆ RepInFfiCall()

Representation dart::compiler::ffi::CallbackMarshaller::RepInFfiCall ( intptr_t  def_index_global) const
virtual

Reimplemented from dart::compiler::ffi::BaseMarshaller.

Definition at line 523 of file marshaller.cc.

524 {
525 intptr_t arg_index = ArgumentIndex(def_index_global);
526 if (IsHandleCType(arg_index)) {
527 // Dart objects are passed to C as untagged pointers to newly created
528 // handles in the IL, and the ptr field of untagged pointers to handles are
529 // extracted when the IL receives handles from C code.
530 return kUntagged;
531 }
532 const auto& location = Location(arg_index);
533 if (location.IsPointerToMemory()) {
534 // The IL gets an untagged pointer to memory both for arguments and for
535 // returns. If this is an argument, then the IL creates a Dart
536 // representation of the compound object from the pointed at memory.
537 // For returns, the IL copies the data from the compound object into
538 // the memory being pointed at before returning to C.
539 return kUntagged;
540 }
541 if (ArgumentIndexIsReturn(arg_index) && location.IsMultiple()) {
542 // To return a compound object broken up over multiple native locations,
543 // the IL loads the compound object into a single TypedData object and
544 // passes that TypedData object to NativeReturn, which handles extracting
545 // the data to the appropriate native locations.
546 return kTagged;
547 }
548 return BaseMarshaller::RepInFfiCall(def_index_global);
549}
virtual Representation RepInFfiCall(intptr_t def_index_global) const
Definition: marshaller.cc:444
bool IsHandleCType(intptr_t arg_index) const
Definition: marshaller.cc:229

Member Data Documentation

◆ callback_locs_

const NativeLocations& dart::compiler::ffi::CallbackMarshaller::callback_locs_
protected

Definition at line 282 of file marshaller.h.


The documentation for this class was generated from the following files: