Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
dart::compiler::ffi::BaseMarshaller Class Referenceabstract

#include <marshaller.h>

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

Public Member Functions

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)
 

Protected Member Functions

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

Zonezone_
 
const Functiondart_signature_
 
const intptr_t dart_signature_params_start_at_
 
const FunctionTypec_signature_
 
const NativeCallingConventionnative_calling_convention_
 

Detailed Description

Definition at line 42 of file marshaller.h.

Constructor & Destructor Documentation

◆ BaseMarshaller()

dart::compiler::ffi::BaseMarshaller::BaseMarshaller ( Zone zone,
const Function dart_signature,
intptr_t  dart_signature_params_start_at,
const FunctionType c_signature,
const NativeCallingConvention native_calling_convention 
)
inlineprotected

Definition at line 176 of file marshaller.h.

181 : zone_(zone),
185 native_calling_convention_(native_calling_convention) {}
const Function & dart_signature() const
Definition marshaller.h:168
const FunctionType & c_signature() const
Definition marshaller.h:172
intptr_t dart_signature_params_start_at() const
Definition marshaller.h:169
const NativeCallingConvention & native_calling_convention_
Definition marshaller.h:195
const FunctionType & c_signature_
Definition marshaller.h:194
const intptr_t dart_signature_params_start_at_
Definition marshaller.h:193

◆ ~BaseMarshaller()

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

Definition at line 187 of file marshaller.h.

187{}

Member Function Documentation

◆ ArgumentIndex()

intptr_t dart::compiler::ffi::BaseMarshaller::ArgumentIndex ( intptr_t  def_index_global) const

Definition at line 367 of file marshaller.cc.

367 {
368 if (DefinitionIndexIsReturn(def_index_global)) {
369 const intptr_t def = DefinitionInArgument(def_index_global, kResultIndex);
371 return kResultIndex;
372 }
373 ASSERT(def_index_global < NumArgumentDefinitions());
374 intptr_t defs = 0;
375 intptr_t arg_index = 0;
376 for (; arg_index < num_args(); arg_index++) {
377 defs += NumDefinitions(arg_index);
378 if (defs > def_index_global) {
379 return arg_index;
380 }
381 }
382 UNREACHABLE();
383}
#define UNREACHABLE()
Definition assert.h:248
bool DefinitionIndexIsReturn(intptr_t def_index_global) const
virtual intptr_t NumReturnDefinitions() const =0
virtual intptr_t NumDefinitions(intptr_t arg_index) const
intptr_t DefinitionInArgument(intptr_t def_index_global, intptr_t arg_index) const
#define ASSERT(E)
const intptr_t kResultIndex
Definition marshaller.h:28

◆ ArgumentIndexIsReturn()

bool dart::compiler::ffi::BaseMarshaller::ArgumentIndexIsReturn ( intptr_t  arg_index) const

Definition at line 357 of file marshaller.cc.

357 {
358 ASSERT(arg_index == kResultIndex || arg_index >= 0);
359 return arg_index == kResultIndex;
360}

◆ c_signature()

const FunctionType & dart::compiler::ffi::BaseMarshaller::c_signature ( ) const
inline

Definition at line 172 of file marshaller.h.

172{ return c_signature_; }

◆ contains_varargs()

bool dart::compiler::ffi::BaseMarshaller::contains_varargs ( ) const
inline

Definition at line 159 of file marshaller.h.

◆ ContainsHandles()

bool dart::compiler::ffi::BaseMarshaller::ContainsHandles ( ) const

Definition at line 245 of file marshaller.cc.

245 {
247}
bool ContainsHandles() const
Definition object.cc:8350

◆ CType()

AbstractTypePtr dart::compiler::ffi::BaseMarshaller::CType ( intptr_t  arg_index) const

Definition at line 108 of file marshaller.cc.

