1 # psi_add_type(type triplet)
2 # Add a pre-defined type to $PSI_TYPES.
10 cat >>$PSI_STDTYPES <<EOF
15 # psi_type_pair(type, size)
16 # Output a PSI_T_<TYPE>, \"<TYPENAME>\" tuple.
17 # Uses stdint types when possible.
19 local psi_type_name=`printf "%s" "$1" | tr -cd A-Za-z0-9_`
20 local psi_type_lower=`printf "%s" "$1" | tr A-Z a-z`
21 case $psi_type_lower in
23 local psi_type_upper=`printf "%s" "$psi_type_name" | tr a-z A-Z`
24 local psi_type_bits=`expr $2 \* 8`
25 echo "PSI_T_${psi_type_upper}${psi_type_bits}, \"${psi_type_lower}${psi_type_bits}_t\""
28 echo "PSI_T_STRUCT, \"$2\""
31 echo "PSI_T_UNION, \"$2\""
34 echo "PSI_T_VOID, \"void\""
37 echo "PSI_T_NAME, \"$psi_type_name\""
42 dnl PSI_TYPE(type name, basic type)
43 dnl Check for a specific type, optionally referring to a basic type.
44 dnl Calls AC_TYPE_<TYPE> (if defined) and PSI_CHECK_SIZEOF.
45 dnl If the basic type is just specified as "int" (in contrast to "sint" or
46 dnl "uint"), AX_CHECK_SIGN is used to discover signedness of the type.
47 dnl Defines a pre-defined type in $PSI_TYPES.
49 ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1))
51 psi_basic_type=AS_TR_SH($2)
52 case $psi_basic_type in
54 AX_CHECK_SIGN($1, :, [psi_basic_type=uint], PSI_INCLUDES)
60 if test "$2" && PSI_SH_TEST_SIZEOF($1); then
61 AS_TR_SH(psi_basic_type_$1)=$psi_basic_type
62 psi_add_type "{`psi_type_pair $psi_basic_type PSI_SH_SIZEOF($1)`, \"$1\"}"
66 AC_DEFUN(PSI_STDTYPE, [
67 ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1))
69 if PSI_SH_TEST_SIZEOF($1); then
71 [float],[psi_add_stdtype "{PSI_T_FLOAT, \"float\", NULL}"],
72 [double],[psi_add_stdtype "{PSI_T_DOUBLE, \"double\", NULL}"],
73 [long double],[psi_add_stdtype "{PSI_T_LONG_DOUBLE, \"long double\", NULL}"],
75 AX_CHECK_SIGN($1, psi_basic_type=int, psi_basic_type=uint, PSI_INCLUDES)
76 AS_TR_SH(psi_basic_type_$1)=$psi_basic_type
77 psi_add_stdtype "{`psi_type_pair $psi_basic_type PSI_SH_SIZEOF($1)`, \"$1\"}"
82 dnl PSI_SH_BASIC_TYPE(type)
83 dnl Expand to the basic type (int/uint) of a distinct type
84 AC_DEFUN(PSI_SH_BASIC_TYPE, [$AS_TR_SH([psi_basic_type_]$1)])
86 dnl PSI_OPAQUE_TYPE(type name)
87 dnl Checks a type for being a scalar, a struct or a pointer type.
88 dnl Calls AC_TYPE_<TYPE> (if defined) and PSI_CHECK_SIZEOF.
89 dnl Defines a pre-defined type in $PSI_TYPES and a pre-defined struct in
90 dnl $PSI_STRUCTS if the type is a struct.
91 AC_DEFUN(PSI_OPAQUE_TYPE, [
92 ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1))
94 if PSI_SH_TEST_SIZEOF($1); then
96 AC_CACHE_CHECK(kind of $1, AS_TR_SH([psi_cv_type_class_]$1), [
97 AC_TRY_COMPILE(PSI_INCLUDES, [char test@<:@($1)1@:>@;], [
100 AC_TRY_COMPILE(PSI_INCLUDES, [$1 test = 0;], [
101 AC_TRY_COMPILE(PSI_INCLUDES, [$1 test = (($1)0)+1;], [
102 psi_type_class="pointer of known type"
104 psi_type_class="pointer of opaque type"
107 psi_type_class=struct
110 AS_TR_SH([psi_cv_type_class_]$1)="$psi_type_class"
112 case "$AS_TR_SH([psi_cv_type_class_]$1)" in
114 AX_CHECK_SIGN($1, [psi_basic_type=int], [psi_basic_type=uint], PSI_INCLUDES)
115 psi_add_type "{`psi_type_pair $psi_basic_type PSI_SH_SIZEOF($1)`, \"$1\"}"
121 psi_add_type "{PSI_T_POINTER, \"void\", \"$1\"}"
124 AC_MSG_WARN(could not detect kind of $1)
130 dnl PSI_VAR_TYPE(decl arg)
131 dnl Extracts the type of a decl arg, e.g. dnl unsigned char* buf[16] -> unsigned char*.
132 AC_DEFUN(PSI_VAR_TYPE, [m4_bregexp([$1], [^\(const \)?\(.*\) \([*]*\)[^ ]+$], [\2\3])])
134 dnl PSI_VAR_NAME(decl arg)
135 dnl Extracts the var name of a decl arg, e.g. unsigned char* buf[16] -> buf.
136 AC_DEFUN(PSI_VAR_NAME, [m4_bregexp(m4_bregexp([$1], [\([^ ]+\)$], [\1]), [\w+], [\&])])
138 dnl PSI_TYPE_INDIRECTION(decl arg, size, pointer_level_var, array_size_var)
139 dnl Calculates and assigns pointer_level and array_size of a decl arg to sh vars.
140 AC_DEFUN(PSI_TYPE_INDIRECTION, [
141 m4_define([psi_pointer_level], m4_len(m4_bpatsubst([PSI_VAR_TYPE($1)], [[^*]])))
142 m4_define([psi_array_size], [m4_bregexp([PSI_VAR_TYPE($1)], [@<:@\([0-9]+\)@:>@], [\1])])
144 ifelse(psi_array_size.$2,0., [
145 AC_MSG_ERROR([cannot compute dynamic array size of a non-struct member])
147 ifelse(psi_pointer_level,0,[
148 m4_define([psi_type_size],[$]AS_TR_SH([ac_cv_sizeof_]m4_bregexp(PSI_VAR_TYPE([$1]), [^\( \|\w\)+], [\&])))
150 m4_define([psi_type_size],$ac_cv_sizeof_void_p)
154 m4_case(psi_array_size,,[
158 $3=m4_incr(psi_pointer_level)
159 $4="`expr $2 / psi_type_size`"
161 $3=m4_incr(psi_pointer_level)
166 dnl PSI_TYPE_PAIR(type)
167 dnl Expand to a PSI_T_<TYPE>, \\"<TYPENAME>\\" tuple.
168 dnl FIXME: There is also psi_type_pair()?
169 AC_DEFUN(PSI_TYPE_PAIR, [m4_case(m4_bregexp([$1], [^\w+], [\&]),
170 [void], [PSI_T_VOID, \"void\"],
171 [struct], [PSI_T_STRUCT, \"m4_bregexp([$1], [^struct \(\w+\)], [\1])\"],
172 [union], [PSI_T_UNION, \"m4_bregexp([$1], [^union \(\w+\)], [\1])\"],
173 [PSI_T_NAME, \"m4_bregexp([$1], [^\(\w+ \)*\w+], [\&])\"])])
175 dnl PSI_CHECK_STD_TYPES()
176 dnl Checks for standard ANSI-C and stdint types.
177 AC_DEFUN(PSI_CHECK_STD_TYPES, [
178 AC_CHECK_HEADERS(stdint.h)
181 PSI_CHECK_SIZEOF(int8_t)
182 AC_CHECK_ALIGNOF(int8_t)
184 PSI_CHECK_SIZEOF(uint8_t)
185 AC_CHECK_ALIGNOF(uint8_t)
187 PSI_CHECK_SIZEOF(int16_t)
188 AC_CHECK_ALIGNOF(int16_t)
190 PSI_CHECK_SIZEOF(uint16_t)
191 AC_CHECK_ALIGNOF(uint16_t)
193 PSI_CHECK_SIZEOF(int32_t)
194 AC_CHECK_ALIGNOF(int32_t)
196 PSI_CHECK_SIZEOF(uint32_t)
197 AC_CHECK_ALIGNOF(uint32_t)
199 PSI_CHECK_SIZEOF(int64_t)
200 AC_CHECK_ALIGNOF(int64_t)
202 PSI_CHECK_SIZEOF(uint64_t)
203 AC_CHECK_ALIGNOF(uint64_t)
205 PSI_CHECK_SIZEOF(void *)
206 AC_CHECK_ALIGNOF(void *)
209 AC_CHECK_ALIGNOF(float)
211 AC_CHECK_ALIGNOF(double)
212 PSI_STDTYPE(long double)
213 AC_CHECK_ALIGNOF(long double)
215 PSI_STDTYPE(char, int)
216 AC_CHECK_ALIGNOF(char)
217 PSI_STDTYPE(signed char, int)
218 PSI_STDTYPE(unsigned char, uint)
219 PSI_STDTYPE(short, int)
220 AC_CHECK_ALIGNOF(short)
221 PSI_STDTYPE(short int, int)
222 PSI_STDTYPE(signed short, int)
223 PSI_STDTYPE(signed short int, int)
224 PSI_STDTYPE(unsigned short, uint)
225 PSI_STDTYPE(unsigned short int, uint)
226 PSI_STDTYPE(int, int)
227 AC_CHECK_ALIGNOF(int)
228 PSI_STDTYPE(signed int, int)
229 PSI_STDTYPE(signed, int)
230 PSI_STDTYPE(unsigned int, uint)
231 PSI_STDTYPE(unsigned, uint)
232 PSI_STDTYPE(long, int)
233 AC_CHECK_ALIGNOF(long)
234 PSI_STDTYPE(long int, int)
235 PSI_STDTYPE(signed long int, int)
236 PSI_STDTYPE(unsigned long, uint)
237 PSI_STDTYPE(unsigned long int, uint)
238 PSI_STDTYPE(long long, int)
239 AC_CHECK_ALIGNOF(long long)
240 PSI_STDTYPE(signed long long, int)
241 PSI_STDTYPE(signed long long int, int)
242 PSI_STDTYPE(unsigned long long, uint)
243 PSI_STDTYPE(unsigned long long int, uint)
244 dnl this must come after the check fo "unsigned long long int"; autoconf, wth?
245 PSI_STDTYPE(long long int, int)