mk-kinds-h.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/sh
  2. LC_ALL=C
  3. export LC_ALL
  4. compile="$1"
  5. # Possible types must be listed in ascending order
  6. possible_integer_kinds="1 2 4 8 16"
  7. possible_real_kinds="4 8 10 16"
  8. largest=""
  9. smallest=""
  10. for k in $possible_integer_kinds; do
  11. echo " integer (kind=$k) :: i" > tmp$$.f90
  12. echo " i = 1_$k" >> tmp$$.f90
  13. echo " end" >> tmp$$.f90
  14. if $compile -S tmp$$.f90 > /dev/null 2>&1; then
  15. s=`expr 8 \* $k`
  16. largest="$k"
  17. if [ $s -eq 128 ]; then
  18. prefix="__"
  19. else
  20. prefix=""
  21. fi
  22. if [ "$smallest" = "" ]; then
  23. smallest="$k"
  24. fi
  25. echo "typedef ${prefix}int${s}_t GFC_INTEGER_${k};"
  26. echo "typedef ${prefix}uint${s}_t GFC_UINTEGER_${k};"
  27. echo "typedef GFC_INTEGER_${k} GFC_LOGICAL_${k};"
  28. echo "#define HAVE_GFC_LOGICAL_${k}"
  29. echo "#define HAVE_GFC_INTEGER_${k}"
  30. echo ""
  31. fi
  32. rm -f tmp$$.*
  33. done
  34. echo "#define GFC_INTEGER_LARGEST GFC_INTEGER_${largest}"
  35. echo "#define GFC_UINTEGER_LARGEST GFC_UINTEGER_${largest}"
  36. echo "#define GFC_DEFAULT_CHAR ${smallest}"
  37. echo ""
  38. # Get the kind value for long double, so we may disambiguate it
  39. # from __float128.
  40. echo "use iso_c_binding; print *, c_long_double ; end" > tmq$$.f90
  41. long_double_kind=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
  42. | sed 's/ *TRANSFER *//'`
  43. rm -f tmq$$.*
  44. for k in $possible_real_kinds; do
  45. echo " real (kind=$k) :: x" > tmp$$.f90
  46. echo " x = 1.0_$k" >> tmp$$.f90
  47. echo " end" >> tmp$$.f90
  48. if $compile -S tmp$$.f90 > /dev/null 2>&1; then
  49. case $k in
  50. 4) ctype="float" ; cplxtype="complex float" ; suffix="f" ;;
  51. 8) ctype="double" ; cplxtype="complex double" ; suffix="" ;;
  52. 10) ctype="long double" ; cplxtype="complex long double" ; suffix="l" ;;
  53. 16) if [ $long_double_kind -eq 10 ]; then
  54. ctype="__float128"
  55. cplxtype="_Complex float __attribute__((mode(TC)))"
  56. suffix="q"
  57. else
  58. ctype="long double"
  59. cplxtype="complex long double"
  60. suffix="l"
  61. fi ;;
  62. *) echo "$0: Unknown type" >&2 ; exit 1 ;;
  63. esac
  64. # Check for the value of HUGE
  65. echo "print *, huge(0._$k) ; end" > tmq$$.f90
  66. huge=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
  67. | sed 's/ *TRANSFER *//' | sed 's/_.*//'`
  68. rm -f tmq$$.*
  69. # Check for the value of DIGITS
  70. echo "print *, digits(0._$k) ; end" > tmq$$.f90
  71. digits=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
  72. | sed 's/ *TRANSFER *//'`
  73. rm -f tmq$$.*
  74. # Check for the value of RADIX
  75. echo "print *, radix(0._$k) ; end" > tmq$$.f90
  76. radix=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
  77. | sed 's/ *TRANSFER *//'`
  78. rm -f tmq$$.*
  79. # Output the information we've gathered
  80. echo "typedef ${ctype} GFC_REAL_${k};"
  81. echo "typedef ${cplxtype} GFC_COMPLEX_${k};"
  82. echo "#define HAVE_GFC_REAL_${k}"
  83. echo "#define HAVE_GFC_COMPLEX_${k}"
  84. echo "#define GFC_REAL_${k}_HUGE ${huge}${suffix}"
  85. echo "#define GFC_REAL_${k}_LITERAL_SUFFIX ${suffix}"
  86. if [ "x$suffix" = "x" ]; then
  87. echo "#define GFC_REAL_${k}_LITERAL(X) (X)"
  88. else
  89. echo "#define GFC_REAL_${k}_LITERAL(X) (X ## ${suffix})"
  90. fi
  91. echo "#define GFC_REAL_${k}_DIGITS ${digits}"
  92. echo "#define GFC_REAL_${k}_RADIX ${radix}"
  93. echo ""
  94. fi
  95. rm -f tmp$$.*
  96. done
  97. # After this, we include a header that can override some of the
  98. # autodetected settings.
  99. echo '#include "kinds-override.h"'
  100. exit 0