RISC-V: Add testcase for PR114749.
[official-gcc.git] / libgfortran / mk-kinds-h.sh
blob0e0ec195875a8aa952fbfef265960d32d81ecad1
1 #!/bin/sh
2 LC_ALL=C
3 export LC_ALL
5 if test "$#" -ne 4; then
6 echo "Usage $0 int_kinds real_kinds compile use_iec_60559"
7 exit 1
8 fi
10 # Possible kinds must be listed in ascending order
11 possible_integer_kinds="$1"
12 possible_real_kinds="$2"
13 compile="$3"
14 use_iec_60559="$4"
16 largest=""
17 smallest=""
18 for k in $possible_integer_kinds; do
19 echo " integer (kind=$k) :: i" > tmp$$.f90
20 echo " i = 1_$k" >> tmp$$.f90
21 echo " end" >> tmp$$.f90
22 if $compile -S tmp$$.f90 > /dev/null 2>&1; then
23 s=`expr 8 \* $k`
24 largest="$k"
26 if [ $s -eq 128 ]; then
27 prefix="__"
28 else
29 prefix=""
32 if [ "$smallest" = "" ]; then
33 smallest="$k"
36 echo "typedef ${prefix}int${s}_t GFC_INTEGER_${k};"
37 echo "typedef ${prefix}uint${s}_t GFC_UINTEGER_${k};"
38 echo "typedef GFC_INTEGER_${k} GFC_LOGICAL_${k};"
39 echo "#define HAVE_GFC_LOGICAL_${k}"
40 echo "#define HAVE_GFC_INTEGER_${k}"
41 echo ""
43 rm -f tmp$$.*
44 done
46 echo "#define GFC_INTEGER_LARGEST GFC_INTEGER_${largest}"
47 echo "#define GFC_UINTEGER_LARGEST GFC_UINTEGER_${largest}"
48 echo "#define GFC_DEFAULT_CHAR ${smallest}"
49 echo ""
52 # Get the kind value for long double, so we may disambiguate it
53 # from _Float128.
54 echo "use iso_c_binding; print *, c_long_double ; end" > tmq$$.f90
55 long_double_kind=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
56 | sed 's/ *TRANSFER *//'`
57 rm -f tmq$$.*
60 for k in $possible_real_kinds; do
61 echo " real (kind=$k) :: x" > tmp$$.f90
62 echo " x = 1.0_$k" >> tmp$$.f90
63 echo " end" >> tmp$$.f90
64 if $compile -S tmp$$.f90 > /dev/null 2>&1; then
65 case $k in
66 4) ctype="float" ; cplxtype="complex float" ; suffix="f" ;;
67 8) ctype="double" ; cplxtype="complex double" ; suffix="" ;;
68 # If we have a REAL(KIND=10), it is always long double
69 10) ctype="long double" ; cplxtype="complex long double" ; suffix="l" ;;
70 # If we have a REAL(KIND=16), it is either long double or _Float128
71 16) if [ $long_double_kind -ne 16 ]; then
72 ctype="_Float128"
73 cplxtype="_Complex _Float128"
74 echo "#define GFC_REAL_16_IS_FLOAT128"
75 if [ x$use_iec_60559 = xyes ]; then
76 suffix="f128"
77 echo "#define GFC_REAL_16_USE_IEC_60559"
78 else
79 suffix="q"
81 else
82 ctype="long double"
83 cplxtype="complex long double"
84 suffix="l"
85 echo "#define GFC_REAL_16_IS_LONG_DOUBLE"
86 fi ;;
87 *) echo "$0: Unknown type" >&2 ; exit 1 ;;
88 esac
90 # Check for the value of HUGE
91 echo "print *, huge(0._$k) ; end" > tmq$$.f90
92 huge=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
93 | sed 's/ *TRANSFER *//' | sed 's/_.*//'`
94 rm -f tmq$$.*
96 # Check for the value of TINY
97 echo "print *, tiny(0._$k) ; end" > tmq$$.f90
98 tiny=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
99 | sed 's/ *TRANSFER *//' | sed 's/_.*//'`
100 rm -f tmq$$.*
102 # Check for the value of DIGITS
103 echo "print *, digits(0._$k) ; end" > tmq$$.f90
104 digits=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
105 | sed 's/ *TRANSFER *//'`
106 rm -f tmq$$.*
108 # Check for the value of RADIX
109 echo "print *, radix(0._$k) ; end" > tmq$$.f90
110 radix=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
111 | sed 's/ *TRANSFER *//'`
112 rm -f tmq$$.*
114 # Output the information we've gathered
115 echo "typedef ${ctype} GFC_REAL_${k};"
116 echo "typedef ${cplxtype} GFC_COMPLEX_${k};"
117 echo "#define HAVE_GFC_REAL_${k}"
118 echo "#define HAVE_GFC_COMPLEX_${k}"
119 echo "#define GFC_REAL_${k}_HUGE ${huge}${suffix}"
120 echo "#define GFC_REAL_${k}_TINY ${tiny}${suffix}"
121 echo "#define GFC_REAL_${k}_LITERAL_SUFFIX ${suffix}"
122 if [ "x$suffix" = "x" ]; then
123 echo "#define GFC_REAL_${k}_LITERAL(X) (X)"
124 else
125 echo "#define GFC_REAL_${k}_LITERAL(X) (X ## ${suffix})"
127 echo "#define GFC_REAL_${k}_DIGITS ${digits}"
128 echo "#define GFC_REAL_${k}_RADIX ${radix}"
129 echo ""
131 rm -f tmp$$.*
132 done
135 # After this, we include a header that can override some of the
136 # autodetected settings.
137 echo '#include "kinds-override.h"'
139 exit 0