2017-04-23 Jerry DeLisle <jvdelisle@gcc.gnu.org>
[official-gcc.git] / libgo / mkrsysinfo.sh
blobaf1859450108f687bc94b3c98b96fd90cb912f19
1 #!/bin/sh
3 # Copyright 2016 The Go Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file.
7 # Create runtime_sysinfo.go from gen-sysinfo.go and errno.i.
9 OUT=tmp-runtime_sysinfo.go
11 set -e
13 echo 'package runtime' > ${OUT}
15 # Get all the consts and types, skipping ones which could not be
16 # represented in Go and ones which we need to rewrite. We also skip
17 # function declarations, as we don't need them here. All the symbols
18 # will all have a leading underscore.
19 grep -v '^// ' gen-sysinfo.go | \
20 grep -v '^func' | \
21 grep -v '^var ' | \
22 grep -v '^type _timeval ' | \
23 grep -v '^type _timespec_t ' | \
24 grep -v '^type _timespec ' | \
25 grep -v '^type _epoll_' | \
26 grep -v 'in6_addr' | \
27 grep -v 'sockaddr_in6' | \
28 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1timeval\2/g' \
29 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
30 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
31 >> ${OUT}
33 # The time structures need special handling: we need to name the
34 # types, so that we can cast integers to the right types when
35 # assigning to the structures.
36 timeval=`grep '^type _timeval ' gen-sysinfo.go`
37 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
38 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
39 echo "type timeval_sec_t $timeval_sec" >> ${OUT}
40 echo "type timeval_usec_t $timeval_usec" >> ${OUT}
41 echo $timeval | \
42 sed -e 's/type _timeval /type timeval /' \
43 -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timeval_sec_t/' \
44 -e 's/tv_usec *[a-zA-Z0-9_]*/tv_usec timeval_usec_t/' >> ${OUT}
45 echo >> ${OUT}
46 echo "func (tv *timeval) set_usec(x int32) {" >> ${OUT}
47 echo " tv.tv_usec = timeval_usec_t(x)" >> ${OUT}
48 echo "}" >> ${OUT}
50 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
51 if test "$timespec" = ""; then
52 # IRIX 6.5 has __timespec instead.
53 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
55 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
56 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
57 echo "type timespec_sec_t $timespec_sec" >> ${OUT}
58 echo "type timespec_nsec_t $timespec_nsec" >> ${OUT}
59 echo $timespec | \
60 sed -e 's/^type ___timespec /type timespec /' \
61 -e 's/^type _timespec /type timespec /' \
62 -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timespec_sec_t/' \
63 -e 's/tv_nsec *[a-zA-Z0-9_]*/tv_nsec timespec_nsec_t/' >> ${OUT}
64 echo >> ${OUT}
65 echo "func (ts *timespec) set_sec(x int64) {" >> ${OUT}
66 echo " ts.tv_sec = timespec_sec_t(x)" >> ${OUT}
67 echo "}" >> ${OUT}
68 echo >> ${OUT}
69 echo "func (ts *timespec) set_nsec(x int32) {" >> ${OUT}
70 echo " ts.tv_nsec = timespec_nsec_t(x)" >> ${OUT}
71 echo "}" >> ${OUT}
73 # Define the epollevent struct. This needs special attention because
74 # the C definition uses a union and is sometimes packed.
75 if grep '^const _epoll_data_offset ' ${OUT} >/dev/null 2>&1; then
76 val=`grep '^const _epoll_data_offset ' ${OUT} | sed -e 's/const _epoll_data_offset = \(.*\)$/\1/'`
77 if test "$val" = "4"; then
78 echo 'type epollevent struct { events uint32; data [8]byte }' >> ${OUT}
79 elif test "$val" = "8"; then
80 echo 'type epollevent struct { events uint32; pad [4]byte; data [8]byte }' >> ${OUT}
81 else
82 echo 1>&2 "unknown epoll data offset value ${val}"
83 exit 1
86 # Make sure EPOLLET is positive.
87 if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go > /dev/null 2>&1; then
88 echo "const _EPOLLETpos = _EPOLLET" >> ${OUT}
89 else
90 echo "const _EPOLLETpos = 0x80000000" >> ${OUT}
92 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
93 if ! grep '^const _EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
94 echo "const _EPOLLRDHUP = 0x2000" >> ${OUT}
96 if ! grep '^const _EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
97 echo "const _EPOLL_CLOEXEC = 02000000" >> ${OUT}
100 # The semt structure, for Solaris.
101 grep '^type _sem_t ' gen-sysinfo.go | \
102 sed -e 's/_sem_t/semt/' >> ${OUT}
104 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
105 # double is commented by -fdump-go-spec.
106 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
107 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
109 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
110 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
113 # The Solaris 11 Update 1 _zone_net_addr_t struct.
114 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
115 sed -e 's/_in6_addr/[16]byte/' \
116 >> ${OUT}
118 # The Solaris 12 _flow_arp_desc_t struct.
119 grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
120 sed -e 's/_in6_addr_t/[16]byte/g' \
121 >> ${OUT}
123 # The Solaris 12 _flow_l3_desc_t struct.
124 grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
125 sed -e 's/_in6_addr_t/[16]byte/g' \
126 >> ${OUT}
128 # The Solaris 12 _mac_ipaddr_t struct.
129 grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
130 sed -e 's/_in6_addr_t/[16]byte/g' \
131 >> ${OUT}
133 # The Solaris 12 _mactun_info_t struct.
134 grep '^type _mactun_info_t ' gen-sysinfo.go | \
135 sed -e 's/_in6_addr_t/[16]byte/g' \
136 >> ${OUT}
138 # The Solaris port_event_t struct.
139 grep '^type _port_event_t ' gen-sysinfo.go | \
140 sed -e s'/_port_event_t/portevent/' \
141 >> ${OUT}
143 # The *BSD kevent struct.
144 grep '^type _kevent ' gen-sysinfo.go | \
145 sed -e s'/_kevent/keventt/' \
146 -e 's/ udata [^;}]*/ udata *byte/' \
147 >> ${OUT}