build cleanup
[m6w6/ext-psi] / m4 / psi / psi_type.m4
1 psi_add_stdtype() {
2 if test "$2" != ""; then
3 local stdtype="
4 #ifdef $2
5 $1,
6 #endif
7 "
8 else
9 local stdtype=" $1,"
10 fi
11 PSI_STDTYPES="$PSI_STDTYPES
12 $stdtype"
13 }
14
15 # psi_type_pair(type, size)
16 # Output a PSI_T_<TYPE>, \"<TYPENAME>\" tuple.
17 # Uses stdint types when possible.
18 psi_type_pair() {
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 while expr "$psi_type_lower" : const >/dev/null; do
22 psi_type_lower=`printf "%s" "$psi_type_lower" | cut -d " " -f2-`
23 done
24 case $psi_type_lower in
25 int*|uint*)
26 local psi_type_upper=`printf "%s" "$psi_type_name" | tr a-z A-Z`
27 local psi_type_bits=`expr $2 \* 8`
28 echo "PSI_T_${psi_type_upper}${psi_type_bits}, \"${psi_type_lower}${psi_type_bits}_t\""
29 ;;
30 struct*)
31 echo "PSI_T_STRUCT, \"$2\""
32 ;;
33 union*)
34 echo "PSI_T_UNION, \"$2\""
35 ;;
36 void)
37 echo "PSI_T_VOID, \"void\""
38 ;;
39 *)
40 echo "PSI_T_NAME, \"$psi_type_name\""
41 ;;
42 esac
43 }
44
45 AC_DEFUN(PSI_STDTYPE, [
46 ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1))
47 PSI_CHECK_SIZEOF([$1], [ifelse([$1],bool,[
48 #ifdef HAVE_STDBOOL_H
49 # include <stdbool.h>
50 #endif
51 ])])
52 if PSI_SH_TEST_SIZEOF($1); then
53 m4_case(ifelse(,[$2],[$1],[$2]),
54 [bool],[psi_add_stdtype "{PSI_T_BOOL, \"bool\", NULL}" HAVE_BOOL],
55 [float],[psi_add_stdtype "{PSI_T_FLOAT, \"float\", NULL}"],
56 [double],[psi_add_stdtype "{PSI_T_DOUBLE, \"double\", NULL}"],
57 [long double],[psi_add_stdtype "{PSI_T_LONG_DOUBLE, \"long double\", NULL}" HAVE_LONG_DOUBLE],
58 [
59 AX_CHECK_SIGN($1, psi_basic_type=int, psi_basic_type=uint)
60 AS_TR_SH(psi_basic_type_$1)=$psi_basic_type
61 psi_add_stdtype "{`psi_type_pair $psi_basic_type PSI_SH_SIZEOF($1)`, \"$1\"}"
62 ])
63 fi
64 ])
65
66 dnl PSI_CHECK_STD_TYPES()
67 dnl Checks for standard ANSI-C, stdint and stdbool types.
68 AC_DEFUN(PSI_CHECK_STD_TYPES, [
69
70
71 PSI_CHECK_SIZEOF(void *)
72 AC_CHECK_ALIGNOF(void *)
73
74 PSI_STDTYPE(float)
75 AC_CHECK_ALIGNOF(float)
76 PSI_STDTYPE(double)
77 AC_CHECK_ALIGNOF(double)
78 PSI_STDTYPE(long double)
79 AC_CHECK_ALIGNOF(long double)
80
81 AC_HEADER_STDBOOL
82 PSI_STDTYPE(bool)
83 AC_CHECK_ALIGNOF(bool,[
84 #ifdef HAVE_STDBOOL_H
85 # include <stdbool.h>
86 #endif
87 ])
88
89 PSI_STDTYPE(char, int)
90 AC_CHECK_ALIGNOF(char)
91 PSI_STDTYPE(signed char, int)
92 PSI_STDTYPE(unsigned char, uint)
93 PSI_STDTYPE(short, int)
94 AC_CHECK_ALIGNOF(short)
95 PSI_STDTYPE(short int, int)
96 PSI_STDTYPE(signed short, int)
97 PSI_STDTYPE(signed short int, int)
98 PSI_STDTYPE(short signed, int)
99 PSI_STDTYPE(short signed int, int)
100 PSI_STDTYPE(unsigned short, uint)
101 PSI_STDTYPE(unsigned short int, uint)
102 PSI_STDTYPE(short unsigned, uint)
103 PSI_STDTYPE(short unsigned int, uint)
104 PSI_STDTYPE(int, int)
105 AC_CHECK_ALIGNOF(int)
106 PSI_STDTYPE(signed int, int)
107 PSI_STDTYPE(signed, int)
108 PSI_STDTYPE(unsigned int, uint)
109 PSI_STDTYPE(unsigned, uint)
110 PSI_STDTYPE(long, int)
111 AC_CHECK_ALIGNOF(long)
112 PSI_STDTYPE(long int, int)
113 PSI_STDTYPE(signed long int, int)
114 PSI_STDTYPE(long signed int, int)
115 PSI_STDTYPE(unsigned long, uint)
116 PSI_STDTYPE(unsigned long int, uint)
117 PSI_STDTYPE(long unsigned, uint)
118 PSI_STDTYPE(long unsigned int, uint)
119 PSI_STDTYPE(long long, int)
120 AC_CHECK_ALIGNOF(long long)
121 PSI_STDTYPE(signed long long, int)
122 PSI_STDTYPE(signed long long int, int)
123 PSI_STDTYPE(long signed long, int)
124 PSI_STDTYPE(long signed long int, int)
125 PSI_STDTYPE(long long signed, int)
126 PSI_STDTYPE(long long signed int, int)
127 PSI_STDTYPE(unsigned long long, uint)
128 PSI_STDTYPE(unsigned long long int, uint)
129 PSI_STDTYPE(long unsigned long, uint)
130 PSI_STDTYPE(long unsigned long int, uint)
131 PSI_STDTYPE(long long unsigned, uint)
132 PSI_STDTYPE(long long unsigned int, uint)
133 dnl this must come after the check for "unsigned long long int"; autoconf, wth?
134 PSI_STDTYPE(long long int, int)
135
136 AC_CHECK_TYPE(__int128, [
137 AC_DEFINE([HAVE_INT128], [1], [ ])
138 AC_CHECK_ALIGNOF(__int128)
139 PSI_STDTYPE(__int128, int)
140 PSI_STDTYPE(signed __int128, int)
141 PSI_STDTYPE(unsigned __int128, uint)
142 ])
143
144 PSI_STDTYPE(_Float32)
145 PSI_STDTYPE(_Float32x)
146 PSI_STDTYPE(_Float64)
147 PSI_STDTYPE(_Float64x)
148 PSI_STDTYPE(_Float128)
149 ])