FreeBSD/Linux Kernel Cross Reference
sys/kern/genassym.sh
1 #!/bin/sh
2 # $FreeBSD$
3
4 # Grrr, this should use stdin and stdout, but is encrufted for compatibility.
5
6 usage() {
7 echo "usage: genassym [-o outfile] objfile"
8 exit 1
9 }
10
11 outfile=/dev/stdout
12 while getopts "o:" option
13 do
14 case "$option" in
15 o) outfile="$OPTARG";;
16 *) usage;;
17 esac
18 done
19 shift $(($OPTIND - 1))
20 case $# in
21 1) ;;
22 *) usage;;
23 esac
24
25 nm "$1" | awk '
26 / C .*sign$/ {
27 sign = substr($1, length($1) - 3, 4)
28 sub("^0*", "", sign)
29 if (sign != "")
30 sign = "-"
31 }
32 / C .*w0$/ {
33 w0 = substr($1, length($1) - 3, 4)
34 }
35 / C .*w1$/ {
36 w1 = substr($1, length($1) - 3, 4)
37 }
38 / C .*w2$/ {
39 w2 = substr($1, length($1) - 3, 4)
40 }
41 / C .*w3$/ {
42 w3 = substr($1, length($1) - 3, 4)
43 w = w3 w2 w1 w0
44 sub("^0*", "", w)
45 if (w == "")
46 w = "0"
47 sub("w3$", "", $3)
48 # This still has minor problems representing INT_MIN, etc. E.g.,
49 # with 32-bit 2''s complement ints, this prints -0x80000000, which
50 # has the wrong type (unsigned int).
51 printf("#define\t%s\t%s0x%s\n", $3, sign, w)
52 }
53 ' 3>"$outfile" >&3 3>&-
Cache object: 9188921b4e812f69098bbe1aaf0f5074
|