| 1 | // Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file |
|---|---|
| 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. |
| 4 | |
| 5 | #ifndef RUNTIME_VM_COMPILER_FFI_NATIVE_CALLING_CONVENTION_H_ |
| 6 | #define RUNTIME_VM_COMPILER_FFI_NATIVE_CALLING_CONVENTION_H_ |
| 7 | |
| 8 | #if defined(DART_PRECOMPILED_RUNTIME) |
| 9 | #error "AOT runtime should not use compiler sources (including header files)" |
| 10 | #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 11 | |
| 12 | #include "platform/globals.h" |
| 13 | #include "vm/compiler/ffi/native_location.h" |
| 14 | #include "vm/compiler/ffi/native_type.h" |
| 15 | |
| 16 | namespace dart { |
| 17 | |
| 18 | namespace compiler { |
| 19 | |
| 20 | namespace ffi { |
| 21 | |
| 22 | using NativeLocations = ZoneGrowableArray<const NativeLocation*>; |
| 23 | |
| 24 | // Calculates native calling convention, is not aware of Dart calling |
| 25 | // convention constraints. |
| 26 | // |
| 27 | // This class is meant to be embedded in a class that is aware of Dart calling |
| 28 | // convention constraints. |
| 29 | class NativeCallingConvention : public ZoneAllocated { |
| 30 | public: |
| 31 | static const NativeCallingConvention& FromSignature( |
| 32 | Zone* zone, |
| 33 | const NativeFunctionType& signature); |
| 34 | |
| 35 | const NativeLocations& argument_locations() const { |
| 36 | return argument_locations_; |
| 37 | } |
| 38 | const NativeLocation& return_location() const { return return_location_; } |
| 39 | bool contains_varargs() const { return contains_varargs_; } |
| 40 | |
| 41 | intptr_t StackTopInBytes() const; |
| 42 | |
| 43 | void PrintTo(BaseTextBuffer* f, bool multi_line = false) const; |
| 44 | void PrintToMultiLine(BaseTextBuffer* f) const; |
| 45 | const char* ToCString(Zone* zone, bool multi_line = false) const; |
| 46 | #if !defined(FFI_UNIT_TESTS) |
| 47 | const char* ToCString(bool multi_line = false) const; |
| 48 | #endif |
| 49 | |
| 50 | private: |
| 51 | NativeCallingConvention(const NativeLocations& argument_locations, |
| 52 | const NativeLocation& return_location, |
| 53 | bool contains_varargs) |
| 54 | : argument_locations_(argument_locations), |
| 55 | return_location_(return_location), |
| 56 | contains_varargs_(contains_varargs) {} |
| 57 | |
| 58 | const NativeLocations& argument_locations_; |
| 59 | const NativeLocation& return_location_; |
| 60 | const bool contains_varargs_; |
| 61 | }; |
| 62 | |
| 63 | } // namespace ffi |
| 64 | |
| 65 | } // namespace compiler |
| 66 | |
| 67 | } // namespace dart |
| 68 | |
| 69 | #endif // RUNTIME_VM_COMPILER_FFI_NATIVE_CALLING_CONVENTION_H_ |
| 70 |
