Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gdb6 / opcodes / cgen.sh
blob059e5596ce21658a6611e84a62e02e7b80b3849d
1 #! /bin/sh
2 # CGEN generic assembler support code.
4 # Copyright 2000, 2003, 2005 Free Software Foundation, Inc.
6 # This file is part of the GNU Binutils and GDB, the GNU debugger.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with this program; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
22 # Generate CGEN opcode files: arch-desc.[ch], arch-opc.[ch],
23 # arch-asm.c, arch-dis.c, arch-opinst.c, arch-ibld.[ch].
25 # Usage:
26 # cgen.sh action srcdir cgen cgendir cgenflags arch prefix \
27 # arch-file opc-file options [extrafiles]
29 # ACTION is currently always "opcodes". It exists to be consistent with the
30 # simulator.
31 # ARCH is the name of the architecture.
32 # It is substituted into @arch@ and @ARCH@ in the generated files.
33 # PREFIX is both the generated file prefix and is substituted into
34 # @prefix@ in the generated files.
35 # ARCH-FILE is the name of the .cpu file (including path).
36 # OPC-FILE is the name of the .opc file (including path).
37 # OPTIONS is comma separated list of options (???).
38 # EXTRAFILES is a space separated list (1 arg still) of extra files to build:
39 # - opinst - arch-opinst.c is being made, causes semantic analysis
41 # We store the generated files in the source directory until we decide to
42 # ship a Scheme interpreter (or other implementation) with gdb/binutils.
43 # Maybe we never will.
45 # We want to behave like make, any error forces us to stop.
46 set -e
48 action=$1
49 srcdir=$2
50 cgen="$3"
51 cgendir=$4
52 cgenflags=$5
53 arch=$6
54 prefix=$7
55 archfile=$8
56 opcfile=$9
57 shift ; options=$9
59 # List of extra files to build.
60 # Values: opinst (only 1 extra file at present)
61 shift ; extrafiles=$9
63 rootdir=${srcdir}/..
64 move_if_change="${CONFIG_SHELL:-/bin/sh} ${rootdir}/move-if-change"
66 # $arch is $6, as passed on the command line.
67 # $ARCH is the same argument but in all uppercase.
68 # Both forms are used in this script.
70 lowercase='abcdefghijklmnopqrstuvwxyz'
71 uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
72 ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
74 extrafile_args=""
75 for ef in .. $extrafiles
77 case $ef in
78 ..) ;;
79 opinst) extrafile_args="-Q tmp-opinst.c1 $extrafile_args" ;;
80 esac
81 done
83 case $action in
84 opcodes)
85 # Remove residual working files.
86 rm -f tmp-desc.h tmp-desc.h1
87 rm -f tmp-desc.c tmp-desc.c1
88 rm -f tmp-opc.h tmp-opc.h1
89 rm -f tmp-opc.c tmp-opc.c1
90 rm -f tmp-opinst.c tmp-opinst.c1
91 rm -f tmp-ibld.h tmp-ibld.h1
92 rm -f tmp-ibld.c tmp-ibld.in1
93 rm -f tmp-asm.c tmp-asm.in1
94 rm -f tmp-dis.c tmp-dis.in1
96 # Run CGEN.
97 ${cgen} ${cgendir}/cgen-opc.scm \
98 -s ${cgendir} \
99 ${cgenflags} \
100 -f "${options}" \
101 -m all \
102 -a ${archfile} \
103 -OPC ${opcfile} \
104 -H tmp-desc.h1 \
105 -C tmp-desc.c1 \
106 -O tmp-opc.h1 \
107 -P tmp-opc.c1 \
108 -L tmp-ibld.in1 \
109 -A tmp-asm.in1 \
110 -D tmp-dis.in1 \
111 ${extrafile_args}
113 # Customise generated files for the particular architecture.
114 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-desc.h1 > tmp-desc.h
115 ${move_if_change} tmp-desc.h ${srcdir}/${prefix}-desc.h
117 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
118 -e "s/@prefix@/${prefix}/" < tmp-desc.c1 > tmp-desc.c
119 ${move_if_change} tmp-desc.c ${srcdir}/${prefix}-desc.c
121 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-opc.h1 > tmp-opc.h
122 ${move_if_change} tmp-opc.h ${srcdir}/${prefix}-opc.h
124 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
125 -e "s/@prefix@/${prefix}/" < tmp-opc.c1 > tmp-opc.c
126 ${move_if_change} tmp-opc.c ${srcdir}/${prefix}-opc.c
128 case $extrafiles in
129 *opinst*)
130 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
131 -e "s/@prefix@/${prefix}/" < tmp-opinst.c1 >tmp-opinst.c
132 ${move_if_change} tmp-opinst.c ${srcdir}/${prefix}-opinst.c
134 esac
136 cat ${srcdir}/cgen-ibld.in tmp-ibld.in1 | \
137 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
138 -e "s/@prefix@/${prefix}/" > tmp-ibld.c
139 ${move_if_change} tmp-ibld.c ${srcdir}/${prefix}-ibld.c
141 sed -e "/ -- assembler routines/ r tmp-asm.in1" ${srcdir}/cgen-asm.in \
142 | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
143 -e "s/@prefix@/${prefix}/" > tmp-asm.c
144 ${move_if_change} tmp-asm.c ${srcdir}/${prefix}-asm.c
146 sed -e "/ -- disassembler routines/ r tmp-dis.in1" ${srcdir}/cgen-dis.in \
147 | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
148 -e "s/@prefix@/${prefix}/" > tmp-dis.c
149 ${move_if_change} tmp-dis.c ${srcdir}/${prefix}-dis.c
151 # Remove temporary files.
152 rm -f tmp-desc.h1 tmp-desc.c1
153 rm -f tmp-opc.h1 tmp-opc.c1
154 rm -f tmp-opinst.c1
155 rm -f tmp-ibld.h1 tmp-ibld.in1
156 rm -f tmp-asm.in1 tmp-dis.in1
160 echo "$0: bad action: ${action}" >&2
161 exit 1
164 esac
166 exit 0