108 {
109 if (arg_index == kResultIndex) {
110 return c_signature_.result_type();
111 }
112
113 Zone* zone = Thread::Current()->zone();
114 const auto& parameter_types =
116 const intptr_t parameter_type_length = parameter_types.Length();
117 const intptr_t last_param_index = parameter_type_length - 1;
118 const auto& last_arg_type = AbstractType::Handle(
119 zone, c_signature_.ParameterTypeAt(last_param_index));
120 ObjectStore* object_store = IsolateGroup::Current()->object_store();
121 const bool has_varargs =
122 last_arg_type.type_class() == object_store->varargs_class();
123
124 // Skip #0 argument, the function pointer.
125 const intptr_t real_arg_index = arg_index + kNativeParamsStartAt;
126
127 if (has_varargs && real_arg_index >= last_param_index) {
128 // The C-type is nested in a VarArgs.
129 const auto& var_args_type_arg = AbstractType::Handle(
130 zone, TypeArguments::Handle(zone, Type::Cast(last_arg_type).arguments())
131 .TypeAt(0));
132 if (var_args_type_arg.IsRecordType()) {
133 const intptr_t index_in_record = real_arg_index - last_param_index;
134 const auto& record_type = RecordType::Cast(var_args_type_arg);
135 ASSERT(index_in_record < record_type.NumFields());
136 return record_type.FieldTypeAt(index_in_record);
137 } else {
138 ASSERT(!var_args_type_arg.IsNull());
139 return var_args_type_arg.ptr();
140 }
141 }
142
144 .IsNull());
145 return c_signature_.ParameterTypeAt(real_arg_index);
146}
AbstractTypePtr ParameterTypeAt(intptr_t index) const
Definition object.cc:8643
AbstractTypePtr result_type() const
Definition object.h:9650
ArrayPtr parameter_types() const
Definition object.h:9658
ObjectStore * object_store() const
Definition isolate.h:505
static IsolateGroup * Current()
Definition isolate.h:534
bool IsNull() const
Definition object.h:363
static Object & Handle()
Definition object.h:407
Zone * zone() const
static Thread * Current()
Definition thread.h:361
const intptr_t kNativeParamsStartAt
Definition marshaller.cc:31

◆ dart_signature()

const Function & dart::compiler::ffi::BaseMarshaller::dart_signature ( ) const
inline

Definition at line 168 of file marshaller.h.

168{ return dart_signature_; }

◆ dart_signature_params_start_at()

intptr_t dart::compiler::ffi::BaseMarshaller::dart_signature_params_start_at ( ) const
inline

Definition at line 169 of file marshaller.h.

169 {
171 }

◆ DartType()

AbstractTypePtr dart::compiler::ffi::BaseMarshaller::DartType ( intptr_t  arg_index) const

Definition at line 148 of file marshaller.cc.

148 {
149 if (arg_index == kResultIndex) {
151 }
152 const intptr_t real_arg_index = arg_index + dart_signature_params_start_at_;
154 ASSERT(real_arg_index <
157 .IsNull());
158 return dart_signature_.ParameterTypeAt(real_arg_index);
159}
ArrayPtr parameter_types() const
Definition object.h:3087
AbstractTypePtr ParameterTypeAt(intptr_t index) const
Definition object.cc:8638
AbstractTypePtr result_type() const
Definition object.h:3079

◆ DefinitionInArgument()

intptr_t dart::compiler::ffi::BaseMarshaller::DefinitionInArgument ( intptr_t  def_index_global,
intptr_t  arg_index 
) const

Definition at line 397 of file marshaller.cc.

398 {
399 if (ArgumentIndexIsReturn(arg_index)) {
400 // Counting down for return definitions.
401 const intptr_t def = kResultIndex - def_index_global;
403 return def;
404 } else {
405 // Counting up for arguments in consecutive order.
406 const intptr_t def = def_index_global - FirstDefinitionIndex(arg_index);
408 return def;
409 }
410}
bool ArgumentIndexIsReturn(intptr_t arg_index) const
intptr_t FirstDefinitionIndex(intptr_t arg_index) const

◆ DefinitionIndex()

intptr_t dart::compiler::ffi::BaseMarshaller::DefinitionIndex ( intptr_t  def_index_in_arg,
intptr_t  arg_index 
) const

Definition at line 412 of file marshaller.cc.

