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