2 # CGEN generic assembler support code.
4 # Copyright (C) 2000-2017 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)
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].
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
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.
59 # List of extra files to build.
60 # Values: opinst (only 1 extra file at present)
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.
77 for ef in .. $extrafiles
81 opinst) extrafile_args="-Q ${tmp}-opinst.c1 $extrafile_args" ;;
87 # Remove residual working files.
88 rm -f ${tmp}-desc.h ${tmp}-desc.h1
89 rm -f ${tmp}-desc.c ${tmp}-desc.c1
90 rm -f ${tmp}-opc.h ${tmp}-opc.h1
91 rm -f ${tmp}-opc.c ${tmp}-opc.c1
92 rm -f ${tmp}-opinst.c ${tmp}-opinst.c1
93 rm -f ${tmp}-ibld.h ${tmp}-ibld.h1
94 rm -f ${tmp}-ibld.c ${tmp}-ibld.in1
95 rm -f ${tmp}-asm.c ${tmp}-asm.in1
96 rm -f ${tmp}-dis.c ${tmp}-dis.in1
99 ${cgen} ${cgendir}/cgen-opc.scm \
115 # Customise generated files for the particular architecture.
116 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
117 -e 's/[ ][ ]*$//' < ${tmp}-desc.h1 > ${tmp}-desc.h
118 ${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${prefix}-desc.h
120 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
121 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
122 < ${tmp}-desc.c1 > ${tmp}-desc.c
123 ${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${prefix}-desc.c
125 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
126 -e 's/[ ][ ]*$//' < ${tmp}-opc.h1 > ${tmp}-opc.h
127 ${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${prefix}-opc.h
129 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
130 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
131 < ${tmp}-opc.c1 > ${tmp}-opc.c
132 ${rootdir}/move-if-change ${tmp}-opc.c ${srcdir}/${prefix}-opc.c
136 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
137 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
138 < ${tmp}-opinst.c1 >${tmp}-opinst.c
139 ${rootdir}/move-if-change ${tmp}-opinst.c ${srcdir}/${prefix}-opinst.c
143 cat ${srcdir}/cgen-ibld.in ${tmp}-ibld.in1 | \
144 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
145 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' > ${tmp}-ibld.c
146 ${rootdir}/move-if-change ${tmp}-ibld.c ${srcdir}/${prefix}-ibld.c
148 sed -e "/ -- assembler routines/ r ${tmp}-asm.in1" ${srcdir}/cgen-asm.in \
149 | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
150 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
152 ${rootdir}/move-if-change ${tmp}-asm.c ${srcdir}/${prefix}-asm.c
154 sed -e "/ -- disassembler routines/ r ${tmp}-dis.in1" ${srcdir}/cgen-dis.in \
155 | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
156 -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
158 ${rootdir}/move-if-change ${tmp}-dis.c ${srcdir}/${prefix}-dis.c
160 # Remove temporary files.
161 rm -f ${tmp}-desc.h1 ${tmp}-desc.c1
162 rm -f ${tmp}-opc.h1 ${tmp}-opc.c1
163 rm -f ${tmp}-opinst.c1
164 rm -f ${tmp}-ibld.h1 ${tmp}-ibld.in1
165 rm -f ${tmp}-asm.in1 ${tmp}-dis.in1
169 echo "$0: bad action: ${action}" >&2