add abi_*.cc
[musl-tools.git] / abi_type.sh
blobbe445afbe035da33aa1fec766c64a08a77f38c96
1 #!/bin/sh
3 export LC_ALL=C
5 ALL='
6 aarch64
7 arm
8 i386
9 microblaze
10 mips
11 mips64
12 or1k
13 powerpc
14 powerpc64
16 x32
17 x86_64
19 ARCH="${ARCH:-$ALL}"
21 # install headers to T.$arch
22 for arch in $ARCH
26 awk -F'\t' '$3 ~ /^[sutSUT]$/ {
27 print $1
28 }' data/musl.generic.decls data/musl.$arch.decls
29 echo 'char
30 short
31 int
32 long
33 long_long
34 float
35 double
36 long_double
37 wchar_t
38 bool
39 void'
40 } |sort |uniq >/tmp/m.$arch.type
42 awk -F'\t' '{print $2}' data/musl.generic.decls |sort |uniq >/tmp/m.header
44 echo '
45 #define _GNU_SOURCE 1
46 #define _FILE_OFFSET_BITS 64
47 #define SYSLOG_NAMES 1
48 #include <stddef.h>
49 #include <sys/types.h>
50 ' >abi_type.$arch.cc
52 awk '
53 /^sys\/(auxv|cachectl|fantotify|errno|fcntl|io|kd|poll|reg|signal|soundcard|termios|vt)\.h$/ { printf "//" }
54 /^(stdalign|stdnoreturn|threads|wait)\.h$/ { printf "//" }
55 { print "#include <" $0 ">" }' /tmp/m.header >>abi_type.$arch.cc
57 echo '
58 typedef long long long_long;
59 typedef long double long_double;
60 struct size {char c;};
61 struct align {char c;};
62 #define T(s,t) void x_##t(s t x, s t* ptr, size(*y)[sizeof(s t)], align(*z)[__alignof__(s t)]){}
63 #define P(s,t) void y_##t(s t* ptr, size(*y)[sizeof(s t*)], align(*z)[__alignof__(s t*)]){}
64 #ifdef __GLIBC__
65 #define M(x)
66 #else
67 #define M(x) x
68 #endif
69 ' >>abi_type.$arch.cc
71 awk '
72 /^(once_flag|mtx_t|cnd_t|thrd_start_t|thrd_t|tss_dtor_t|tss_t)$/ ||
73 /^(struct|union) __(CODE|ptcb|siginfo|ucontext|sigjmp_buf|double_repr|float_repr|sigset_t|mbstate_t|fsid_t|locale_struct)$/ ||
74 /^(elf_fpxregset_t|struct user_fpxregs_struct|Sg_io_vec|struct ih_.*|struct ip6_hdrctl|tcp_seq|union _G_fpos64_t|struct cpu_set_t|__isoc_va_list|ns_tcp_tsig.*|ns_tsig_.*|struct ptrace_peeksiginfo_.*)$/ { printf "//" }
75 { if (!sub(/ /,",")) sub(/^/,",") }
76 /,(DIR|FILE|void)$/ { print "P(" $0 ")"; next }
77 { print "T(" $0 ")" }' /tmp/m.$arch.type >>abi_type.$arch.cc
78 done
80 #$CXX -S -o - abi_type.cc |sed -n 's/^\(_Z.*\):/\1/p' |$CXXFILT |sed '
81 #s/^x_\([^(]*\)(\(.*\))/\1: \2/
82 #s/^y_\([^(]*\)(\(.*\))/\1*: \2/
83 #s/floatcomplex /float _Complex/g
84 #s/doublecomplex /double _Complex/g
85 #' >data/musl.abi_type