public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
* [Sim] New sim/common/cgen.sh
@ 2000-12-03 19:24 Ben Elliston
  2000-12-03 21:28 ` Doug Evans
  0 siblings, 1 reply; 9+ messages in thread
From: Ben Elliston @ 2000-12-03 19:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: cgen

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Sim] New sim/common/cgen.sh
  2000-12-03 19:24 [Sim] New sim/common/cgen.sh Ben Elliston
@ 2000-12-03 21:28 ` Doug Evans
  2000-12-03 23:49   ` Ben Elliston
  2000-12-04  1:47   ` Ben Elliston
  0 siblings, 2 replies; 9+ messages in thread
From: Doug Evans @ 2000-12-03 21:28 UTC (permalink / raw)
  To: Ben Elliston; +Cc: gdb-patches, cgen

Ben Elliston writes:
 > 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?

The nice thing about the way things are now is that each section
is self contained.  In and of itself that's not a bad thing.

Also, while the existing script has problems with parallel makes,
your version has even worse problems.  You might want to fix that.

 > 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Sim] New sim/common/cgen.sh
  2000-12-03 21:28 ` Doug Evans
@ 2000-12-03 23:49   ` Ben Elliston
  2000-12-04  1:47   ` Ben Elliston
  1 sibling, 0 replies; 9+ messages in thread
From: Ben Elliston @ 2000-12-03 23:49 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches, cgen

   Also, while the existing script has problems with parallel makes, your
   version has even worse problems.  You might want to fix that.

You're right -- that is important.  I'll improve it.

Thanks, B.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Sim] New sim/common/cgen.sh
  2000-12-03 21:28 ` Doug Evans
  2000-12-03 23:49   ` Ben Elliston
@ 2000-12-04  1:47   ` Ben Elliston
  2000-12-04  1:57     ` Ben Elliston
  1 sibling, 1 reply; 9+ messages in thread
From: Ben Elliston @ 2000-12-04  1:47 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches, cgen

   Also, while the existing script has problems with parallel makes, your
   version has even worse problems.  You might want to fix that.

I've made those changes.  If there aren't any other comments, I'll check the
new cgen.sh in tomorrow.

Ben

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Sim] New sim/common/cgen.sh
  2000-12-04  1:47   ` Ben Elliston
@ 2000-12-04  1:57     ` Ben Elliston
  2000-12-04 10:55       ` Doug Evans
  0 siblings, 1 reply; 9+ messages in thread
From: Ben Elliston @ 2000-12-04  1:57 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches, cgen

      Also, while the existing script has problems with parallel makes, your
      version has even worse problems.  You might want to fix that.

I have also just fixed genmloop.sh so that it has an -outfile-suffix option.
This allows the generated files to form unique filenames -- so it, too, can
be run by a parallel make.

Ben

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Sim] New sim/common/cgen.sh
  2000-12-04  1:57     ` Ben Elliston
@ 2000-12-04 10:55       ` Doug Evans
  2000-12-04 13:11         ` Ben Elliston
  0 siblings, 1 reply; 9+ messages in thread
From: Doug Evans @ 2000-12-04 10:55 UTC (permalink / raw)
  To: Ben Elliston; +Cc: Doug Evans, gdb-patches, cgen

Ben Elliston writes:
 >       Also, while the existing script has problems with parallel makes, your
 >       version has even worse problems.  You might want to fix that.
 > 
 > I have also just fixed genmloop.sh so that it has an -outfile-suffix option.
 > This allows the generated files to form unique filenames -- so it, too, can
 > be run by a parallel make.

Can't this problem be solved without adding an option?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Sim] New sim/common/cgen.sh
  2000-12-04 10:55       ` Doug Evans
@ 2000-12-04 13:11         ` Ben Elliston
  2000-12-04 18:40           ` Doug Evans
  0 siblings, 1 reply; 9+ messages in thread
From: Ben Elliston @ 2000-12-04 13:11 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches, cgen

    > I have also just fixed genmloop.sh so that it has an -outfile-suffix option.
    > This allows the generated files to form unique filenames -- so it, too, can
    > be run by a parallel make.

   Can't this problem be solved without adding an option?

Can you suggest how?

Ben

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Sim] New sim/common/cgen.sh
  2000-12-04 13:11         ` Ben Elliston
@ 2000-12-04 18:40           ` Doug Evans
  2000-12-04 19:29             ` Ben Elliston
  0 siblings, 1 reply; 9+ messages in thread
From: Doug Evans @ 2000-12-04 18:40 UTC (permalink / raw)
  To: Ben Elliston; +Cc: gdb-patches, cgen

Ben Elliston writes:
 >     > I have also just fixed genmloop.sh so that it has an -outfile-suffix option.
 >     > This allows the generated files to form unique filenames -- so it, too, can
 >     > be run by a parallel make.
 > 
 >    Can't this problem be solved without adding an option?
 > 
 > Can you suggest how?

The theory is that the script is already being passed something it can use.

There's the -cpu argument.  I dunno if your @prefix@ patches change whether
genmloop.sh should use @cpu@ or @prefix@, but won't one of them
(whichever it is) be sufficient to separate the output files?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Sim] New sim/common/cgen.sh
  2000-12-04 18:40           ` Doug Evans
@ 2000-12-04 19:29             ` Ben Elliston
  0 siblings, 0 replies; 9+ messages in thread
From: Ben Elliston @ 2000-12-04 19:29 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches, cgen

   The theory is that the script is already being passed something it can
   use.

The same could be said for determining the input filename (ie. mloop.in),
but we provide the flexibility to specify *that*.  There is even a comment
in genmloop.sh that says that it would be useful to provide options to
specify the output filenames (both of them) in the future.

Ben

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2000-12-04 19:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-03 19:24 [Sim] New sim/common/cgen.sh Ben Elliston
2000-12-03 21:28 ` Doug Evans
2000-12-03 23:49   ` Ben Elliston
2000-12-04  1:47   ` Ben Elliston
2000-12-04  1:57     ` Ben Elliston
2000-12-04 10:55       ` Doug Evans
2000-12-04 13:11         ` Ben Elliston
2000-12-04 18:40           ` Doug Evans
2000-12-04 19:29             ` Ben Elliston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).