#!/bin/sh
#	tras - translate assembler source from Apple to local
#
#	tras mumble.s		# output left on tmumble.s
#
trap "rm -f /tmp/sed$$" 0 1 2 15
cat <<EOT >/tmp/sed$$
s/;/|/
s/_[a-z][a-z]*/.word	_&/
s/@\([0-9]*\)/\1$/
s/ \.equ / =    /
/=/!s/^[^ |][^ |]*/&:/
s/\.[dr]ef/.globl/
s/\.func/.proc/
/ *\.proc */{
s///
i\\
\		.text
s/,.*$//
s/$/       /
s/^\(........\).*$/_\1/
s/ *$//
h
s/.*/		.globl	&/
G
s/$/:/
}
s/-(\(..\))/\1@-/g
s/\([-$+a-z0-9][-$+a-z0-9]*\)(\(..\),\(..\)\.\(.\))/\2@(\1,\3:\4)/g
s/\([-$+a-z0-9][-$+a-z0-9]*\)(\(..\))/\2@[\1)/g
s/(\(..\))/\1@/g
s/@\[/@(/g
s///g
s/\*\([-+]\)/.\1/g
s/ add[ai]/ add/
s/ add / addw /
s/ addq / addqw /
s/ andi/ and/
s/ and / andw /
s/ clr / clrw /
s/ cmp[aim]/ cmp/
s/ cmp / cmpw /
s/ eori/ eor/
s/ eor / eorw /
s/ movea/ move/
s/ move / movw /
s/ move\./  mov./
s/ neg / negw /
s/ not / notw /
s/ ori/ or/
s/ or / orw /
s/ sub[ai]/ sub/
s/ sub / subw /
s/ subq / subqw /
s/ tst / tstw /
s/$\([0-9a-f][0-9a-f]*\)/0x\1/g
s/\([a-z]\)\.\([lwbs]\)/\1\2/
s/   */	/g
EOT
tr "[A-Z]" "[a-z]" <$1 | sed -f /tmp/sed$$ >t$1
