brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.6 KiB · 8e3f78c Raw
149 lines · plain
1!===-- module/iso_c_binding.f90 --------------------------------------------===!2!3! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4! See https://llvm.org/LICENSE.txt for license information.5! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6!7!===------------------------------------------------------------------------===!8 9! See Fortran 2018, clause 18.210 11module iso_c_binding12 13  use __fortran_builtins, only: &14    c_associated => __builtin_c_associated, &15    c_funloc => __builtin_c_funloc, &16    c_funptr => __builtin_c_funptr, &17    c_f_pointer => __builtin_c_f_pointer, &18    c_loc => __builtin_c_loc, &19    c_null_funptr => __builtin_c_null_funptr, &20    c_null_ptr => __builtin_c_null_ptr, &21    c_ptr => __builtin_c_ptr, &22    c_sizeof => sizeof, &23    operator(==), operator(/=)24 25  implicit none26 27  ! Set PRIVATE by default to explicitly only export what is meant28  ! to be exported by this MODULE.29  private30 31  public :: c_associated, c_funloc, c_funptr, c_f_pointer, c_loc, &32    c_null_funptr, c_null_ptr, c_ptr, c_sizeof, &33    operator(==), operator(/=)34 35  ! Table 18.2 (in clause 18.3.1)36  ! TODO: Specialize (via macros?) for alternative targets37  integer, parameter, public :: &38    c_int8_t = 1, &39    c_int16_t = 2, &40    c_int32_t = 4, &41    c_int64_t = 8, &42    c_int128_t = 16 ! anticipating future addition43  integer, parameter, public :: &44    c_int = c_int32_t, &45    c_short = c_int16_t, &46    c_long = c_int64_t, &47    c_long_long = c_int64_t, &48    c_signed_char = c_int8_t, &49    c_size_t = kind(c_sizeof(1)), &50    ! Currently both gcc and clang define intmax_t to be 64 bit.51    c_intmax_t = c_int64_t, &52    c_intptr_t = c_size_t, &53    c_ptrdiff_t = c_size_t54  integer, parameter, public :: &55    c_int_least8_t = c_int8_t, &56    c_int_fast8_t = c_int8_t, &57    c_int_least16_t = c_int16_t, &58#if defined(__linux__) && defined(__powerpc__)59    c_int_fast16_t = c_long, &60#else61    c_int_fast16_t = c_int16_t, &62#endif63    c_int_least32_t = c_int32_t, &64#if defined(__linux__) && defined(__powerpc__)65    c_int_fast32_t = c_long, &66#else67    c_int_fast32_t = c_int32_t, &68#endif69    c_int_least64_t = c_int64_t, &70    c_int_fast64_t = c_int64_t, &71    c_int_least128_t = c_int128_t, &72    c_int_fast128_t = c_int128_t73 74  integer, parameter, public :: &75    c_float = 4, &76    c_double = 8, &77#if __x86_64__78    c_long_double = 1079#else80    c_long_double = 1681#endif82 83  integer, parameter, public :: &84    c_float_complex = c_float, &85    c_double_complex = c_double, &86    c_long_double_complex = c_long_double87 88  integer, parameter, public :: c_bool = 189  integer, parameter, public :: c_char = 190 91  ! C characters with special semantics92  character(kind=c_char, len=1), parameter, public :: c_null_char = achar(0)93  character(kind=c_char, len=1), parameter, public :: c_alert = achar(7)94  character(kind=c_char, len=1), parameter, public :: c_backspace = achar(8)95  character(kind=c_char, len=1), parameter, public :: c_form_feed = achar(12)96  character(kind=c_char, len=1), parameter, public :: c_new_line = achar(10)97  character(kind=c_char, len=1), parameter, public :: c_carriage_return = achar(13)98  character(kind=c_char, len=1), parameter, public :: c_horizontal_tab = achar(9)99  character(kind=c_char, len=1), parameter, public :: c_vertical_tab =  achar(11)100 101  interface c_f_procpointer102    module procedure c_f_procpointer103  end interface104  public :: c_f_procpointer105 106  ! gfortran extensions107  integer, parameter, public :: &108    c_float128 = 16, &109    c_float128_complex = c_float128110  integer, parameter, public :: &111    c_uint8_t = 1, &112    c_uint16_t = 2, &113    c_uint32_t = 4, &114    c_uint64_t = 8, &115    c_uint128_t = 16116  integer, parameter, public :: &117    c_unsigned_char = c_uint8_t, &118    c_unsigned_short = c_uint16_t, &119    c_unsigned = c_uint32_t, &120    c_unsigned_long = c_uint64_t, &121    c_unsigned_long_long = c_unsigned_long, &122#if __powerpc__123    c_uintmax_t = c_uint64_t124#else125    c_uintmax_t = c_uint128_t126#endif127  integer, parameter, public :: &128    c_uint_fast8_t = c_uint8_t, &129    c_uint_fast16_t = c_uint16_t, &130    c_uint_fast32_t = c_uint32_t, &131    c_uint_fast64_t = c_uint64_t, &132    c_uint_fast128_t = c_uint128_t133  integer, parameter, public :: &134    c_uint_least8_t = c_uint8_t, &135    c_uint_least16_t = c_uint16_t, &136    c_uint_least32_t = c_uint32_t, &137    c_uint_least64_t = c_uint64_t, &138    c_uint_least128_t = c_uint128_t139 140 contains141 142  subroutine c_f_procpointer(cptr, fptr)143    type(c_funptr), intent(in) :: cptr144    procedure(), pointer, intent(out) :: fptr145    ! TODO: implement146  end subroutine c_f_procpointer147 148end module iso_c_binding149