2005-06-23 20:50:25 +02:00
|
|
|
#!/bin/sh
|
2007-10-27 16:07:14 +02:00
|
|
|
LC_ALL=C
|
|
|
|
export LC_ALL
|
2005-06-23 20:50:25 +02:00
|
|
|
|
2020-07-26 07:20:24 +02:00
|
|
|
if test "$#" -ne 3; then
|
|
|
|
echo "Usage $0 int_kinds real_kinds compile"
|
|
|
|
exit 1
|
|
|
|
fi
|
2005-06-23 20:50:25 +02:00
|
|
|
|
2020-07-26 07:20:24 +02:00
|
|
|
# Possible kinds must be listed in ascending order
|
|
|
|
possible_integer_kinds="$1"
|
|
|
|
possible_real_kinds="$2"
|
|
|
|
compile="$3"
|
2005-06-23 20:50:25 +02:00
|
|
|
|
|
|
|
largest=""
|
2007-07-22 01:45:44 +02:00
|
|
|
smallest=""
|
2005-06-23 20:50:25 +02:00
|
|
|
for k in $possible_integer_kinds; do
|
|
|
|
echo " integer (kind=$k) :: i" > tmp$$.f90
|
2008-09-10 18:39:15 +02:00
|
|
|
echo " i = 1_$k" >> tmp$$.f90
|
2005-06-23 20:50:25 +02:00
|
|
|
echo " end" >> tmp$$.f90
|
2008-01-16 10:13:39 +01:00
|
|
|
if $compile -S tmp$$.f90 > /dev/null 2>&1; then
|
2005-06-23 20:50:25 +02:00
|
|
|
s=`expr 8 \* $k`
|
|
|
|
largest="$k"
|
|
|
|
|
|
|
|
if [ $s -eq 128 ]; then
|
|
|
|
prefix="__"
|
|
|
|
else
|
|
|
|
prefix=""
|
|
|
|
fi
|
|
|
|
|
2007-07-22 01:45:44 +02:00
|
|
|
if [ "$smallest" = "" ]; then
|
|
|
|
smallest="$k"
|
|
|
|
fi
|
|
|
|
|
2005-06-23 20:50:25 +02:00
|
|
|
echo "typedef ${prefix}int${s}_t GFC_INTEGER_${k};"
|
|
|
|
echo "typedef ${prefix}uint${s}_t GFC_UINTEGER_${k};"
|
|
|
|
echo "typedef GFC_INTEGER_${k} GFC_LOGICAL_${k};"
|
2021-07-08 17:21:20 +02:00
|
|
|
echo "#define HAVE_GFC_LOGICAL_${k} 1"
|
|
|
|
echo "#define HAVE_GFC_INTEGER_${k} 1"
|
2007-10-26 01:32:07 +02:00
|
|
|
echo ""
|
2005-06-23 20:50:25 +02:00
|
|
|
fi
|
|
|
|
rm -f tmp$$.*
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "#define GFC_INTEGER_LARGEST GFC_INTEGER_${largest}"
|
|
|
|
echo "#define GFC_UINTEGER_LARGEST GFC_UINTEGER_${largest}"
|
2007-07-22 01:45:44 +02:00
|
|
|
echo "#define GFC_DEFAULT_CHAR ${smallest}"
|
2005-06-23 20:50:25 +02:00
|
|
|
echo ""
|
|
|
|
|
2010-11-16 22:23:19 +01:00
|
|
|
|
|
|
|
# Get the kind value for long double, so we may disambiguate it
|
|
|
|
# from __float128.
|
|
|
|
echo "use iso_c_binding; print *, c_long_double ; end" > tmq$$.f90
|
|
|
|
long_double_kind=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
|
|
|
|
| sed 's/ *TRANSFER *//'`
|
|
|
|
rm -f tmq$$.*
|
|
|
|
|
2005-06-23 20:50:25 +02:00
|
|
|
|
|
|
|
for k in $possible_real_kinds; do
|
|
|
|
echo " real (kind=$k) :: x" > tmp$$.f90
|
2008-09-10 18:39:15 +02:00
|
|
|
echo " x = 1.0_$k" >> tmp$$.f90
|
2005-06-23 20:50:25 +02:00
|
|
|
echo " end" >> tmp$$.f90
|
2008-01-16 10:13:39 +01:00
|
|
|
if $compile -S tmp$$.f90 > /dev/null 2>&1; then
|
2005-06-23 20:50:25 +02:00
|
|
|
case $k in
|
2010-11-16 22:23:19 +01:00
|
|
|
4) ctype="float" ; cplxtype="complex float" ; suffix="f" ;;
|
|
|
|
8) ctype="double" ; cplxtype="complex double" ; suffix="" ;;
|
|
|
|
10) ctype="long double" ; cplxtype="complex long double" ; suffix="l" ;;
|
|
|
|
16) if [ $long_double_kind -eq 10 ]; then
|
|
|
|
ctype="__float128"
|
|
|
|
cplxtype="_Complex float __attribute__((mode(TC)))"
|
|
|
|
suffix="q"
|
|
|
|
else
|
|
|
|
ctype="long double"
|
|
|
|
cplxtype="complex long double"
|
|
|
|
suffix="l"
|
|
|
|
fi ;;
|
2005-06-23 20:50:25 +02:00
|
|
|
*) echo "$0: Unknown type" >&2 ; exit 1 ;;
|
|
|
|
esac
|
2007-10-26 01:32:07 +02:00
|
|
|
|
|
|
|
# Check for the value of HUGE
|
|
|
|
echo "print *, huge(0._$k) ; end" > tmq$$.f90
|
2008-01-16 10:13:39 +01:00
|
|
|
huge=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
|
2007-11-08 20:17:19 +01:00
|
|
|
| sed 's/ *TRANSFER *//' | sed 's/_.*//'`
|
2007-10-26 01:32:07 +02:00
|
|
|
rm -f tmq$$.*
|
|
|
|
|
|
|
|
# Check for the value of DIGITS
|
|
|
|
echo "print *, digits(0._$k) ; end" > tmq$$.f90
|
2008-01-16 10:13:39 +01:00
|
|
|
digits=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
|
2007-10-26 01:32:07 +02:00
|
|
|
| sed 's/ *TRANSFER *//'`
|
|
|
|
rm -f tmq$$.*
|
|
|
|
|
|
|
|
# Check for the value of RADIX
|
|
|
|
echo "print *, radix(0._$k) ; end" > tmq$$.f90
|
2008-01-16 10:13:39 +01:00
|
|
|
radix=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
|
2007-10-26 01:32:07 +02:00
|
|
|
| sed 's/ *TRANSFER *//'`
|
|
|
|
rm -f tmq$$.*
|
|
|
|
|
|
|
|
# Output the information we've gathered
|
2005-06-23 20:50:25 +02:00
|
|
|
echo "typedef ${ctype} GFC_REAL_${k};"
|
2010-11-16 22:23:19 +01:00
|
|
|
echo "typedef ${cplxtype} GFC_COMPLEX_${k};"
|
2021-07-08 17:21:20 +02:00
|
|
|
echo "#define HAVE_GFC_REAL_${k} 1"
|
|
|
|
echo "#define HAVE_GFC_COMPLEX_${k} 1"
|
2007-10-26 01:32:07 +02:00
|
|
|
echo "#define GFC_REAL_${k}_HUGE ${huge}${suffix}"
|
2010-06-09 14:56:35 +02:00
|
|
|
echo "#define GFC_REAL_${k}_LITERAL_SUFFIX ${suffix}"
|
|
|
|
if [ "x$suffix" = "x" ]; then
|
|
|
|
echo "#define GFC_REAL_${k}_LITERAL(X) (X)"
|
|
|
|
else
|
|
|
|
echo "#define GFC_REAL_${k}_LITERAL(X) (X ## ${suffix})"
|
|
|
|
fi
|
2007-10-26 01:32:07 +02:00
|
|
|
echo "#define GFC_REAL_${k}_DIGITS ${digits}"
|
|
|
|
echo "#define GFC_REAL_${k}_RADIX ${radix}"
|
|
|
|
echo ""
|
2005-06-23 20:50:25 +02:00
|
|
|
fi
|
|
|
|
rm -f tmp$$.*
|
|
|
|
done
|
|
|
|
|
2021-07-08 17:21:20 +02:00
|
|
|
# For ISO_Fortran_binding.h
|
|
|
|
for k in "C_LONG_DOUBLE" "C_FLOAT128" "C_INT128_T"; do
|
|
|
|
fname="tmp$$.val"
|
|
|
|
echo "use iso_c_binding, only: $k; end" > tmp$$.f90
|
|
|
|
if $compile -S -fdump-parse-tree tmp$$.f90 > "$fname"; then
|
|
|
|
kind=`grep "value:" "$fname" |grep value: | sed -e 's/.*value: *//'`
|
|
|
|
if [ "x$kind" = "x" ]; then
|
|
|
|
echo "ERROR: Failed to extract kind for $k" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "#define GFC_${k}_KIND ${kind}"
|
|
|
|
else
|
|
|
|
echo "ERROR: Failed to extract kind for $k" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
rm -f tmp$$.*
|
|
|
|
done
|
2010-11-16 22:23:19 +01:00
|
|
|
|
2020-07-26 07:20:24 +02:00
|
|
|
# After this, we include a header that can override some of the
|
2010-11-16 22:23:19 +01:00
|
|
|
# autodetected settings.
|
|
|
|
echo '#include "kinds-override.h"'
|
|
|
|
|
2005-06-23 20:50:25 +02:00
|
|
|
exit 0
|