TOOLDIR=${TOOLDIR:-/usr/MC88000/sgs2.0};
TMPDIR=${TMPDIR:-/tmp}
SGS=`basename $0 as`
if [ x$SGS = xas ]
then
	SGS=
fi

#  script to call sifilter with assembler call
#  Charles Wolff  2/12/88
#  changed grep to fgrep 880219saj

#  set traps for normal, interrupt exits

	trap "rm -f $TMPDIR/sif$$ ; exit 0" 0
	trap "rm -f $TMPDIR/sif$$ ; exit 1" 2


#  check for -o, sifilter options on call

	SIFOPTS=
	ASOPTS=

# int	ismot = TRUE;		 /*  -g: select Green Hills vs. Mot compiler */
# int 	verbose = FALSE; 	 /*  -v: put additional comments in output   */
# int 	statistics  = FALSE;	 /*  -s: display statistics at end of run    */
# int	strip_comments = FALSE;  /*  -c: all comments stripped from output   */
# int	dummy_before_ld = FALSE; /*  -q: put dummy load before loads         */
# int	trap_before_st = FALSE;	 /*  -p: put traps before stores	     */
# int   trap_after_ld = FALSE;   /*  -a: put traps after loads               */
# int   nop_after_ld = FALSE;    /*  -k: add nops after traps after loads    */
# int	double_st = FALSE;       /*  -d: issue stores twice                  */
# int   trap_after_st = FALSE;   /*  -z: put traps after stores              */
# int   nop_after_st = FALSE;    /*  -y: put nops after traps after stores   */
# int	is_absoft = FALSE;       /*  -f: input generated by FORTRAN compiler */
# int	split_loads = FALSE;	 /*  -l: split ld.d into two ld's */
# int	move_float = FALSE;	 /*  -m: split ld.d into two ld's */
# int	split_stores = FALSE;	 /*  -b: split st.d into two st's */
# int	nop_before_st = FALSE;	 /*  -n: put nop after trap before store     */
# int	allow_litsyn = FALSE;    /*  -e: enable literal synthesis */

	while true; do
		case $1 in
			-a )	SIFOPTS="$SIFOPTS -a"
				shift
				;;
			-b )	SIFOPTS="$SIFOPTS -b"
				shift
				;;
			-c )	SIFOPTS="$SIFOPTS -c"
				shift
				;;
			-d )	SIFOPTS="$SIFOPTS -d"
				shift
				;;
			-e )	SIFOPTS="$SIFOPTS -e"
				shift
				;;
			-f )	SIFOPTS="$SIFOPTS -f"
				shift
				;;
			-j )	SIFOPTS="$SIFOPTS -j"
				shift
				;;
			-k )	SIFOPTS="$SIFOPTS -k"
				shift
				;;
			-l )	SIFOPTS="$SIFOPTS -l"
				shift
				;;
			-m )	SIFOPTS="$SIFOPTS -m"
				shift
				;;
			-n )	SIFOPTS="$SIFOPTS -n"
				shift
				;;
			-s )	SIFOPTS="$SIFOPTS -s"
				shift
				;;
			-o)	ASOPTS="$1 $2"
				shift
				shift
				;;
			-p )	SIFOPTS="$SIFOPTS -p"
				shift
				;;
			-q )	SIFOPTS="$SIFOPTS -q"
				shift
				;;
			-v )	SIFOPTS="$SIFOPTS -v"
				shift
				;;
			-y )	SIFOPTS="$SIFOPTS -y"
				shift
				;;
			-w )	SIFOPTS="$SIFOPTS -w"
				shift
				;;
			*)	break
				;;
		esac
	done

#  if there was not a -o option on the call, generate one from input file name

	if [ "x$ASOPTS" = x ]
	then
		ONAME=`dirname $1`/`basename $1 .s`.o
		ASOPTS="-o $ONAME"
	fi

#  execute sifilter to patch assembler instructions

#	echo "===silicon fix filter: options ${SIFOPTS}"
	${TOOLDIR}/bin/${SGS}sifilter ${SIFOPTS} $1 $TMPDIR/sif$$

#  execute actual assembler, using real or generated -o option

	${TOOLDIR}/lib/${SGS}as $ASOPTS $TMPDIR/sif$$

#  traps will remove the temp file, whether we fall out cleanly or interrupt
