You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
12 KiB

  1. # intparam.m4 serial 1
  2. dnl Copyright (C) 2005 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. dnl From Bruno Haible.
  7. AC_DEFUN([CL_INTPARAM_CROSS],
  8. [
  9. AC_REQUIRE([CL_LONGLONG])
  10. AC_REQUIRE([CL_LONGDOUBLE])
  11. AC_REQUIRE([AC_C_BIGENDIAN])
  12. cl_machine_file_h=$1
  13. {
  14. CL_INTPARAM_BITSIZE([signed char], [char_bitsize])
  15. CL_INTPARAM_BITSIZE([short], [short_bitsize])
  16. CL_INTPARAM_BITSIZE([int], [int_bitsize])
  17. CL_INTPARAM_BITSIZE([long], [long_bitsize])
  18. if test $cl_cv_c_longlong = yes; then
  19. CL_INTPARAM_BITSIZE([long long], [longlong_bitsize])
  20. fi
  21. CL_INTPARAM_BITSIZE([unsigned char], [uchar_bitsize])
  22. CL_INTPARAM_BITSIZE([unsigned short], [ushort_bitsize])
  23. CL_INTPARAM_BITSIZE([unsigned int], [uint_bitsize])
  24. CL_INTPARAM_BITSIZE([unsigned long], [ulong_bitsize])
  25. if test $cl_cv_c_longlong = yes; then
  26. CL_INTPARAM_BITSIZE([unsigned long long], [ulonglong_bitsize])
  27. fi
  28. if test -n "$char_bitsize"; then
  29. echo "/* Integers of type char have $char_bitsize bits. */"
  30. echo "#define char_bitsize $char_bitsize"
  31. echo
  32. else
  33. echo "#error \"Integers of type char have no binary representation!!\""
  34. fi
  35. if test -n "$short_bitsize"; then
  36. echo "/* Integers of type short have $short_bitsize bits. */"
  37. echo "#define short_bitsize $short_bitsize"
  38. echo
  39. else
  40. echo "#error \"Integers of type short have no binary representation!!\""
  41. fi
  42. if test -n "$int_bitsize"; then
  43. echo "/* Integers of type int have $int_bitsize bits. */"
  44. echo "#define int_bitsize $int_bitsize"
  45. echo
  46. else
  47. echo "#error \"Integers of type int have no binary representation!!\""
  48. fi
  49. if test -n "$long_bitsize"; then
  50. echo "/* Integers of type long have $long_bitsize bits. */"
  51. echo "#define long_bitsize $long_bitsize"
  52. echo
  53. else
  54. echo "#error \"Integers of type long have no binary representation!!\""
  55. fi
  56. if test $cl_cv_c_longlong = yes; then
  57. if test -n "$longlong_bitsize"; then
  58. echo "/* Integers of type long long have $longlong_bitsize bits. */"
  59. echo "#define long_long_bitsize $longlong_bitsize"
  60. echo
  61. else
  62. echo "#error \"Integers of type long long have no binary representation!!\""
  63. fi
  64. fi
  65. if test -n "$uchar_bitsize"; then
  66. echo "/* Integers of type unsigned char have $uchar_bitsize bits. */"
  67. echo
  68. else
  69. echo "#error \"Integers of type unsigned char have no binary representation!!\""
  70. fi
  71. if test -n "$ushort_bitsize"; then
  72. echo "/* Integers of type unsigned short have $ushort_bitsize bits. */"
  73. echo
  74. else
  75. echo "#error \"Integers of type unsigned short have no binary representation!!\""
  76. fi
  77. if test -n "$uint_bitsize"; then
  78. echo "/* Integers of type unsigned int have $uint_bitsize bits. */"
  79. echo
  80. else
  81. echo "#error \"Integers of type unsigned int have no binary representation!!\""
  82. fi
  83. if test -n "$ulong_bitsize"; then
  84. echo "/* Integers of type unsigned long have $ulong_bitsize bits. */"
  85. echo
  86. else
  87. echo "#error \"Integers of type unsigned long have no binary representation!!\""
  88. fi
  89. if test $cl_cv_c_longlong = yes; then
  90. if test -n "$ulonglong_bitsize"; then
  91. echo "/* Integers of type unsigned long long have $ulonglong_bitsize bits. */"
  92. echo
  93. else
  94. echo "#error \"Integers of type unsigned long long have no binary representation!!\""
  95. fi
  96. fi
  97. if test "$char_bitsize" != "$uchar_bitsize"; then
  98. echo "#error \"Integer types char and unsigned char have different sizes!!\""
  99. fi
  100. if test "$short_bitsize" != "$ushort_bitsize"; then
  101. echo "#error \"Integer types short and unsigned short have different sizes!!\""
  102. fi
  103. if test "$int_bitsize" != "$uint_bitsize"; then
  104. echo "#error \"Integer types int and unsigned int have different sizes!!\""
  105. fi
  106. if test "$long_bitsize" != "$ulong_bitsize"; then
  107. echo "#error \"Integer types long and unsigned long have different sizes!!\""
  108. fi
  109. if test $cl_cv_c_longlong = yes; then
  110. if test "$longlong_bitsize" != "$ulonglong_bitsize"; then
  111. echo "#error \"Integer types long long and unsigned long long have different sizes!!\""
  112. fi
  113. fi
  114. AC_TRY_COMPILE([], [typedef int verify[2*(sizeof(char*)<=sizeof (long))-1];],
  115. [], [echo "#error \"Type char * does not fit into a long!!\""])
  116. _AC_COMPUTE_INT([sizeof (char *)], [pointer_size])
  117. pointer_bitsize=`expr $pointer_size '*' $char_bitsize`
  118. echo "/* Pointers of type char * have $pointer_bitsize bits. */"
  119. echo "#define pointer_bitsize $pointer_bitsize"
  120. echo
  121. CL_INTPARAM_SIZEOF([char], [sizeof_char])
  122. CL_INTPARAM_ALIGNOF([char], [alignment_char])
  123. echo "/* Type char has sizeof = $sizeof_char and alignment = $alignment_char. */"
  124. echo "#define sizeof_char $sizeof_char"
  125. echo "#define alignment_char $alignment_char"
  126. echo
  127. CL_INTPARAM_SIZEOF([unsigned char], [sizeof_uchar])
  128. CL_INTPARAM_ALIGNOF([unsigned char], [alignment_uchar])
  129. echo "/* Type unsigned char has sizeof = $sizeof_uchar and alignment = $alignment_uchar. */"
  130. echo
  131. CL_INTPARAM_SIZEOF([short], [sizeof_short])
  132. CL_INTPARAM_ALIGNOF([short], [alignment_short])
  133. echo "/* Type short has sizeof = $sizeof_short and alignment = $alignment_short. */"
  134. echo "#define sizeof_short $sizeof_short"
  135. echo "#define alignment_short $alignment_short"
  136. echo
  137. CL_INTPARAM_SIZEOF([unsigned short], [sizeof_ushort])
  138. CL_INTPARAM_ALIGNOF([unsigned short], [alignment_ushort])
  139. echo "/* Type unsigned short has sizeof = $sizeof_ushort and alignment = $alignment_ushort. */"
  140. echo
  141. CL_INTPARAM_SIZEOF([int], [sizeof_int])
  142. CL_INTPARAM_ALIGNOF([int], [alignment_int])
  143. echo "/* Type int has sizeof = $sizeof_int and alignment = $alignment_int. */"
  144. echo "#define sizeof_int $sizeof_int"
  145. echo "#define alignment_int $alignment_int"
  146. echo
  147. CL_INTPARAM_SIZEOF([unsigned int], [sizeof_uint])
  148. CL_INTPARAM_ALIGNOF([unsigned int], [alignment_uint])
  149. echo "/* Type unsigned int has sizeof = $sizeof_uint and alignment = $alignment_uint. */"
  150. echo
  151. CL_INTPARAM_SIZEOF([long], [sizeof_long])
  152. CL_INTPARAM_ALIGNOF([long], [alignment_long])
  153. echo "/* Type long has sizeof = $sizeof_long and alignment = $alignment_long. */"
  154. echo "#define sizeof_long $sizeof_long"
  155. echo "#define alignment_long $alignment_long"
  156. echo
  157. CL_INTPARAM_SIZEOF([unsigned long], [sizeof_ulong])
  158. CL_INTPARAM_ALIGNOF([unsigned long], [alignment_ulong])
  159. echo "/* Type unsigned long has sizeof = $sizeof_ulong and alignment = $alignment_ulong. */"
  160. echo
  161. if test $cl_cv_c_longlong = yes; then
  162. CL_INTPARAM_SIZEOF([long long], [sizeof_longlong])
  163. CL_INTPARAM_ALIGNOF([long long], [alignment_longlong])
  164. echo "/* Type long long has sizeof = $sizeof_longlong and alignment = $alignment_longlong. */"
  165. echo "#define sizeof_long_long $sizeof_longlong"
  166. echo "#define alignment_long_long $alignment_longlong"
  167. echo
  168. CL_INTPARAM_SIZEOF([unsigned long long], [sizeof_ulonglong])
  169. CL_INTPARAM_ALIGNOF([unsigned long long], [alignment_ulonglong])
  170. echo "/* Type unsigned long long has sizeof = $sizeof_ulonglong and alignment = $alignment_ulonglong. */"
  171. echo
  172. fi
  173. CL_INTPARAM_SIZEOF([float], [sizeof_float])
  174. CL_INTPARAM_ALIGNOF([float], [alignment_float])
  175. echo "/* Type float has sizeof = $sizeof_float and alignment = $alignment_float. */"
  176. echo "#define sizeof_float $sizeof_float"
  177. echo "#define alignment_float $alignment_float"
  178. echo
  179. CL_INTPARAM_SIZEOF([double], [sizeof_double])
  180. CL_INTPARAM_ALIGNOF([double], [alignment_double])
  181. echo "/* Type double has sizeof = $sizeof_double and alignment = $alignment_double. */"
  182. echo "#define sizeof_double $sizeof_double"
  183. echo "#define alignment_double $alignment_double"
  184. echo
  185. if test $cl_cv_c_longdouble = yes; then
  186. CL_INTPARAM_SIZEOF([long double], [sizeof_longdouble])
  187. CL_INTPARAM_ALIGNOF([long double], [alignment_longdouble])
  188. echo "/* Type long double has sizeof = $sizeof_longdouble and alignment = $alignment_longdouble. */"
  189. echo "#define sizeof_long_double $sizeof_longdouble"
  190. echo "#define alignment_long_double $alignment_longdouble"
  191. echo
  192. fi
  193. CL_INTPARAM_SIZEOF([char *], [sizeof_char_ptr])
  194. CL_INTPARAM_ALIGNOF([char *], [alignment_char_ptr])
  195. echo "/* Type char * has sizeof = $sizeof_char_ptr and alignment = $alignment_char_ptr. */"
  196. echo
  197. CL_INTPARAM_SIZEOF([long *], [sizeof_long_ptr])
  198. CL_INTPARAM_ALIGNOF([long *], [alignment_long_ptr])
  199. echo "/* Type long * has sizeof = $sizeof_long_ptr and alignment = $alignment_long_ptr. */"
  200. echo
  201. CL_INTPARAM_SIZEOF([void (*)(void)], [sizeof_function_ptr])
  202. CL_INTPARAM_ALIGNOF([void (*)(void)], [alignment_function_ptr])
  203. echo "/* Type function * has sizeof = $sizeof_function_ptr and alignment = $alignment_function_ptr. */"
  204. echo
  205. case $ac_cv_c_bigendian in
  206. yes)
  207. echo "/* Type unsigned short is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
  208. echo "#define short_big_endian"
  209. echo "/* Type unsigned int is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
  210. echo "#define int_big_endian"
  211. echo "/* Type unsigned long is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
  212. echo "#define long_big_endian"
  213. if test $cl_cv_c_longlong = yes; then
  214. echo "/* Type unsigned long long is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
  215. echo "#define long_long_big_endian"
  216. fi
  217. ;;
  218. no)
  219. echo "/* Type unsigned short is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
  220. echo "#define short_little_endian"
  221. echo "/* Type unsigned int is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
  222. echo "#define int_little_endian"
  223. echo "/* Type unsigned long is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
  224. echo "#define long_little_endian"
  225. if test $cl_cv_c_longlong = yes; then
  226. echo "/* Type unsigned long long is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
  227. echo "#define long_long_little_endian"
  228. fi
  229. ;;
  230. *)
  231. echo "#error \"Type short is stored in memory in an obscure manner!!\""
  232. echo "#error \"Type int is stored in memory in an obscure manner!!\""
  233. echo "#error \"Type long is stored in memory in an obscure manner!!\""
  234. if test $cl_cv_c_longlong = yes; then
  235. echo "#error \"Type long long is stored in memory in an obscure manner!!\""
  236. fi
  237. ;;
  238. esac
  239. echo
  240. case $host_cpu in
  241. hppa)
  242. echo "/* Stack grows up. */"
  243. echo "#define stack_grows_up"
  244. ;;
  245. *)
  246. echo "/* Stack grows down. */"
  247. echo "#define stack_grows_down"
  248. ;;
  249. esac
  250. } > "$cl_machine_file_h"
  251. ])
  252. dnl CL_INTPARAM_BITSIZE(type, variable)
  253. dnl puts into variable the determined bitsize of the type.
  254. AC_DEFUN([CL_INTPARAM_BITSIZE],
  255. [
  256. n=1; x="($1)2"
  257. while true; do
  258. AC_TRY_COMPILE([], [typedef int verify[2*(($1)($x) == 0) - 1];],
  259. [$2=$n; break;],
  260. [if test $n = 1000; then $2=; break; fi;])
  261. n=`expr $n + 1`; x="$x * ($1)2"
  262. done
  263. ])
  264. dnl CL_INTPARAM_SIZEOF(type, variable)
  265. dnl puts into variable the determined size of the type.
  266. AC_DEFUN([CL_INTPARAM_SIZEOF],
  267. [
  268. _AC_COMPUTE_INT([sizeof($1)], [$2])
  269. ])
  270. dnl CL_INTPARAM_ALIGNOF(type, variable)
  271. dnl puts into variable the determined alignment of the type.
  272. AC_DEFUN([CL_INTPARAM_ALIGNOF],
  273. [
  274. dnl Simplify the guessing by assuming that the alignment is a power of 2.
  275. n=1
  276. while true; do
  277. AC_TRY_COMPILE([
  278. #ifdef __cplusplus
  279. # ifdef __GNUC__
  280. # define alignof(type) __alignof__ (type)
  281. # else
  282. template <class type> struct alignof_helper { char slot1; type slot2; };
  283. # define alignof(type) offsetof (alignof_helper<type>, slot2)
  284. # endif
  285. #else
  286. # define alignof(type) offsetof (struct { char slot1; type slot2; }, slot2)
  287. #endif
  288. ], [typedef int verify[2*(alignof($1) == $n) - 1];],
  289. [$2=$n; break;]
  290. [if test $n = 0; then $2=; break; fi])
  291. n=`expr $n '*' 2`
  292. done
  293. ])