185815Sobrien#! /bin/sh 285815Sobrien# CGEN generic assembler support code. 385815Sobrien# 4218822Sdim# Copyright 2000, 2003, 2005 Free Software Foundation, Inc. 585815Sobrien# 685815Sobrien# This file is part of the GNU Binutils and GDB, the GNU debugger. 785815Sobrien# 885815Sobrien# This program is free software; you can redistribute it and/or modify 985815Sobrien# it under the terms of the GNU General Public License as published by 1085815Sobrien# the Free Software Foundation; either version 2, or (at your option) 1185815Sobrien# any later version. 1285815Sobrien# 1385815Sobrien# This program is distributed in the hope that it will be useful, 1485815Sobrien# but WITHOUT ANY WARRANTY; without even the implied warranty of 1585815Sobrien# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1685815Sobrien# GNU General Public License for more details. 1785815Sobrien# 1885815Sobrien# You should have received a copy of the GNU General Public License along 1985815Sobrien# with this program; if not, write to the Free Software Foundation, Inc., 20218822Sdim# 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 2185815Sobrien# 2285815Sobrien# Generate CGEN opcode files: arch-desc.[ch], arch-opc.[ch], 2385815Sobrien# arch-asm.c, arch-dis.c, arch-opinst.c, arch-ibld.[ch]. 2485815Sobrien# 2585815Sobrien# Usage: 26130561Sobrien# cgen.sh action srcdir cgen cgendir cgenflags arch prefix \ 27130561Sobrien# arch-file opc-file options [extrafiles] 2885815Sobrien# 2985815Sobrien# ACTION is currently always "opcodes". It exists to be consistent with the 3085815Sobrien# simulator. 31130561Sobrien# ARCH is the name of the architecture. 32130561Sobrien# It is substituted into @arch@ and @ARCH@ in the generated files. 33130561Sobrien# PREFIX is both the generated file prefix and is substituted into 34130561Sobrien# @prefix@ in the generated files. 35130561Sobrien# ARCH-FILE is the name of the .cpu file (including path). 36130561Sobrien# OPC-FILE is the name of the .opc file (including path). 37130561Sobrien# OPTIONS is comma separated list of options (???). 38130561Sobrien# EXTRAFILES is a space separated list (1 arg still) of extra files to build: 3985815Sobrien# - opinst - arch-opinst.c is being made, causes semantic analysis 4085815Sobrien# 4185815Sobrien# We store the generated files in the source directory until we decide to 4285815Sobrien# ship a Scheme interpreter (or other implementation) with gdb/binutils. 4385815Sobrien# Maybe we never will. 4485815Sobrien 4585815Sobrien# We want to behave like make, any error forces us to stop. 4685815Sobrienset -e 4785815Sobrien 4885815Sobrienaction=$1 4985815Sobriensrcdir=$2 50218822Sdimcgen="$3" 5185815Sobriencgendir=$4 5285815Sobriencgenflags=$5 5385815Sobrienarch=$6 5485815Sobrienprefix=$7 55130561Sobrienarchfile=$8 56130561Sobrienopcfile=$9 57130561Sobrienshift ; options=$9 5885815Sobrien 5985815Sobrien# List of extra files to build. 6085815Sobrien# Values: opinst (only 1 extra file at present) 61130561Sobrienshift ; extrafiles=$9 6285815Sobrien 6385815Sobrienrootdir=${srcdir}/.. 6485815Sobrien 6585815Sobrien# $arch is $6, as passed on the command line. 6685815Sobrien# $ARCH is the same argument but in all uppercase. 6785815Sobrien# Both forms are used in this script. 6885815Sobrien 6985815Sobrienlowercase='abcdefghijklmnopqrstuvwxyz' 7085815Sobrienuppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ' 7185815SobrienARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"` 7285815Sobrien 7385815Sobrienextrafile_args="" 7485815Sobrienfor ef in .. $extrafiles 7585815Sobriendo 7685815Sobrien case $ef in 7785815Sobrien ..) ;; 7885815Sobrien opinst) extrafile_args="-Q tmp-opinst.c1 $extrafile_args" ;; 7985815Sobrien esac 8085815Sobriendone 8185815Sobrien 8285815Sobriencase $action in 8385815Sobrienopcodes) 8485815Sobrien # Remove residual working files. 8585815Sobrien rm -f tmp-desc.h tmp-desc.h1 8685815Sobrien rm -f tmp-desc.c tmp-desc.c1 8785815Sobrien rm -f tmp-opc.h tmp-opc.h1 8885815Sobrien rm -f tmp-opc.c tmp-opc.c1 8985815Sobrien rm -f tmp-opinst.c tmp-opinst.c1 9085815Sobrien rm -f tmp-ibld.h tmp-ibld.h1 9185815Sobrien rm -f tmp-ibld.c tmp-ibld.in1 9285815Sobrien rm -f tmp-asm.c tmp-asm.in1 9385815Sobrien rm -f tmp-dis.c tmp-dis.in1 9485815Sobrien 9585815Sobrien # Run CGEN. 96218822Sdim ${cgen} ${cgendir}/cgen-opc.scm \ 9785815Sobrien -s ${cgendir} \ 9885815Sobrien ${cgenflags} \ 9985815Sobrien -f "${options}" \ 10085815Sobrien -m all \ 101130561Sobrien -a ${archfile} \ 102130561Sobrien -OPC ${opcfile} \ 10385815Sobrien -H tmp-desc.h1 \ 10485815Sobrien -C tmp-desc.c1 \ 10585815Sobrien -O tmp-opc.h1 \ 10685815Sobrien -P tmp-opc.c1 \ 10785815Sobrien -L tmp-ibld.in1 \ 10885815Sobrien -A tmp-asm.in1 \ 10985815Sobrien -D tmp-dis.in1 \ 11085815Sobrien ${extrafile_args} 11185815Sobrien 11285815Sobrien # Customise generated files for the particular architecture. 11385815Sobrien sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-desc.h1 > tmp-desc.h 11485815Sobrien ${rootdir}/move-if-change tmp-desc.h ${srcdir}/${prefix}-desc.h 11585815Sobrien 11685815Sobrien sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 11785815Sobrien -e "s/@prefix@/${prefix}/" < tmp-desc.c1 > tmp-desc.c 11885815Sobrien ${rootdir}/move-if-change tmp-desc.c ${srcdir}/${prefix}-desc.c 11985815Sobrien 12085815Sobrien sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-opc.h1 > tmp-opc.h 12185815Sobrien ${rootdir}/move-if-change tmp-opc.h ${srcdir}/${prefix}-opc.h 12285815Sobrien 12385815Sobrien sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 12485815Sobrien -e "s/@prefix@/${prefix}/" < tmp-opc.c1 > tmp-opc.c 12585815Sobrien ${rootdir}/move-if-change tmp-opc.c ${srcdir}/${prefix}-opc.c 12685815Sobrien 12785815Sobrien case $extrafiles in 12885815Sobrien *opinst*) 12985815Sobrien sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 13085815Sobrien -e "s/@prefix@/${prefix}/" < tmp-opinst.c1 >tmp-opinst.c 13185815Sobrien ${rootdir}/move-if-change tmp-opinst.c ${srcdir}/${prefix}-opinst.c 13285815Sobrien ;; 13385815Sobrien esac 13485815Sobrien 13585815Sobrien cat ${srcdir}/cgen-ibld.in tmp-ibld.in1 | \ 13685815Sobrien sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 13785815Sobrien -e "s/@prefix@/${prefix}/" > tmp-ibld.c 13885815Sobrien ${rootdir}/move-if-change tmp-ibld.c ${srcdir}/${prefix}-ibld.c 13985815Sobrien 14085815Sobrien sed -e "/ -- assembler routines/ r tmp-asm.in1" ${srcdir}/cgen-asm.in \ 14185815Sobrien | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 14285815Sobrien -e "s/@prefix@/${prefix}/" > tmp-asm.c 14385815Sobrien ${rootdir}/move-if-change tmp-asm.c ${srcdir}/${prefix}-asm.c 14485815Sobrien 14585815Sobrien sed -e "/ -- disassembler routines/ r tmp-dis.in1" ${srcdir}/cgen-dis.in \ 14685815Sobrien | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 14785815Sobrien -e "s/@prefix@/${prefix}/" > tmp-dis.c 14885815Sobrien ${rootdir}/move-if-change tmp-dis.c ${srcdir}/${prefix}-dis.c 14985815Sobrien 15085815Sobrien # Remove temporary files. 15185815Sobrien rm -f tmp-desc.h1 tmp-desc.c1 15285815Sobrien rm -f tmp-opc.h1 tmp-opc.c1 15385815Sobrien rm -f tmp-opinst.c1 15485815Sobrien rm -f tmp-ibld.h1 tmp-ibld.in1 15585815Sobrien rm -f tmp-asm.in1 tmp-dis.in1 15685815Sobrien ;; 15785815Sobrien 15885815Sobrien*) 15985815Sobrien echo "$0: bad action: ${action}" >&2 16085815Sobrien exit 1 16185815Sobrien ;; 16285815Sobrien 16385815Sobrienesac 16485815Sobrien 16585815Sobrienexit 0 166