2000-06-02 09:27:48 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# $FreeBSD$
|
|
|
|
|
2001-12-27 20:16:21 +00:00
|
|
|
usage()
|
|
|
|
{
|
2000-06-02 09:27:48 +00:00
|
|
|
echo "usage: genassym [-o outfile] objfile"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2008-01-18 17:02:14 +00:00
|
|
|
|
|
|
|
work()
|
|
|
|
{
|
2015-08-14 22:57:13 +00:00
|
|
|
${NM:='nm'} ${NMFLAGS} "$1" | ${AWK:='awk'} '
|
2008-01-18 17:02:14 +00:00
|
|
|
/ C .*sign$/ {
|
|
|
|
sign = substr($1, length($1) - 3, 4)
|
|
|
|
sub("^0*", "", sign)
|
|
|
|
if (sign != "")
|
|
|
|
sign = "-"
|
|
|
|
}
|
|
|
|
/ C .*w0$/ {
|
|
|
|
w0 = substr($1, length($1) - 3, 4)
|
|
|
|
}
|
|
|
|
/ C .*w1$/ {
|
|
|
|
w1 = substr($1, length($1) - 3, 4)
|
|
|
|
}
|
|
|
|
/ C .*w2$/ {
|
|
|
|
w2 = substr($1, length($1) - 3, 4)
|
|
|
|
}
|
|
|
|
/ C .*w3$/ {
|
|
|
|
w3 = substr($1, length($1) - 3, 4)
|
|
|
|
w = w3 w2 w1 w0
|
|
|
|
sub("^0*", "", w)
|
|
|
|
if (w == "")
|
|
|
|
w = "0"
|
2017-04-13 15:43:44 +00:00
|
|
|
hex = ""
|
|
|
|
if (w != "0")
|
|
|
|
hex = "0x"
|
2008-01-18 17:02:14 +00:00
|
|
|
sub("w3$", "", $3)
|
|
|
|
# This still has minor problems representing INT_MIN, etc.
|
|
|
|
# E.g.,
|
|
|
|
# with 32-bit 2''s complement ints, this prints -0x80000000,
|
|
|
|
# which has the wrong type (unsigned int).
|
2017-04-13 15:43:44 +00:00
|
|
|
printf("#define\t%s\t%s%s%s\n", $3, sign, hex, w)
|
2008-01-18 17:02:14 +00:00
|
|
|
} '
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#MAIN PROGGRAM
|
|
|
|
#
|
|
|
|
use_outfile="no"
|
2000-06-02 09:27:48 +00:00
|
|
|
while getopts "o:" option
|
|
|
|
do
|
|
|
|
case "$option" in
|
2008-01-18 17:02:14 +00:00
|
|
|
o) outfile="$OPTARG"
|
|
|
|
use_outfile="yes";;
|
2000-06-02 09:27:48 +00:00
|
|
|
*) usage;;
|
|
|
|
esac
|
|
|
|
done
|
2021-07-28 19:42:29 +00:00
|
|
|
shift $((OPTIND - 1))
|
2000-06-02 09:27:48 +00:00
|
|
|
case $# in
|
|
|
|
1) ;;
|
|
|
|
*) usage;;
|
|
|
|
esac
|
|
|
|
|
2008-01-18 17:02:14 +00:00
|
|
|
if [ "$use_outfile" = "yes" ]
|
|
|
|
then
|
2021-07-28 19:42:29 +00:00
|
|
|
work "$1" 3>"$outfile" >&3 3>&-
|
2008-01-18 17:02:14 +00:00
|
|
|
else
|
2021-07-28 19:42:29 +00:00
|
|
|
work "$1"
|
2008-01-18 17:02:14 +00:00
|
|
|
fi
|
|
|
|
|