Node:Restrictions on foreign declarations, Next:, Previous:Interfacing to other languages, Up:Interfacing to other languages



Restrictions on foreign declarations

Any subprogram can be imported. GHDL puts no restrictions on foreign subprograms. However, the representation of a type or of an interface in a foreign language may be obscur. Most of non-composite types are easily imported:

integer types
They are represented on a 32 bits word. This generally corresponds to int for C or Integer for Ada.
physical types
They are represented on a 64 bits word. This generally corresponds to the long long for C or Long_Long_Integer for Ada.
floating point types
They are represented on a 64 bits floating point word. This generally corresponds to double for C or Long_Float for Ada.
enumeration types
They are represented on 8 bits or 32 bits word, if the number of literals is greater than 256. There is no corresponding C types, since arguments are not promoted.

Non-composite types are passed by value. For the in mode, this corresponds to the C or Ada mechanism. The out and inout interfaces of non-composite types are gathered in a record and this record is passed by reference as the first argument to the subprogram. As a consequence, you shouldn't use in and inout modes in foreign subprograms, since they are not portable.

Records are represented like a C structure and are passed by reference to subprograms.

Arrays with static bounds are represented like a C array, whose length is the number of elements, and are passed by reference to subprograms.

Unconstrained array are represented by a fat pointer. Do not use unconstrained arrays in foreign subprograms.

Accesses to an unconstrained array is a fat pointer. Other accesses corresponds a an address and are passed to a subprogram like other non-composite types.

Files are represented by a 32 bits word, which corresponds to an index in a table.