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.
9 AC_DEFUN([CL_INTPARAM_CROSS],
11 AC_REQUIRE([CL_LONGLONG])
12 AC_REQUIRE([CL_LONGDOUBLE])
13 AC_REQUIRE([AC_C_BIGENDIAN])
16 CL_INTPARAM_BITSIZE([signed char], [char_bitsize])
17 CL_INTPARAM_BITSIZE([short], [short_bitsize])
18 CL_INTPARAM_BITSIZE([int], [int_bitsize])
19 CL_INTPARAM_BITSIZE([long], [long_bitsize])
20 if test $cl_cv_c_longlong = yes; then
21 CL_INTPARAM_BITSIZE([long long], [longlong_bitsize])
23 CL_INTPARAM_BITSIZE([unsigned char], [uchar_bitsize])
24 CL_INTPARAM_BITSIZE([unsigned short], [ushort_bitsize])
25 CL_INTPARAM_BITSIZE([unsigned int], [uint_bitsize])
26 CL_INTPARAM_BITSIZE([unsigned long], [ulong_bitsize])
27 if test $cl_cv_c_longlong = yes; then
28 CL_INTPARAM_BITSIZE([unsigned long long], [ulonglong_bitsize])
30 if test -n "$char_bitsize"; then
31 echo "/* Integers of type char have $char_bitsize bits. */"
32 echo "#define char_bitsize $char_bitsize"
35 echo "#error \"Integers of type char have no binary representation!!\""
37 if test -n "$short_bitsize"; then
38 echo "/* Integers of type short have $short_bitsize bits. */"
39 echo "#define short_bitsize $short_bitsize"
42 echo "#error \"Integers of type short have no binary representation!!\""
44 if test -n "$int_bitsize"; then
45 echo "/* Integers of type int have $int_bitsize bits. */"
46 echo "#define int_bitsize $int_bitsize"
49 echo "#error \"Integers of type int have no binary representation!!\""
51 if test -n "$long_bitsize"; then
52 echo "/* Integers of type long have $long_bitsize bits. */"
53 echo "#define long_bitsize $long_bitsize"
56 echo "#error \"Integers of type long have no binary representation!!\""
58 if test $cl_cv_c_longlong = yes; then
59 if test -n "$longlong_bitsize"; then
60 echo "/* Integers of type long long have $longlong_bitsize bits. */"
61 echo "#define long_long_bitsize $longlong_bitsize"
64 echo "#error \"Integers of type long long have no binary representation!!\""
67 if test -n "$uchar_bitsize"; then
68 echo "/* Integers of type unsigned char have $uchar_bitsize bits. */"
71 echo "#error \"Integers of type unsigned char have no binary representation!!\""
73 if test -n "$ushort_bitsize"; then
74 echo "/* Integers of type unsigned short have $ushort_bitsize bits. */"
77 echo "#error \"Integers of type unsigned short have no binary representation!!\""
79 if test -n "$uint_bitsize"; then
80 echo "/* Integers of type unsigned int have $uint_bitsize bits. */"
83 echo "#error \"Integers of type unsigned int have no binary representation!!\""
85 if test -n "$ulong_bitsize"; then
86 echo "/* Integers of type unsigned long have $ulong_bitsize bits. */"
89 echo "#error \"Integers of type unsigned long have no binary representation!!\""
91 if test $cl_cv_c_longlong = yes; then
92 if test -n "$ulonglong_bitsize"; then
93 echo "/* Integers of type unsigned long long have $ulonglong_bitsize bits. */"
96 echo "#error \"Integers of type unsigned long long have no binary representation!!\""
99 if test "$char_bitsize" != "$uchar_bitsize"; then
100 echo "#error \"Integer types char and unsigned char have different sizes!!\""
102 if test "$short_bitsize" != "$ushort_bitsize"; then
103 echo "#error \"Integer types short and unsigned short have different sizes!!\""
105 if test "$int_bitsize" != "$uint_bitsize"; then
106 echo "#error \"Integer types int and unsigned int have different sizes!!\""
108 if test "$long_bitsize" != "$ulong_bitsize"; then
109 echo "#error \"Integer types long and unsigned long have different sizes!!\""
111 if test $cl_cv_c_longlong = yes; then
112 if test "$longlong_bitsize" != "$ulonglong_bitsize"; then
113 echo "#error \"Integer types long long and unsigned long long have different sizes!!\""
116 AC_TRY_COMPILE([#include <stdint.h>], [static_assert(sizeof(char*) <= sizeof(intptr_t), "");],
117 [], [echo "#error \"Type char * does not fit into an intptr_t!!\""])
118 _AC_COMPUTE_INT([sizeof (char *)], [pointer_size])
119 pointer_bitsize=`expr $pointer_size '*' $char_bitsize`
120 echo "/* Pointers of type char * have $pointer_bitsize bits. */"
121 echo "#define pointer_bitsize $pointer_bitsize"
123 CL_INTPARAM_SIZEOF([char], [sizeof_char])
124 CL_INTPARAM_ALIGNOF([char], [alignment_char])
125 echo "/* Type char has sizeof = $sizeof_char and alignment = $alignment_char. */"
126 echo "#define sizeof_char $sizeof_char"
127 echo "#define alignment_char $alignment_char"
129 CL_INTPARAM_SIZEOF([unsigned char], [sizeof_uchar])
130 CL_INTPARAM_ALIGNOF([unsigned char], [alignment_uchar])
131 echo "/* Type unsigned char has sizeof = $sizeof_uchar and alignment = $alignment_uchar. */"
133 CL_INTPARAM_SIZEOF([short], [sizeof_short])
134 CL_INTPARAM_ALIGNOF([short], [alignment_short])
135 echo "/* Type short has sizeof = $sizeof_short and alignment = $alignment_short. */"
136 echo "#define sizeof_short $sizeof_short"
137 echo "#define alignment_short $alignment_short"
139 CL_INTPARAM_SIZEOF([unsigned short], [sizeof_ushort])
140 CL_INTPARAM_ALIGNOF([unsigned short], [alignment_ushort])
141 echo "/* Type unsigned short has sizeof = $sizeof_ushort and alignment = $alignment_ushort. */"
143 CL_INTPARAM_SIZEOF([int], [sizeof_int])
144 CL_INTPARAM_ALIGNOF([int], [alignment_int])
145 echo "/* Type int has sizeof = $sizeof_int and alignment = $alignment_int. */"
146 echo "#define sizeof_int $sizeof_int"
147 echo "#define alignment_int $alignment_int"
149 CL_INTPARAM_SIZEOF([unsigned int], [sizeof_uint])
150 CL_INTPARAM_ALIGNOF([unsigned int], [alignment_uint])
151 echo "/* Type unsigned int has sizeof = $sizeof_uint and alignment = $alignment_uint. */"
153 CL_INTPARAM_SIZEOF([long], [sizeof_long])
154 CL_INTPARAM_ALIGNOF([long], [alignment_long])
155 echo "/* Type long has sizeof = $sizeof_long and alignment = $alignment_long. */"
156 echo "#define sizeof_long $sizeof_long"
157 echo "#define alignment_long $alignment_long"
159 CL_INTPARAM_SIZEOF([unsigned long], [sizeof_ulong])
160 CL_INTPARAM_ALIGNOF([unsigned long], [alignment_ulong])
161 echo "/* Type unsigned long has sizeof = $sizeof_ulong and alignment = $alignment_ulong. */"
163 if test $cl_cv_c_longlong = yes; then
164 CL_INTPARAM_SIZEOF([long long], [sizeof_longlong])
165 CL_INTPARAM_ALIGNOF([long long], [alignment_longlong])
166 echo "/* Type long long has sizeof = $sizeof_longlong and alignment = $alignment_longlong. */"
167 echo "#define sizeof_long_long $sizeof_longlong"
168 echo "#define alignment_long_long $alignment_longlong"
170 CL_INTPARAM_SIZEOF([unsigned long long], [sizeof_ulonglong])
171 CL_INTPARAM_ALIGNOF([unsigned long long], [alignment_ulonglong])
172 echo "/* Type unsigned long long has sizeof = $sizeof_ulonglong and alignment = $alignment_ulonglong. */"
175 CL_INTPARAM_SIZEOF([float], [sizeof_float])
176 CL_INTPARAM_ALIGNOF([float], [alignment_float])
177 echo "/* Type float has sizeof = $sizeof_float and alignment = $alignment_float. */"
178 echo "#define sizeof_float $sizeof_float"
179 echo "#define alignment_float $alignment_float"
181 CL_INTPARAM_SIZEOF([double], [sizeof_double])
182 CL_INTPARAM_ALIGNOF([double], [alignment_double])
183 echo "/* Type double has sizeof = $sizeof_double and alignment = $alignment_double. */"
184 echo "#define sizeof_double $sizeof_double"
185 echo "#define alignment_double $alignment_double"
187 if test $cl_cv_c_longdouble = yes; then
188 CL_INTPARAM_SIZEOF([long double], [sizeof_longdouble])
189 CL_INTPARAM_ALIGNOF([long double], [alignment_longdouble])
190 echo "/* Type long double has sizeof = $sizeof_longdouble and alignment = $alignment_longdouble. */"
191 echo "#define sizeof_long_double $sizeof_longdouble"
192 echo "#define alignment_long_double $alignment_longdouble"
195 CL_INTPARAM_SIZEOF([char *], [sizeof_char_ptr])
196 CL_INTPARAM_ALIGNOF([char *], [alignment_char_ptr])
197 echo "/* Type char * has sizeof = $sizeof_char_ptr and alignment = $alignment_char_ptr. */"
199 CL_INTPARAM_SIZEOF([long *], [sizeof_long_ptr])
200 CL_INTPARAM_ALIGNOF([long *], [alignment_long_ptr])
201 echo "/* Type long * has sizeof = $sizeof_long_ptr and alignment = $alignment_long_ptr. */"
203 CL_INTPARAM_SIZEOF([void (*)(void)], [sizeof_function_ptr])
204 CL_INTPARAM_ALIGNOF([void (*)(void)], [alignment_function_ptr])
205 echo "/* Type function * has sizeof = $sizeof_function_ptr and alignment = $alignment_function_ptr. */"
207 case $ac_cv_c_bigendian in
209 echo "/* Type unsigned short is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
210 echo "#define short_big_endian"
211 echo "/* Type unsigned int is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
212 echo "#define int_big_endian"
213 echo "/* Type unsigned long is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
214 echo "#define long_big_endian"
215 if test $cl_cv_c_longlong = yes; then
216 echo "/* Type unsigned long long is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
217 echo "#define long_long_big_endian"
221 echo "/* Type unsigned short is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
222 echo "#define short_little_endian"
223 echo "/* Type unsigned int is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
224 echo "#define int_little_endian"
225 echo "/* Type unsigned long is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
226 echo "#define long_little_endian"
227 if test $cl_cv_c_longlong = yes; then
228 echo "/* Type unsigned long long is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
229 echo "#define long_long_little_endian"
233 echo "#error \"Type short is stored in memory in an obscure manner!!\""
234 echo "#error \"Type int is stored in memory in an obscure manner!!\""
235 echo "#error \"Type long is stored in memory in an obscure manner!!\""
236 if test $cl_cv_c_longlong = yes; then
237 echo "#error \"Type long long is stored in memory in an obscure manner!!\""
244 echo "/* Stack grows up. */"
245 echo "#define stack_grows_up"
248 echo "/* Stack grows down. */"
249 echo "#define stack_grows_down"
252 } > "$cl_machine_file_h"
255 dnl CL_INTPARAM_BITSIZE(type, variable)
256 dnl puts into variable the determined bitsize of the type.
257 AC_DEFUN([CL_INTPARAM_BITSIZE],
261 AC_TRY_COMPILE([], [typedef int verify[2*(($1)($x) == 0) - 1];],
263 [if test $n = 1000; then $2=; break; fi;])
264 n=`expr $n + 1`; x="$x * ($1)2"
268 dnl CL_INTPARAM_SIZEOF(type, variable)
269 dnl puts into variable the determined size of the type.
270 AC_DEFUN([CL_INTPARAM_SIZEOF],
272 _AC_COMPUTE_INT([sizeof($1)], [$2])
275 dnl CL_INTPARAM_ALIGNOF(type, variable)
276 dnl puts into variable the determined alignment of the type.
277 AC_DEFUN([CL_INTPARAM_ALIGNOF],
279 dnl Simplify the guessing by assuming that the alignment is a power of 2.
285 # define alignof(type) __alignof__ (type)
287 template <class type> struct alignof_helper { char slot1; type slot2; };
288 # define alignof(type) offsetof (alignof_helper<type>, slot2)
291 # define alignof(type) offsetof (struct { char slot1; type slot2; }, slot2)
293 ], [static_assert(alignof($1) == $n, "");],
295 [if test $n = 0; then $2=; break; fi])