2000-08-04 04:21:43 +02:00
|
|
|
#! /bin/sh
|
2001-03-13 23:58:38 +01:00
|
|
|
# CGEN generic assembler support code.
|
|
|
|
#
|
2015-01-01 15:15:26 +01:00
|
|
|
# Copyright (C) 2000-2015 Free Software Foundation, Inc.
|
2001-03-13 23:58:38 +01:00
|
|
|
#
|
2007-07-05 11:49:03 +02:00
|
|
|
# This file is part of the GNU opcodes library.
|
2001-03-13 23:58:38 +01:00
|
|
|
#
|
2007-07-05 11:49:03 +02:00
|
|
|
# This library is free software; you can redistribute it and/or modify
|
2001-03-13 23:58:38 +01:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-07-05 11:49:03 +02:00
|
|
|
# the Free Software Foundation; either version 3, or (at your option)
|
2001-03-13 23:58:38 +01:00
|
|
|
# any later version.
|
|
|
|
#
|
2007-07-05 11:49:03 +02:00
|
|
|
# It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
# License for more details.
|
2001-03-13 23:58:38 +01:00
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
2005-05-07 09:34:31 +02:00
|
|
|
# 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
|
2001-03-13 23:58:38 +01:00
|
|
|
#
|
2000-08-04 04:21:43 +02:00
|
|
|
# Generate CGEN opcode files: arch-desc.[ch], arch-opc.[ch],
|
|
|
|
# arch-asm.c, arch-dis.c, arch-opinst.c, arch-ibld.[ch].
|
|
|
|
#
|
|
|
|
# Usage:
|
2003-09-08 19:24:05 +02:00
|
|
|
# cgen.sh action srcdir cgen cgendir cgenflags arch prefix \
|
|
|
|
# arch-file opc-file options [extrafiles]
|
2000-08-04 04:21:43 +02:00
|
|
|
#
|
2015-08-12 13:45:07 +02:00
|
|
|
# ACTION is currently always "opcodes". It exists to be consistent with the
|
2000-08-04 04:21:43 +02:00
|
|
|
# simulator.
|
2003-09-08 19:24:05 +02:00
|
|
|
# ARCH is the name of the architecture.
|
|
|
|
# It is substituted into @arch@ and @ARCH@ in the generated files.
|
|
|
|
# PREFIX is both the generated file prefix and is substituted into
|
|
|
|
# @prefix@ in the generated files.
|
|
|
|
# ARCH-FILE is the name of the .cpu file (including path).
|
|
|
|
# OPC-FILE is the name of the .opc file (including path).
|
|
|
|
# OPTIONS is comma separated list of options (???).
|
|
|
|
# EXTRAFILES is a space separated list (1 arg still) of extra files to build:
|
2000-08-04 04:21:43 +02:00
|
|
|
# - opinst - arch-opinst.c is being made, causes semantic analysis
|
|
|
|
#
|
|
|
|
# We store the generated files in the source directory until we decide to
|
|
|
|
# ship a Scheme interpreter (or other implementation) with gdb/binutils.
|
|
|
|
# Maybe we never will.
|
|
|
|
|
|
|
|
# We want to behave like make, any error forces us to stop.
|
|
|
|
set -e
|
|
|
|
|
|
|
|
action=$1
|
|
|
|
srcdir=$2
|
2005-02-08 05:52:24 +01:00
|
|
|
cgen="$3"
|
2000-08-04 04:21:43 +02:00
|
|
|
cgendir=$4
|
|
|
|
cgenflags=$5
|
|
|
|
arch=$6
|
|
|
|
prefix=$7
|
2003-09-08 19:24:05 +02:00
|
|
|
archfile=$8
|
|
|
|
opcfile=$9
|
|
|
|
shift ; options=$9
|
2000-08-04 04:21:43 +02:00
|
|
|
|
|
|
|
# List of extra files to build.
|
|
|
|
# Values: opinst (only 1 extra file at present)
|
2003-09-08 19:24:05 +02:00
|
|
|
shift ; extrafiles=$9
|
2000-08-04 04:21:43 +02:00
|
|
|
|
|
|
|
rootdir=${srcdir}/..
|
|
|
|
|
|
|
|
# $arch is $6, as passed on the command line.
|
|
|
|
# $ARCH is the same argument but in all uppercase.
|
|
|
|
# Both forms are used in this script.
|
|
|
|
|
|
|
|
lowercase='abcdefghijklmnopqrstuvwxyz'
|
|
|
|
uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
|
|
ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
|
|
|
|
|
2009-06-14 18:36:56 +02:00
|
|
|
# Allow parallel makes to run multiple cgen's without colliding.
|
|
|
|
tmp=tmp-$$
|
|
|
|
|
2000-08-04 04:21:43 +02:00
|
|
|
extrafile_args=""
|
|
|
|
for ef in .. $extrafiles
|
|
|
|
do
|
|
|
|
case $ef in
|
|
|
|
..) ;;
|
2009-06-14 18:36:56 +02:00
|
|
|
opinst) extrafile_args="-Q ${tmp}-opinst.c1 $extrafile_args" ;;
|
2000-08-04 04:21:43 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $action in
|
|
|
|
opcodes)
|
|
|
|
# Remove residual working files.
|
2009-06-14 18:36:56 +02:00
|
|
|
rm -f ${tmp}-desc.h ${tmp}-desc.h1
|
|
|
|
rm -f ${tmp}-desc.c ${tmp}-desc.c1
|
|
|
|
rm -f ${tmp}-opc.h ${tmp}-opc.h1
|
|
|
|
rm -f ${tmp}-opc.c ${tmp}-opc.c1
|
|
|
|
rm -f ${tmp}-opinst.c ${tmp}-opinst.c1
|
|
|
|
rm -f ${tmp}-ibld.h ${tmp}-ibld.h1
|
|
|
|
rm -f ${tmp}-ibld.c ${tmp}-ibld.in1
|
|
|
|
rm -f ${tmp}-asm.c ${tmp}-asm.in1
|
|
|
|
rm -f ${tmp}-dis.c ${tmp}-dis.in1
|
2000-08-04 04:21:43 +02:00
|
|
|
|
|
|
|
# Run CGEN.
|
2005-02-08 05:52:24 +01:00
|
|
|
${cgen} ${cgendir}/cgen-opc.scm \
|
2000-08-04 04:21:43 +02:00
|
|
|
-s ${cgendir} \
|
|
|
|
${cgenflags} \
|
|
|
|
-f "${options}" \
|
|
|
|
-m all \
|
2003-09-08 19:24:05 +02:00
|
|
|
-a ${archfile} \
|
|
|
|
-OPC ${opcfile} \
|
2009-06-14 18:36:56 +02:00
|
|
|
-H ${tmp}-desc.h1 \
|
|
|
|
-C ${tmp}-desc.c1 \
|
|
|
|
-O ${tmp}-opc.h1 \
|
|
|
|
-P ${tmp}-opc.c1 \
|
|
|
|
-L ${tmp}-ibld.in1 \
|
|
|
|
-A ${tmp}-asm.in1 \
|
|
|
|
-D ${tmp}-dis.in1 \
|
2000-08-04 04:21:43 +02:00
|
|
|
${extrafile_args}
|
|
|
|
|
|
|
|
# Customise generated files for the particular architecture.
|
2015-08-17 04:21:44 +02:00
|
|
|
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
|
|
|
|
-e 's/[ ][ ]*$//' < ${tmp}-desc.h1 > ${tmp}-desc.h
|
2009-06-14 18:36:56 +02:00
|
|
|
${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${prefix}-desc.h
|
2000-08-04 04:21:43 +02:00
|
|
|
|
|
|
|
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
|
2015-08-17 04:21:44 +02:00
|
|
|
-e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
|
|
|
|
< ${tmp}-desc.c1 > ${tmp}-desc.c
|
2009-06-14 18:36:56 +02:00
|
|
|
${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${prefix}-desc.c
|
2000-08-04 04:21:43 +02:00
|
|
|
|
2015-08-17 04:21:44 +02:00
|
|
|
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
|
|
|
|
-e 's/[ ][ ]*$//' < ${tmp}-opc.h1 > ${tmp}-opc.h
|
2009-06-14 18:36:56 +02:00
|
|
|
${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${prefix}-opc.h
|
2000-08-04 04:21:43 +02:00
|
|
|
|
|
|
|
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
|
2015-08-17 04:21:44 +02:00
|
|
|
-e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
|
|
|
|
< ${tmp}-opc.c1 > ${tmp}-opc.c
|
2009-06-14 18:36:56 +02:00
|
|
|
${rootdir}/move-if-change ${tmp}-opc.c ${srcdir}/${prefix}-opc.c
|
2000-08-04 04:21:43 +02:00
|
|
|
|
|
|
|
case $extrafiles in
|
|
|
|
*opinst*)
|
|
|
|
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
|
2015-08-17 04:21:44 +02:00
|
|
|
-e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
|
|
|
|
< ${tmp}-opinst.c1 >${tmp}-opinst.c
|
2009-06-14 18:36:56 +02:00
|
|
|
${rootdir}/move-if-change ${tmp}-opinst.c ${srcdir}/${prefix}-opinst.c
|
2000-08-04 04:21:43 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-06-14 18:36:56 +02:00
|
|
|
cat ${srcdir}/cgen-ibld.in ${tmp}-ibld.in1 | \
|
2000-08-04 04:21:43 +02:00
|
|
|
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
|
2015-08-17 04:21:44 +02:00
|
|
|
-e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' > ${tmp}-ibld.c
|
2009-06-14 18:36:56 +02:00
|
|
|
${rootdir}/move-if-change ${tmp}-ibld.c ${srcdir}/${prefix}-ibld.c
|
2000-08-04 04:21:43 +02:00
|
|
|
|
2009-06-14 18:36:56 +02:00
|
|
|
sed -e "/ -- assembler routines/ r ${tmp}-asm.in1" ${srcdir}/cgen-asm.in \
|
2000-08-04 04:21:43 +02:00
|
|
|
| sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
|
2015-08-17 04:21:44 +02:00
|
|
|
-e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
|
|
|
|
> ${tmp}-asm.c
|
2009-06-14 18:36:56 +02:00
|
|
|
${rootdir}/move-if-change ${tmp}-asm.c ${srcdir}/${prefix}-asm.c
|
2000-08-04 04:21:43 +02:00
|
|
|
|
2009-06-14 18:36:56 +02:00
|
|
|
sed -e "/ -- disassembler routines/ r ${tmp}-dis.in1" ${srcdir}/cgen-dis.in \
|
2000-08-04 04:21:43 +02:00
|
|
|
| sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
|
2015-08-17 04:21:44 +02:00
|
|
|
-e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
|
|
|
|
> ${tmp}-dis.c
|
2009-06-14 18:36:56 +02:00
|
|
|
${rootdir}/move-if-change ${tmp}-dis.c ${srcdir}/${prefix}-dis.c
|
2000-08-04 04:21:43 +02:00
|
|
|
|
|
|
|
# Remove temporary files.
|
2009-06-14 18:36:56 +02:00
|
|
|
rm -f ${tmp}-desc.h1 ${tmp}-desc.c1
|
|
|
|
rm -f ${tmp}-opc.h1 ${tmp}-opc.c1
|
|
|
|
rm -f ${tmp}-opinst.c1
|
|
|
|
rm -f ${tmp}-ibld.h1 ${tmp}-ibld.in1
|
|
|
|
rm -f ${tmp}-asm.in1 ${tmp}-dis.in1
|
2000-08-04 04:21:43 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "$0: bad action: ${action}" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|