genassym.sh revision 61174
1#!/bin/sh
2# $FreeBSD: head/sys/kern/genassym.sh 61174 2000-06-02 09:27:48Z bde $
3
4# Grrr, this should use stdin and stdout, but is encrufted for compatibility.
5
6usage() {
7	echo "usage: genassym [-o outfile] objfile"
8	exit 1
9}
10
11outfile=/dev/stdout
12while getopts "o:" option
13do
14	case "$option" in
15	o)	outfile="$OPTARG";;
16	*)	usage;;
17	esac
18done
19shift $(($OPTIND - 1))
20case $# in
211)	;;
22*)	usage;;
23esac
24
25nm "$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>&-
54