]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/kern/genassym.sh
zfs: merge openzfs/zfs@797f55ef1
[FreeBSD/FreeBSD.git] / sys / kern / genassym.sh
1 #!/bin/sh
2
3 usage()
4 {
5         echo "usage: genassym [-o outfile] objfile"
6         exit 1
7 }
8
9
10 work()
11 {
12         ${NM:='nm'} ${NMFLAGS} "$1" | ${AWK:='awk'} '
13         / C .*sign$/ {
14                 sign = substr($1, length($1) - 3, 4)
15                 sub("^0*", "", sign)
16                 if (sign != "")
17                         sign = "-"
18         }
19         / C .*w0$/ {
20                 w0 = substr($1, length($1) - 3, 4)
21         }
22         / C .*w1$/ {
23                 w1 = substr($1, length($1) - 3, 4)
24         }
25         / C .*w2$/ {
26                 w2 = substr($1, length($1) - 3, 4)
27         }
28         / C .*w3$/ {
29                 w3 = substr($1, length($1) - 3, 4)
30                 w = w3 w2 w1 w0
31                 sub("^0*", "", w)
32                 if (w == "")
33                         w = "0"
34                 hex = ""
35                 if (w != "0")
36                         hex = "0x"
37                 sub("w3$", "", $3)
38                 # This still has minor problems representing INT_MIN, etc. 
39                 # E.g.,
40                 # with 32-bit 2''s complement ints, this prints -0x80000000,
41                 # which has the wrong type (unsigned int).
42                 printf("#define\t%s\t%s%s%s\n", $3, sign, hex, w)
43         } '
44 }
45
46
47 #
48 #MAIN PROGGRAM
49 #
50 use_outfile="no"
51 while getopts "o:" option
52 do
53         case "$option" in
54         o)      outfile="$OPTARG"
55                 use_outfile="yes";;
56         *)      usage;;
57         esac
58 done
59 shift $((OPTIND - 1))
60 case $# in
61 1)      ;;
62 *)      usage;;
63 esac
64
65 if [ "$use_outfile" = "yes" ]
66 then
67         work "$1"  3>"$outfile" >&3 3>&-
68 else
69         work "$1"
70 fi
71