[Sim] New sim/common/cgen.sh

Ben Elliston bje@redhat.com
Sun Dec 3 19:24:00 GMT 2000


It's not very often that I advocate complete rewrites :-), but in this
case, the cgen.sh script (used to generate the sim files with cgen)
was a rats' nest.  Rather than post diffs, I have included the new
script for review.  (Diffs are left as an exercise for the reader).

I think this script is much clearer and certainly more maintainable.
In the future, we need to allow finer control over files that are
generated -- for example, you might want the cpu files, but not
model.c.

The reason I did this is that the script provides a new "defs" action,
to emit a defs.h file using last week's CGEN modifications.

Comments?

Ben


2000-12-04  Ben Elliston  <bje@redhat.com>

	* cgen.sh: Rewrite. Add "defs" action.


#! /bin/sh
# Generate CGEN simulator files.
#
# Usage: /bin/sh cgen.sh {"arch"|"cpu"|"decode"|"defs"|"cpu-decode"} srcdir \
#	cgen cgendir cgenflags \
#	arch archflags cpu mach suffix [extrafiles...]
#
# We store the generated files in the source directory until we decide to
# ship a Scheme interpreter (or other implementation) with gdb/binutils.
# Maybe we never will.

# We want to behave like make, any error forces us to stop.
set -e

action=$1
srcdir=$2
cgen=$3
cgendir=$4
cgenflags=$5
arch=$6
archflags=$7
cpu=$8
isa=$9
# portably bring parameters beyond $9 into view
shift ; mach=$9
shift ; suffix=$9
shift ; extrafiles=$9

rootdir=${srcdir}/../..

if test -z "$isa" ; then
  isa=all
  prefix=${cpu}
else
  prefix=${cpu}_${isa}
fi

lowercase='abcdefghijklmnopqrstuvwxyz'
uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
CPU=`echo ${cpu} | tr "${lowercase}" "${uppercase}"`
PREFIX=`echo ${prefix} | tr "${lowercase}" "${uppercase}"`

sedscript="\
-e s/@ARCH@/${ARCH}/g -e s/@arch@/${arch}/g \
-e s/@CPU@/${CPU}/g -e s/@cpu@/${cpu}/g \
-e s/@PREFIX@/${PREFIX}/g -e s/@prefix@/${prefix}/g"

tmp_postprocessed=\
"tmp-all.h tmp-arch.h tmp-arch.c tmp-cpu.c tmp-cpu.h tmp-dec.h tmp-dec.c tmp-defs.h tmp-desc.h tmp-desc.c tmp-ext.c tmp-mod.c tmp-opc.h tmp-read.c tmp-sem.c tmp-semsw.c tmp-write.c"

for file in ${tmp_postprocessed} ; do
  tmp_preprocessed="${file}1 $tmp_preprocessed" 
done

# Step 1: clean up.
rm -f ${tmp_preprocessed} ${tmp_postprocessed}

# Step 2: run cgen to produce pre-processed files.
case $action in
arch)
	${cgen} -s ${cgendir}/cgen-sim.scm \
		-s ${cgendir} \
		${cgenflags} \
		-f "${archflags}" \
		-m ${mach} \
		-a ${arch} \
		-i ${isa} \
		-A tmp-arch.h1 \
		-B tmp-arch.c1 \
		-N tmp-all.h1
	;;

cpu | decode | cpu-decode)
	fileopts=""
	case $action in
	*cpu*)
		fileopts="$fileopts \
			-C tmp-cpu.h1 \
			-U tmp-cpu.c1 \
			-M tmp-mod.c1 \
			${extrafiles}"
		;;
	esac
	case $action in
	*decode*)
		fileopts="$fileopts \
			-T tmp-dec.h1 \
			-D tmp-dec.c1" 
		case ${extrafiles} in
		  ignored) # Do nothing.
		           ;; 
		  *)       fileopts="$fileopts ${extrafiles}"
		           ;;
		esac
		;;
	esac

	${cgen} -s ${cgendir}/cgen-sim.scm \
		-s ${cgendir} \
		${cgenflags} \
		-f "${archflags}" \
		-m ${mach} \
		-a ${arch} \
		-i ${isa} \
		${fileopts}
	;;

defs)
	${cgen} -s ${cgendir}/cgen-sim.scm \
		-s ${cgendir} \
		${cgenflags} \
		-f "${archflags}" \
		-m ${mach} \
		-a ${arch} \
		-i ${isa} \
		-G tmp-defs.h1
	;;

desc)
	${cgen} -s ${cgendir}/cgen-opc.scm \
		-s ${cgendir} \
		${cgenflags} \
		-f "${archflags}" \
		-m ${mach} \
		-a ${arch} \
		-i ${isa} \
		-H tmp-desc.h1 \
		-C tmp-desc.c1 \
		-O tmp-opc.h1
	;;

*)
	echo "`basename $0`: unknown action: ${action}" >&2
	exit 1
	;;
esac

# Step 3: post-process files.
for file in ${tmp_preprocessed} ; do
  if test -f $file ; then
    postproc=`basename $file 1`
    sed ${sedscript} < $file > $postproc
    if grep '@[^ ]*@' $postproc >/dev/null ; then
      echo "Warning: $postproc may contain unsubstituted macros" >&2
    fi
    rm $file
    case $postproc in
      tmp-all.h)   srcfile=cpuall.h ;;
      tmp-arch.h)  srcfile=arch.h ;;
      tmp-arch.c)  srcfile=arch.c ;;
      tmp-cpu.h)   srcfile=cpu${suffix}.h ;;
      tmp-cpu.c)   srcfile=cpu${suffix}.c ;;
      tmp-dec.c)   srcfile=decode${suffix}.c ;;
      tmp-dec.h)   srcfile=decode${suffix}.h ;;
      tmp-defs.h)  srcfile=defs${suffix}.h ;;
      tmp-desc.c)  srcfile=${arch}-desc.c ;;
      tmp-desc.h)  srcfile=${arch}-desc.h ;;
      tmp-ext.c)   srcfile=extract${suffix}.c ;;
      tmp-mod.c)   srcfile=model${suffix}.c ;;
      tmp-opc.h)   srcfile=${arch}-opc.h ;;
      tmp-read.c)  srcfile=read${suffix}.c ;;
      tmp-sem.c)   srcfile=sem${suffix}.c ;;
      tmp-semsw.c) srcfile=sem${suffix}-switch.c ;;
      tmp-write.c) srcfile=write${suffix}.c ;; 

      *) echo "Unknown post-processed file $postproc"
	 exit 1
	 ;;
    esac
    ${rootdir}/move-if-change ${postproc} ${srcdir}/${srcfile}
  fi
done

if ls *1 2>/dev/null ; then
  echo "Warning: output files were left behind!" >&2
  exit 1
fi

exit 0


More information about the Gdb-patches mailing list