1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#! /bin/sh
# CGEN generic assembler support code.
#
# Copyright 2000, 2003, 2005 Free Software Foundation, Inc.
#
# This file is part of the GNU Binutils and GDB, the GNU debugger.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program 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.
#
# 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.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#
# Generate CGEN opcode files: arch-desc.[ch], arch-opc.[ch],
# arch-asm.c, arch-dis.c, arch-opinst.c, arch-ibld.[ch].
#
# Usage:
# cgen.sh action srcdir cgen cgendir cgenflags arch prefix \
# arch-file opc-file options [extrafiles]
#
# ACTION is currently always "opcodes". It exists to be consistent with the
# simulator.
# 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:
# - 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
cgen="$3"
cgendir=$4
cgenflags=$5
arch=$6
prefix=$7
archfile=$8
opcfile=$9
shift ; options=$9
# List of extra files to build.
# Values: opinst (only 1 extra file at present)
shift ; extrafiles=$9
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}"`
extrafile_args=""
for ef in .. $extrafiles
do
case $ef in
..) ;;
opinst) extrafile_args="-Q tmp-opinst.c1 $extrafile_args" ;;
esac
done
case $action in
opcodes)
# Remove residual working files.
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
# Run CGEN.
${cgen} ${cgendir}/cgen-opc.scm \
-s ${cgendir} \
${cgenflags} \
-f "${options}" \
-m all \
-a ${archfile} \
-OPC ${opcfile} \
-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 \
${extrafile_args}
# Customise generated files for the particular architecture.
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-desc.h1 > tmp-desc.h
${rootdir}/move-if-change tmp-desc.h ${srcdir}/${prefix}-desc.h
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
-e "s/@prefix@/${prefix}/" < tmp-desc.c1 > tmp-desc.c
${rootdir}/move-if-change tmp-desc.c ${srcdir}/${prefix}-desc.c
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-opc.h1 > tmp-opc.h
${rootdir}/move-if-change tmp-opc.h ${srcdir}/${prefix}-opc.h
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
-e "s/@prefix@/${prefix}/" < tmp-opc.c1 > tmp-opc.c
${rootdir}/move-if-change tmp-opc.c ${srcdir}/${prefix}-opc.c
case $extrafiles in
*opinst*)
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
-e "s/@prefix@/${prefix}/" < tmp-opinst.c1 >tmp-opinst.c
${rootdir}/move-if-change tmp-opinst.c ${srcdir}/${prefix}-opinst.c
;;
esac
cat ${srcdir}/cgen-ibld.in tmp-ibld.in1 | \
sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
-e "s/@prefix@/${prefix}/" > tmp-ibld.c
${rootdir}/move-if-change tmp-ibld.c ${srcdir}/${prefix}-ibld.c
sed -e "/ -- assembler routines/ r tmp-asm.in1" ${srcdir}/cgen-asm.in \
| sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
-e "s/@prefix@/${prefix}/" > tmp-asm.c
${rootdir}/move-if-change tmp-asm.c ${srcdir}/${prefix}-asm.c
sed -e "/ -- disassembler routines/ r tmp-dis.in1" ${srcdir}/cgen-dis.in \
| sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
-e "s/@prefix@/${prefix}/" > tmp-dis.c
${rootdir}/move-if-change tmp-dis.c ${srcdir}/${prefix}-dis.c
# Remove temporary files.
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
;;
*)
echo "$0: bad action: ${action}" >&2
exit 1
;;
esac
exit 0
|