413 {
414 ASSERT(def_index_in_arg < NumDefinitions(arg_index));
415 if (ArgumentIndexIsReturn(arg_index)) {
416 return kResultIndex - def_index_in_arg;
417 } else {
418 return FirstDefinitionIndex(arg_index) + def_index_in_arg;
419 }
420}

◆ DefinitionIndexIsReturn()

bool dart::compiler::ffi::BaseMarshaller::DefinitionIndexIsReturn ( intptr_t  def_index_global) const

Definition at line 363 of file marshaller.cc.

363 {
364 return def_index_global <= kResultIndex;
365}

◆ FirstDefinitionIndex()

intptr_t dart::compiler::ffi::BaseMarshaller::FirstDefinitionIndex ( intptr_t  arg_index) const

Definition at line 385 of file marshaller.cc.

385 {
386 if (arg_index <= kResultIndex) {
387 return kResultIndex;
388 }
389 ASSERT(arg_index < num_args());
390 intptr_t num_defs = 0;
391 for (intptr_t i = 0; i < arg_index; i++) {
392 num_defs += NumDefinitions(i);
393 }
394 return num_defs;
395}

◆ function_name()

StringPtr dart::compiler::ffi::BaseMarshaller::function_name ( ) const
inline

Definition at line 173 of file marshaller.h.

173{ return dart_signature_.name(); }
StringPtr name() const
Definition object.h:2972

◆ IsBool()

bool dart::compiler::ffi::BaseMarshaller::IsBool ( intptr_t  arg_index) const

Definition at line 234 of file marshaller.cc.

234 {
235 return AbstractType::Handle(zone_, CType(arg_index)).type_class_id() ==
236 kFfiBoolCid;
237}
AbstractTypePtr CType(intptr_t arg_index) const

◆ IsCompoundCType()

bool dart::compiler::ffi::BaseMarshaller::IsCompoundCType ( intptr_t  arg_index) const

Definition at line 240 of file marshaller.cc.

240 {
241 const auto& c_type = AbstractType::Handle(zone_, CType(arg_index));
242 return IsCompound(this->zone_, c_type);
243}
static bool IsCompound(Zone *zone, const AbstractType &type)

◆ IsCompoundPointer()

bool dart::compiler::ffi::BaseMarshaller::IsCompoundPointer ( intptr_t  arg_index) const

Definition at line 215 of file marshaller.cc.

215 {
216 if (!IsPointerCType(arg_index)) {
217 return false;
218 }
220 // TODO(https://dartbug.com/54173): BuildGraphOfSyncFfiCallback provides a
221 // function object with its type arguments not initialized.
222 return false;
223 }
224
225 const auto& dart_type = AbstractType::Handle(zone_, DartType(arg_index));
226 return IsCompound(this->zone_, dart_type);
227}
static ObjectPtr null()
Definition object.h:433
bool IsPointerCType(intptr_t arg_index) const
AbstractTypePtr DartType(intptr_t arg_index) const

◆ IsHandleCType()

bool dart::compiler::ffi::BaseMarshaller::IsHandleCType ( intptr_t  arg_index) const

Definition at line 229 of file marshaller.cc.

229 {
230 return AbstractType::Handle(zone_, CType(arg_index)).type_class_id() ==
231 kFfiHandleCid;
232}

◆ IsPointerCType()

bool dart::compiler::ffi::BaseMarshaller::IsPointerCType ( intptr_t  arg_index) const
protected

Definition at line 161 of file marshaller.cc.

161 {
162 return AbstractType::Handle(zone_, CType(arg_index)).type_class_id() ==
163 kPointerCid;
164}

◆ IsPointerDartType()

bool dart::compiler::ffi::BaseMarshaller::IsPointerDartType ( intptr_t  arg_index) const
protected

Definition at line 166 of file marshaller.cc.

166 {
167 return AbstractType::Handle(zone_, DartType(arg_index)).type_class_id() ==
168 kPointerCid;
169}

◆ IsPointerPointer()

bool dart::compiler::ffi::BaseMarshaller::IsPointerPointer ( intptr_t  arg_index) const

Definition at line 171 of file marshaller.cc.

