1 # psi_add_type(type triplet)
2 # Add a pre-defined type to $PSI_TYPES.
4 cat >>$PSI_TYPES <<<" $1, "
8 cat >>$PSI_STDTYPES <<<" $1, "
11 # psi_type_pair(type, size)
12 # Output a PSI_T_<TYPE>, \"<TYPENAME>\" tuple.
13 # Uses stdint types when possible.
15 local psi_type_name=`tr -cd A-Za-z0-9_ <<<$1`
16 local psi_type_lower=`tr A-Z a-z <<<$psi_type_name`
17 case $psi_type_lower in
19 local psi_type_upper=`tr a-z A-Z <<<$psi_type_name`
20 local psi_type_bits=`expr $2 \* 8`
21 echo "PSI_T_${psi_type_upper}${psi_type_bits}, \"${psi_type_lower}${psi_type_bits}_t\""
24 echo "PSI_T_STRUCT, \"$2\""
27 echo "PSI_T_UNION, \"$2\""
30 echo "PSI_T_VOID, \"void\""
33 echo "PSI_T_NAME, \"$psi_type_name\""
38 dnl PSI_TYPE(type name, basic type)
39 dnl Check for a specific type, optionally referring to a basic type.
40 dnl Calls AC_TYPE_<TYPE> (if defined) and PSI_CHECK_SIZEOF.
41 dnl If the basic type is just specified as "int" (in contrast to "sint" or
42 dnl "uint"), AX_CHECK_SIGN is used to discover signedness of the type.
43 dnl Defines a pre-defined type in $PSI_TYPES.
45 ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1))
47 psi_basic_type=AS_TR_SH($2)
48 case $psi_basic_type in
50 AX_CHECK_SIGN($1, :, [psi_basic_type=uint], PSI_INCLUDES)
56 if test "$2" && PSI_SH_TEST_SIZEOF($1); then
57 AS_TR_SH(psi_basic_type_$1)=$psi_basic_type
58 psi_add_type "{`psi_type_pair $psi_basic_type PSI_SH_SIZEOF($1)`, \"$1\"}"
62 AC_DEFUN(PSI_STDTYPE, [
63 ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1))
65 if PSI_SH_TEST_SIZEOF($1); then
67 [float],[psi_add_stdtype "{PSI_T_FLOAT, \"float\", NULL}"],
68 [double],[psi_add_stdtype "{PSI_T_DOUBLE, \"double\", NULL}"],
69 [long double],[psi_add_stdtype "{PSI_T_LONG_DOUBLE, \"long double\", NULL}"],
71 AX_CHECK_SIGN($1, psi_basic_type=int, psi_basic_type=uint, PSI_INCLUDES)
72 AS_TR_SH(psi_basic_type_$1)=$psi_basic_type
73 psi_add_stdtype "{`psi_type_pair $psi_basic_type PSI_SH_SIZEOF($1)`, \"$1\"}"
78 dnl PSI_SH_BASIC_TYPE(type)
79 dnl Expand to the basic type (int/uint) of a distinct type
80 AC_DEFUN(PSI_SH_BASIC_TYPE, [$AS_TR_SH([psi_basic_type_]$1)])
82 dnl PSI_OPAQUE_TYPE(type name)
83 dnl Checks a type for being a scalar, a struct or a pointer type.
84 dnl Calls AC_TYPE_<TYPE> (if defined) and PSI_CHECK_SIZEOF.
85 dnl Defines a pre-defined type in $PSI_TYPES and a pre-defined struct in
86 dnl $PSI_STRUCTS if the type is a struct.
87 AC_DEFUN(PSI_OPAQUE_TYPE, [
88 ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1))
90 if PSI_SH_TEST_SIZEOF($1); then
92 AC_CACHE_CHECK(kind of $1, AS_TR_SH([psi_cv_type_class_]$1), [
93 AC_TRY_COMPILE(PSI_INCLUDES, [char test@<:@($1)1@:>@;], [
96 AC_TRY_COMPILE(PSI_INCLUDES, [$1 test = 0;], [
97 AC_TRY_COMPILE(PSI_INCLUDES, [$1 test = (($1)0)+1;], [
98 psi_type_class="pointer of known type"
100 psi_type_class="pointer of opaque type"
103 psi_type_class=struct
106 AS_TR_SH([psi_cv_type_class_]$1)="$psi_type_class"
108 case "$AS_TR_SH([psi_cv_type_class_]$1)" in
110 AX_CHECK_SIGN($1, [psi_basic_type=int], [psi_basic_type=uint], PSI_INCLUDES)
111 psi_add_type "{`psi_type_pair $psi_basic_type PSI_SH_SIZEOF($1)`, \"$1\"}"
117 psi_add_type "{PSI_T_POINTER, \"void\", \"$1\"}"
120 AC_MSG_WARN(could not detect kind of $1)
126 dnl PSI_VAR_TYPE(decl arg)
127 dnl Extracts the type of a decl arg, e.g. dnl unsigned char* buf[16] -> unsigned char*.
128 AC_DEFUN(PSI_VAR_TYPE, [m4_bregexp([$1], [^\(const \)?\(.*\) \([*]*\)[^ ]+$], [\2\3])])
130 dnl PSI_VAR_NAME(decl arg)
131 dnl Extracts the var name of a decl arg, e.g. unsigned char* buf[16] -> buf.
132 AC_DEFUN(PSI_VAR_NAME, [m4_bregexp(m4_bregexp([$1], [\([^ ]+\)$], [\1]), [\w+], [\&])])
134 dnl PSI_TYPE_INDIRECTION(decl arg, size, pointer_level_var, array_size_var)
135 dnl Calculates and assigns pointer_level and array_size of a decl arg to sh vars.
136 AC_DEFUN(PSI_TYPE_INDIRECTION, [
137 m4_define([psi_pointer_level], m4_len(m4_bpatsubst([PSI_VAR_TYPE($1)], [[^*]])))
138 m4_define([psi_array_size], [m4_bregexp([PSI_VAR_TYPE($1)], [@<:@\([0-9]+\)@:>@], [\1])])
140 ifelse(psi_array_size.$2,0., [
141 AC_MSG_ERROR([cannot compute dynamic array size of a non-struct member])
143 ifelse(psi_pointer_level,0,[
144 m4_define([psi_type_size],[$]AS_TR_SH([ac_cv_sizeof_]m4_bregexp(PSI_VAR_TYPE([$1]), [^\( \|\w\)+], [\&])))
146 m4_define([psi_type_size],$ac_cv_sizeof_void_p)
150 m4_case(psi_array_size,,[
154 $3=m4_incr(psi_pointer_level)
155 $4="`expr $2 / psi_type_size`"
157 $3=m4_incr(psi_pointer_level)
162 dnl PSI_TYPE_PAIR(type)
163 dnl Expand to a PSI_T_<TYPE>, \\"<TYPENAME>\\" tuple.
164 dnl FIXME: There is also psi_type_pair()?
165 AC_DEFUN(PSI_TYPE_PAIR, [m4_case(m4_bregexp([$1], [^\w+], [\&]),
166 [void], [PSI_T_VOID, \"void\"],
167 [struct], [PSI_T_STRUCT, \"m4_bregexp([$1], [^struct \(\w+\)], [\1])\"],
168 [union], [PSI_T_UNION, \"m4_bregexp([$1], [^union \(\w+\)], [\1])\"],
169 [PSI_T_NAME, \"m4_bregexp([$1], [^\(\w+ \)*\w+], [\&])\"])])
171 dnl PSI_CHECK_STD_TYPES()
172 dnl Checks for standard ANSI-C and stdint types.
173 AC_DEFUN(PSI_CHECK_STD_TYPES, [
174 AC_CHECK_HEADERS(stdint.h)
177 PSI_CHECK_SIZEOF(int8_t)
178 AC_CHECK_ALIGNOF(int8_t)
180 PSI_CHECK_SIZEOF(uint8_t)
181 AC_CHECK_ALIGNOF(uint8_t)
183 PSI_CHECK_SIZEOF(int16_t)
184 AC_CHECK_ALIGNOF(int16_t)
186 PSI_CHECK_SIZEOF(uint16_t)
187 AC_CHECK_ALIGNOF(uint16_t)
189 PSI_CHECK_SIZEOF(int32_t)
190 AC_CHECK_ALIGNOF(int32_t)
192 PSI_CHECK_SIZEOF(uint32_t)
193 AC_CHECK_ALIGNOF(uint32_t)
195 PSI_CHECK_SIZEOF(int64_t)
196 AC_CHECK_ALIGNOF(int64_t)
198 PSI_CHECK_SIZEOF(uint64_t)
199 AC_CHECK_ALIGNOF(uint64_t)
201 PSI_CHECK_SIZEOF(void *)
202 AC_CHECK_ALIGNOF(void *)
205 AC_CHECK_ALIGNOF(float)
207 AC_CHECK_ALIGNOF(double)
208 PSI_STDTYPE(long double)
209 AC_CHECK_ALIGNOF(long double)
211 PSI_STDTYPE(char, int)
212 AC_CHECK_ALIGNOF(char)
213 PSI_STDTYPE(signed char, int)
214 PSI_STDTYPE(unsigned char, uint)
215 PSI_STDTYPE(short, int)
216 AC_CHECK_ALIGNOF(short)
217 PSI_STDTYPE(short int, int)
218 PSI_STDTYPE(signed short, int)
219 PSI_STDTYPE(signed short int, int)
220 PSI_STDTYPE(unsigned short, uint)
221 PSI_STDTYPE(unsigned short int, uint)
222 PSI_STDTYPE(int, int)
223 AC_CHECK_ALIGNOF(int)
224 PSI_STDTYPE(signed int, int)
225 PSI_STDTYPE(signed, int)
226 PSI_STDTYPE(unsigned int, uint)
227 PSI_STDTYPE(unsigned, uint)
228 PSI_STDTYPE(long, int)
229 AC_CHECK_ALIGNOF(long)
230 PSI_STDTYPE(long int, int)
231 PSI_STDTYPE(signed long int, int)
232 PSI_STDTYPE(unsigned long, uint)
233 PSI_STDTYPE(unsigned long int, uint)
234 PSI_STDTYPE(long long, int)
235 AC_CHECK_ALIGNOF(long long)
236 PSI_STDTYPE(signed long long, int)
237 PSI_STDTYPE(signed long long int, int)
238 PSI_STDTYPE(unsigned long long, uint)
239 PSI_STDTYPE(unsigned long long int, uint)
240 dnl this must come after the check fo "unsigned long long int"; autoconf, wth?
241 PSI_STDTYPE(long long int, int)