testsuite: skip confirmation in 'gdb_reinitialize_dir'
[binutils-gdb.git] / opcodes / cgen.sh
blob467535e5f905115cc79d120e0e4e95472d6a9e68
1 #! /bin/sh
2 # CGEN generic assembler support code.
4 # Copyright (C) 2000-2024 Free Software Foundation, Inc.
6 # This file is part of the GNU opcodes library.
8 # This library 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 3, or (at your option)
11 # any later version.
13 # It is distributed in the hope that it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 # 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}/..
65 # $arch is $6, as passed on the command line.
66 # $ARCH is the same argument but in all uppercase.
67 # Both forms are used in this script.
69 lowercase='abcdefghijklmnopqrstuvwxyz'
70 uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
71 ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
73 # Allow parallel makes to run multiple cgen's without colliding.
74 tmp=tmp-$$
76 extrafile_args=""
77 for ef in .. $extrafiles
79 case $ef in
80 ..) ;;
81 opinst) extrafile_args="-Q ${tmp}-opinst.c1 $extrafile_args" ;;
82 esac
83 done
85 header="/* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */"
87 case $action in
88 opcodes)
89 # Remove residual working files.
90 rm -f ${tmp}-desc.h ${tmp}-desc.h1
91 rm -f ${tmp}-desc.c ${tmp}-desc.c1
92 rm -f ${tmp}-opc.h ${tmp}-opc.h1
93 rm -f ${tmp}-opc.c ${tmp}-opc.c1
94 rm -f ${tmp}-opinst.c ${tmp}-opinst.c1
95 rm -f ${tmp}-ibld.h ${tmp}-ibld.h1
96 rm -f ${tmp}-ibld.c ${tmp}-ibld.in1
97 rm -f ${tmp}-asm.c ${tmp}-asm.in1
98 rm -f ${tmp}-dis.c ${tmp}-dis.in1
100 # Run CGEN.
101 ${cgen} ${cgendir}/cgen-opc.scm \
102 ${cgenflags} \
103 -f "${options}" \
104 -m all \
105 -a ${archfile} \
106 -OPC ${opcfile} \
107 -H ${tmp}-desc.h1 \
108 -C ${tmp}-desc.c1 \
109 -O ${tmp}-opc.h1 \
110 -P ${tmp}-opc.c1 \
111 -L ${tmp}-ibld.in1 \
112 -A ${tmp}-asm.in1 \
113 -D ${tmp}-dis.in1 \
114 ${extrafile_args}
116 # Customise generated files for the particular architecture.
117 sed -e "1i$header" \
118 -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
119 -e 's/[ ][ ]*$//' < ${tmp}-desc.h1 > ${tmp}-desc.h
120 ${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${prefix}-desc.h
122 sed -e "1i$header" \
123 -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
124 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
125 < ${tmp}-desc.c1 > ${tmp}-desc.c
126 ${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${prefix}-desc.c
128 sed -e "1i$header" \
129 -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
130 -e 's/[ ][ ]*$//' < ${tmp}-opc.h1 > ${tmp}-opc.h
131 ${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${prefix}-opc.h
133 sed -e "1i$header" \
134 -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
135 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
136 < ${tmp}-opc.c1 > ${tmp}-opc.c
137 ${rootdir}/move-if-change ${tmp}-opc.c ${srcdir}/${prefix}-opc.c
139 case $extrafiles in
140 *opinst*)
141 sed -e "1i$header" \
142 -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
143 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
144 < ${tmp}-opinst.c1 >${tmp}-opinst.c
145 ${rootdir}/move-if-change ${tmp}-opinst.c ${srcdir}/${prefix}-opinst.c
147 esac
149 cat ${srcdir}/cgen-ibld.in ${tmp}-ibld.in1 | \
150 sed -e "1i$header" \
151 -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
152 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' > ${tmp}-ibld.c
153 ${rootdir}/move-if-change ${tmp}-ibld.c ${srcdir}/${prefix}-ibld.c
155 sed -e "/ -- assembler routines/ r ${tmp}-asm.in1" ${srcdir}/cgen-asm.in \
156 | sed -e "1i$header" \
157 -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
158 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
159 > ${tmp}-asm.c
160 ${rootdir}/move-if-change ${tmp}-asm.c ${srcdir}/${prefix}-asm.c
162 sed -e "/ -- disassembler routines/ r ${tmp}-dis.in1" ${srcdir}/cgen-dis.in \
163 | sed -e "1i$header" \
164 -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
165 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
166 > ${tmp}-dis.c
167 ${rootdir}/move-if-change ${tmp}-dis.c ${srcdir}/${prefix}-dis.c
169 # Remove temporary files.
170 rm -f ${tmp}-desc.h1 ${tmp}-desc.c1
171 rm -f ${tmp}-opc.h1 ${tmp}-opc.c1
172 rm -f ${tmp}-opinst.c1
173 rm -f ${tmp}-ibld.h1 ${tmp}-ibld.in1
174 rm -f ${tmp}-asm.in1 ${tmp}-dis.in1
177 desc)
178 # For ports that only generate the desc module & opc header.
179 rm -f ${tmp}-desc.h1 ${tmp}-desc.h
180 rm -f ${tmp}-desc.c1 ${tmp}-desc.c
181 rm -f ${tmp}-opc.h1 ${tmp}-opc.h
183 ${cgen} ${cgendir}/cgen-opc.scm \
184 ${cgenflags} \
185 -OPC ${opcfile} \
186 -f "${archflags}" \
187 -m all \
188 -a ${archfile} \
189 -i all \
190 -H ${tmp}-desc.h1 \
191 -C ${tmp}-desc.c1 \
192 -O ${tmp}-opc.h1
194 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
195 -e "s/@prefix@/${prefix}/g" -e 's/[ ][ ]*$//' \
196 < ${tmp}-desc.h1 > ${tmp}-desc.h
197 ${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${arch}-desc.h
198 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
199 -e "s/@prefix@/${prefix}/g" -e 's/[ ][ ]*$//' \
200 < ${tmp}-desc.c1 > ${tmp}-desc.c
201 ${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${arch}-desc.c
202 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
203 -e "s/@prefix@/${prefix}/g" -e 's/[ ][ ]*$//' \
204 < ${tmp}-opc.h1 > ${tmp}-opc.h
205 ${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${arch}-opc.h
207 rm -f ${tmp}-desc.h1 ${tmp}-desc.c1 ${tmp}-opc.h1
211 echo "$0: bad action: ${action}" >&2
212 exit 1
215 esac
217 exit 0