2000-11-09 Philip Blundell <pb@futuretv.com>
[binutils.git] / opcodes / cgen.sh
blob8a4eb6b8a2b9b2f635137e61f93449589319a584
1 #! /bin/sh
2 # Generate CGEN opcode files: arch-desc.[ch], arch-opc.[ch],
3 # arch-asm.c, arch-dis.c, arch-opinst.c, arch-ibld.[ch].
5 # Usage:
6 # cgen.sh action srcdir cgen cgendir cgenflags arch prefix options
8 # ACTION is currently always "opcodes". It exists to be consistent with the
9 # simulator.
10 # OPTIONS is comma separated list of options:
11 # - opinst - arch-opinst.c is being made, causes semantic analysis
13 # We store the generated files in the source directory until we decide to
14 # ship a Scheme interpreter (or other implementation) with gdb/binutils.
15 # Maybe we never will.
17 # We want to behave like make, any error forces us to stop.
18 set -e
20 action=$1
21 srcdir=$2
22 cgen=$3
23 cgendir=$4
24 cgenflags=$5
25 arch=$6
26 prefix=$7
27 options=$8
29 # List of extra files to build.
30 # Values: opinst (only 1 extra file at present)
31 extrafiles=$9
33 rootdir=${srcdir}/..
35 # $arch is $6, as passed on the command line.
36 # $ARCH is the same argument but in all uppercase.
37 # Both forms are used in this script.
39 lowercase='abcdefghijklmnopqrstuvwxyz'
40 uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
41 ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
43 extrafile_args=""
44 for ef in .. $extrafiles
46 case $ef in
47 ..) ;;
48 opinst) extrafile_args="-Q tmp-opinst.c1 $extrafile_args" ;;
49 esac
50 done
52 case $action in
53 opcodes)
54 # Remove residual working files.
55 rm -f tmp-desc.h tmp-desc.h1
56 rm -f tmp-desc.c tmp-desc.c1
57 rm -f tmp-opc.h tmp-opc.h1
58 rm -f tmp-opc.c tmp-opc.c1
59 rm -f tmp-opinst.c tmp-opinst.c1
60 rm -f tmp-ibld.h tmp-ibld.h1
61 rm -f tmp-ibld.c tmp-ibld.in1
62 rm -f tmp-asm.c tmp-asm.in1
63 rm -f tmp-dis.c tmp-dis.in1
65 # Run CGEN.
66 ${cgen} -s ${cgendir}/cgen-opc.scm \
67 -s ${cgendir} \
68 ${cgenflags} \
69 -f "${options}" \
70 -m all \
71 -a ${arch} \
72 -H tmp-desc.h1 \
73 -C tmp-desc.c1 \
74 -O tmp-opc.h1 \
75 -P tmp-opc.c1 \
76 -L tmp-ibld.in1 \
77 -A tmp-asm.in1 \
78 -D tmp-dis.in1 \
79 ${extrafile_args}
81 # Customise generated files for the particular architecture.
82 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-desc.h1 > tmp-desc.h
83 ${rootdir}/move-if-change tmp-desc.h ${srcdir}/${prefix}-desc.h
85 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
86 -e "s/@prefix@/${prefix}/" < tmp-desc.c1 > tmp-desc.c
87 ${rootdir}/move-if-change tmp-desc.c ${srcdir}/${prefix}-desc.c
89 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-opc.h1 > tmp-opc.h
90 ${rootdir}/move-if-change tmp-opc.h ${srcdir}/${prefix}-opc.h
92 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
93 -e "s/@prefix@/${prefix}/" < tmp-opc.c1 > tmp-opc.c
94 ${rootdir}/move-if-change tmp-opc.c ${srcdir}/${prefix}-opc.c
96 case $extrafiles in
97 *opinst*)
98 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
99 -e "s/@prefix@/${prefix}/" < tmp-opinst.c1 >tmp-opinst.c
100 ${rootdir}/move-if-change tmp-opinst.c ${srcdir}/${prefix}-opinst.c
102 esac
104 cat ${srcdir}/cgen-ibld.in tmp-ibld.in1 | \
105 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
106 -e "s/@prefix@/${prefix}/" > tmp-ibld.c
107 ${rootdir}/move-if-change tmp-ibld.c ${srcdir}/${prefix}-ibld.c
109 sed -e "/ -- assembler routines/ r tmp-asm.in1" ${srcdir}/cgen-asm.in \
110 | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
111 -e "s/@prefix@/${prefix}/" > tmp-asm.c
112 ${rootdir}/move-if-change tmp-asm.c ${srcdir}/${prefix}-asm.c
114 sed -e "/ -- disassembler routines/ r tmp-dis.in1" ${srcdir}/cgen-dis.in \
115 | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
116 -e "s/@prefix@/${prefix}/" > tmp-dis.c
117 ${rootdir}/move-if-change tmp-dis.c ${srcdir}/${prefix}-dis.c
119 # Remove temporary files.
120 rm -f tmp-desc.h1 tmp-desc.c1
121 rm -f tmp-opc.h1 tmp-opc.c1
122 rm -f tmp-opinst.c1
123 rm -f tmp-ibld.h1 tmp-ibld.in1
124 rm -f tmp-asm.in1 tmp-dis.in1
128 echo "$0: bad action: ${action}" >&2
129 exit 1
132 esac
134 exit 0