xref: /illumos-gate/usr/src/contrib/ast/src/lib/libast/astsa/mkast_sa (revision 763f1f5f97e4c16840af2ced98915f0ed0f46616)
1: generate ast_sa.h
2case $# in
30)	set cc ;;
4esac
5cat > _ast_.c <<'!'
6	#define _BYTESEX_H
7
8	#include <stdio.h>
9	#include <sys/types.h>
10
11	#if N == 0
12	#define _ast_int8_t	long
13	#define _ast_int8_str	"long"
14	#endif
15	#if N == 1
16	#define _ast_int8_t	long long
17	#define _ast_int8_str	"long long"
18	#endif
19	#if N == 2
20	#define _ast_int8_t	__int64_t
21	#define _ast_int8_str	"__int64_t"
22	#endif
23	#if N == 3
24	#define _ast_int8_t	_int64_t
25	#define _ast_int8_str	"_int64_t"
26	#endif
27	#if N == 4
28	#define _ast_int8_t	int64_t
29	#define _ast_int8_str	"int64_t"
30	#endif
31	#if N == 5
32	#define _ast_int8_t	__int64
33	#define _ast_int8_str	"__int64"
34	#endif
35	#if N == 6
36	#define _ast_int8_t	_int64
37	#define _ast_int8_str	"_int64"
38	#endif
39	#if N == 7
40	#define _ast_int8_t	int64
41	#define _ast_int8_str	"int64"
42	#endif
43
44	#define elementsof(x)	(sizeof(x)/sizeof(x[0]))
45
46	static char		i_char = 1;
47	static short		i_short = 1;
48	static int		i_int = 1;
49	static long		i_long = 1;
50	#ifdef _ast_int8_t
51	static _ast_int8_t	i_long_long = 1;
52	#endif
53
54	static struct
55	{
56		char*	name;
57		int	size;
58		char*	swap;
59	} int_type[] =
60	{
61		"char",		sizeof(char),		(char*)&i_char,
62		"short",	sizeof(short),		(char*)&i_short,
63		"int",		sizeof(int),		(char*)&i_int,
64		"long",		sizeof(long),		(char*)&i_long,
65	#ifdef _ast_int8_t
66		_ast_int8_str,	sizeof(_ast_int8_t),	(char*)&i_long_long,
67	#endif
68	};
69
70	static struct
71	{
72		char*	name;
73		int	size;
74	} flt_type[] =
75	{
76		"float",	sizeof(float),
77		"double",	sizeof(double),
78	#ifdef _typ_long_double
79		"long double",	sizeof(long double),
80	#endif
81	};
82
83	static int	int_size[] = { 1, 2, 4, 8 };
84
85	main()
86	{
87		register int	t;
88		register int	s;
89		register int	m = 1;
90		register int	b = 1;
91		register int	w = 0;
92
93	#ifdef _ast_int8_t
94		if (int_type[elementsof(int_type)-1].size <= 4)
95			return 1;
96	#endif
97		for (s = 0; s < elementsof(int_size); s++)
98		{
99			for (t = 0; t < elementsof(int_type) && int_type[t].size < int_size[s]; t++);
100			if (t < elementsof(int_type))
101			{
102				m = int_size[s];
103				printf("#define _ast_int%d_t		%s\n", m, int_type[t].name);
104				if (m > 1)
105				{
106					if (*int_type[t].swap)
107						w |= b;
108					b <<= 1;
109				}
110			}
111		}
112		printf("#define _ast_intmax_t		_ast_int%d_t\n", m);
113		if (m == sizeof(long))
114			printf("#define _ast_intmax_long		1\n");
115		printf("#define _ast_intswap		%d\n", w);
116		printf("\n");
117		for (t = 0; t < elementsof(flt_type); t++)
118		{
119			while (t < elementsof(flt_type) && flt_type[t].size == flt_type[t + 1].size)
120				t++;
121			m = flt_type[t].size;
122			printf("#define _ast_flt%d_t		%s\n", flt_type[t].size, flt_type[t].name);
123		}
124		printf("#define _ast_fltmax_t		_ast_flt%d_t\n", m);
125		if (m == sizeof(double))
126			printf("#define _ast_fltmax_double		1\n");
127		return 0;
128	}
129!
130echo "#ifndef _AST_SA_H"
131echo "#define _AST_SA_H		1"
132echo
133for i in '' -DN=0 -DN=1 -DN=2 -DN=3 -DN=4 -DN=5 -DN=6 -DN=7 -DN=8
134do	"$@" $i -o _ast_.exe _ast_.c 2> /dev/null &&
135	./_ast_.exe &&
136	break
137done
138echo '#include <stdint.h>' > _ast_.c
139if	"$@" -E _ast_.c > /dev/null 2>&1
140then	echo "#define _hdr_stdint	1"
141fi
142echo '#include <unistd.h>' > _ast_.c
143if	"$@" -E _ast_.c > /dev/null 2>&1
144then	echo "#define _hdr_unistd	1"
145fi
146rm -f _ast_.c _ast_.exe
147echo "#define __DEFINE__(T,obj,val)	T obj = val"
148echo "#define __EXTERN__(T,obj)		extern T obj"
149echo
150echo "#endif"
151