From: Ben Elliston <bje@redhat.com>
To: gdb-patches@sources.redhat.com
Cc: cgen@sources.redhat.com
Subject: [Sim] New sim/common/cgen.sh
Date: Sun, 03 Dec 2000 19:24:00 -0000 [thread overview]
Message-ID: <200012040323.eB43Nv011864@scooby.cygnus.com> (raw)
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
next reply other threads:[~2000-12-03 19:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-12-03 19:24 Ben Elliston [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200012040323.eB43Nv011864@scooby.cygnus.com \
--to=bje@redhat.com \
--cc=cgen@sources.redhat.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).