2001-03-13 Fernando Nasser <fnasser@redhat.com>
[deliverable/binutils-gdb.git] / opcodes / cgen.sh
CommitLineData
f6e6b40f
BE
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].
4#
5# Usage:
6# cgen.sh action srcdir cgen cgendir cgenflags arch prefix options
7#
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
12#
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.
16
17# We want to behave like make, any error forces us to stop.
18set -e
19
20action=$1
21srcdir=$2
22cgen=$3
23cgendir=$4
24cgenflags=$5
25arch=$6
26prefix=$7
27options=$8
28
29# List of extra files to build.
30# Values: opinst (only 1 extra file at present)
31extrafiles=$9
32
33rootdir=${srcdir}/..
34
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.
38
39lowercase='abcdefghijklmnopqrstuvwxyz'
40uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
41ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
42
43extrafile_args=""
44for ef in .. $extrafiles
45do
46 case $ef in
47 ..) ;;
48 opinst) extrafile_args="-Q tmp-opinst.c1 $extrafile_args" ;;
49 esac
50done
51
52case $action in
53opcodes)
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
64
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}
80
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
84
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
88
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
91
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
95
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
101 ;;
102 esac
103
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
108
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
113
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
118
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
125 ;;
126
127*)
128 echo "$0: bad action: ${action}" >&2
129 exit 1
130 ;;
131
132esac
133
134exit 0
This page took 0.043782 seconds and 4 git commands to generate.