171 {
173 // TODO(https://dartbug.com/54173): BuildGraphOfSyncFfiCallback provides a
174 // function object with its type arguments not initialized.
175 return IsPointerCType(arg_index);
176 }
177 return IsPointerDartType(arg_index) && IsPointerCType(arg_index);
178}
bool IsPointerDartType(intptr_t arg_index) const

◆ IsTypedDataPointer()

bool dart::compiler::ffi::BaseMarshaller::IsTypedDataPointer ( intptr_t  arg_index) const

Definition at line 180 of file marshaller.cc.

180 {
181 if (!IsPointerCType(arg_index)) {
182 return false;
183 }
184 if (IsHandleCType(arg_index)) {
185 return false;
186 }
187
189 // TODO(https://dartbug.com/54173): BuildGraphOfSyncFfiCallback provides a
190 // function object with its type arguments not initialized. Change this
191 // to an assert when addressing that issue.
192 return false;
193 }
194
195 const auto& type = AbstractType::Handle(zone_, DartType(arg_index));
196 return type.type_class() ==
198}
const Class & TypedDataClass()
ObjectPtr ptr() const
Definition object.h:332
CompilerState & compiler_state()
Definition thread.h:583
bool IsHandleCType(intptr_t arg_index) const

◆ IsVoid()

bool dart::compiler::ffi::BaseMarshaller::IsVoid ( intptr_t  arg_index) const
inline

Definition at line 152 of file marshaller.h.

152 {
153 return AbstractType::Handle(zone_, CType(arg_index)).type_class_id() ==
154 kFfiVoidCid;
155 }

◆ Location()

const NativeLocation & dart::compiler::ffi::BaseMarshaller::Location ( intptr_t  arg_index) const
inline

Definition at line 71 of file marshaller.h.

71 {
72 if (arg_index == kResultIndex) {
74 }
76 }
const T & At(intptr_t index) const

◆ num_args()

intptr_t dart::compiler::ffi::BaseMarshaller::num_args ( ) const
inline

Definition at line 44 of file marshaller.h.

◆ NumArgumentDefinitions()

intptr_t dart::compiler::ffi::BaseMarshaller::NumArgumentDefinitions ( ) const

Definition at line 249 of file marshaller.cc.

249 {
250 intptr_t total = 0;
251 for (intptr_t i = 0; i < num_args(); i++) {
252 total += NumDefinitions(i);
253 }
254 return total;
255}

◆ NumDefinitions()

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

Reimplemented in dart::compiler::ffi::CallMarshaller, and dart::compiler::ffi::CallbackMarshaller.

Definition at line 257 of file marshaller.cc.

257 {
258 if (ArgumentIndexIsReturn(arg_index)) {
259 return NumReturnDefinitions();
260 }
261
262 const auto& loc = Location(arg_index);
263 const auto& type = loc.payload_type();
264
265 if (IsCompoundPointer(arg_index)) {
266 // typed data base and offset.
267 return 2;
268 }
269 if (type.IsPrimitive()) {
270 // All non-struct arguments are 1 definition in IL. Even 64 bit values
271 // on 32 bit architectures.
272 return 1;
273 }
274
275 ASSERT(type.IsCompound());
276 ASSERT(!loc.IsPointerToMemory()); // Handled in overrides.
277 if (loc.IsMultiple()) {
278 // One IL definition for every nested location.
279 const auto& multiple = loc.AsMultiple();
280 return multiple.locations().length();
281 }
282
283 ASSERT(loc.IsStack());
284 // For stack, word size definitions in IL. In FFI calls passed into the
285 // native call, in FFI callbacks read in separate NativeParams.
286 const intptr_t size_in_bytes = type.SizeInBytes();
287 const intptr_t num_defs =
288 Utils::RoundUp(size_in_bytes, compiler::target::kWordSize) /
289 compiler::target::kWordSize;
290 return num_defs;
291}
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
Definition utils.h:105
bool IsCompoundPointer(intptr_t arg_index) const

◆ NumReturnDefinitions()

virtual intptr_t dart::compiler::ffi::BaseMarshaller::NumReturnDefinitions ( ) const
pure virtual

◆ RepInDart()

Representation dart::compiler::ffi::BaseMarshaller::RepInDart ( intptr_t  arg_index) const

Definition at line 434 of file marshaller.cc.

434 {
435 // This should never be called on Pointers or Handles, which are specially
436 // handled during marshalling/unmarshalling.
437 ASSERT(!IsHandleCType(arg_index));
438 ASSERT(!IsPointerPointer(arg_index));
439 return Location(arg_index).payload_type().AsRepresentationOverApprox(zone_);
440}
bool IsPointerPointer(intptr_t arg_index) const

◆ RepInFfiCall()

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

Reimplemented in dart::compiler::ffi::CallMarshaller, and dart::compiler::ffi::CallbackMarshaller.

Definition at line 444 of file marshaller.cc.

444 {
445 intptr_t arg_index = ArgumentIndex(def_index_global);
446
447 // Handled appropriately in the subclasses.
448 ASSERT(!IsHandleCType(arg_index));
449
450 // The IL extracts the address stored in the Pointer object as an untagged
451 // pointer before passing it to C, and creates a new Pointer object to store
452 // the received untagged pointer when receiving a pointer from C.
453 if (IsPointerPointer(arg_index)) return kUntagged;
454
455 const auto& location = Location(arg_index);
456 if (location.container_type().IsPrimitive()) {
457 return SelectRepresentationInIL(zone_, location);
458 }
459 ASSERT(location.container_type().IsCompound());
460
461 if (location.IsStack()) {
462 // Split the struct in architecture size chunks.
463 return kUnboxedWord;
464 }
465
466 if (location.IsMultiple()) {
467 const intptr_t def_index_in_arg =
468 DefinitionInArgument(def_index_global, arg_index);
469 const auto& def_loc =
470 *(location.AsMultiple().locations()[def_index_in_arg]);
471 return SelectRepresentationInIL(zone_, def_loc);
472 }
473
474 UNREACHABLE(); // Implemented in subclasses.
475}
intptr_t ArgumentIndex(intptr_t def_index_global) const
static Representation SelectRepresentationInIL(Zone *zone, const NativeLocation &location)
static constexpr Representation kUnboxedWord
Definition locations.h:164

◆ RepsInFfiCall()

void dart::compiler::ffi::BaseMarshaller::RepsInFfiCall ( intptr_t  arg_index,
GrowableArray< Representation > *  out 
) const

Definition at line 551 of file marshaller.cc.

552 {
553 const intptr_t num_definitions = NumDefinitions(arg_index);
554 const intptr_t first_def = FirstDefinitionIndex(arg_index);
555 for (int i = 0; i < num_definitions; i++) {
556 out->Add(RepInFfiCall(first_def + i));
557 }
558}
virtual Representation RepInFfiCall(intptr_t def_index_global) const

◆ RequiresBitCast()

bool dart::compiler::ffi::BaseMarshaller::RequiresBitCast ( intptr_t  index) const
inline

Definition at line 92 of file marshaller.h.

92 {
93 return Location(index).payload_type().IsFloat() &&
94 Location(index).container_type().IsInt();
95 }

◆ SignExtendFrom()

const NativeType & dart::compiler::ffi::BaseMarshaller::SignExtendFrom ( intptr_t  arg_index) const
inline

Definition at line 98 of file marshaller.h.

98 {
99 return Location(arg_index).payload_type();
100 }

Member Data Documentation

◆ c_signature_

const FunctionType& dart::compiler::ffi::BaseMarshaller::c_signature_
protected

Definition at line 194 of file marshaller.h.

◆ dart_signature_

const Function& dart::compiler::ffi::BaseMarshaller::dart_signature_
protected

Definition at line 192 of file marshaller.h.

◆ dart_signature_params_start_at_

const intptr_t dart::compiler::ffi::BaseMarshaller::dart_signature_params_start_at_
protected

Definition at line 193 of file marshaller.h.

◆ native_calling_convention_

const NativeCallingConvention& dart::compiler::ffi::BaseMarshaller::native_calling_convention_
protected

Definition at line 195 of file marshaller.h.

◆ zone_

Zone* dart::compiler::ffi::BaseMarshaller::zone_
protected

Definition at line 189 of file marshaller.h.


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