15f210c2aSfgsch#! /bin/sh 25f210c2aSfgsch# CGEN generic assembler support code. 35f210c2aSfgsch# 45f210c2aSfgsch# Copyright 2001 Free Software Foundation, Inc. 55f210c2aSfgsch# 65f210c2aSfgsch# This file is part of the GNU Binutils and GDB, the GNU debugger. 75f210c2aSfgsch# 85f210c2aSfgsch# This program is free software; you can redistribute it and/or modify 95f210c2aSfgsch# it under the terms of the GNU General Public License as published by 105f210c2aSfgsch# the Free Software Foundation; either version 2, or (at your option) 115f210c2aSfgsch# any later version. 125f210c2aSfgsch# 135f210c2aSfgsch# This program is distributed in the hope that it will be useful, 145f210c2aSfgsch# but WITHOUT ANY WARRANTY; without even the implied warranty of 155f210c2aSfgsch# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165f210c2aSfgsch# GNU General Public License for more details. 175f210c2aSfgsch# 185f210c2aSfgsch# You should have received a copy of the GNU General Public License along 195f210c2aSfgsch# with this program; if not, write to the Free Software Foundation, Inc., 205f210c2aSfgsch# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 215f210c2aSfgsch# 225f210c2aSfgsch# Generate CGEN opcode files: arch-desc.[ch], arch-opc.[ch], 235f210c2aSfgsch# arch-asm.c, arch-dis.c, arch-opinst.c, arch-ibld.[ch]. 245f210c2aSfgsch# 255f210c2aSfgsch# Usage: 26*cf2f2c56Smiod# cgen.sh action srcdir cgen cgendir cgenflags arch prefix \ 27*cf2f2c56Smiod# arch-file opc-file options [extrafiles] 285f210c2aSfgsch# 295f210c2aSfgsch# ACTION is currently always "opcodes". It exists to be consistent with the 305f210c2aSfgsch# simulator. 31*cf2f2c56Smiod# ARCH is the name of the architecture. 32*cf2f2c56Smiod# It is substituted into @arch@ and @ARCH@ in the generated files. 33*cf2f2c56Smiod# PREFIX is both the generated file prefix and is substituted into 34*cf2f2c56Smiod# @prefix@ in the generated files. 35*cf2f2c56Smiod# ARCH-FILE is the name of the .cpu file (including path). 36*cf2f2c56Smiod# OPC-FILE is the name of the .opc file (including path). 37*cf2f2c56Smiod# OPTIONS is comma separated list of options (???). 38*cf2f2c56Smiod# EXTRAFILES is a space separated list (1 arg still) of extra files to build: 395f210c2aSfgsch# - opinst - arch-opinst.c is being made, causes semantic analysis 405f210c2aSfgsch# 415f210c2aSfgsch# We store the generated files in the source directory until we decide to 425f210c2aSfgsch# ship a Scheme interpreter (or other implementation) with gdb/binutils. 435f210c2aSfgsch# Maybe we never will. 445f210c2aSfgsch 455f210c2aSfgsch# We want to behave like make, any error forces us to stop. 465f210c2aSfgschset -e 475f210c2aSfgsch 485f210c2aSfgschaction=$1 495f210c2aSfgschsrcdir=$2 505f210c2aSfgschcgen=$3 515f210c2aSfgschcgendir=$4 525f210c2aSfgschcgenflags=$5 535f210c2aSfgscharch=$6 545f210c2aSfgschprefix=$7 55*cf2f2c56Smiodarchfile=$8 56*cf2f2c56Smiodopcfile=$9 57*cf2f2c56Smiodshift ; options=$9 585f210c2aSfgsch 595f210c2aSfgsch# List of extra files to build. 605f210c2aSfgsch# Values: opinst (only 1 extra file at present) 61*cf2f2c56Smiodshift ; extrafiles=$9 625f210c2aSfgsch 635f210c2aSfgschrootdir=${srcdir}/.. 645f210c2aSfgsch 655f210c2aSfgsch# $arch is $6, as passed on the command line. 665f210c2aSfgsch# $ARCH is the same argument but in all uppercase. 675f210c2aSfgsch# Both forms are used in this script. 685f210c2aSfgsch 695f210c2aSfgschlowercase='abcdefghijklmnopqrstuvwxyz' 705f210c2aSfgschuppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ' 715f210c2aSfgschARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"` 725f210c2aSfgsch 735f210c2aSfgschextrafile_args="" 745f210c2aSfgschfor ef in .. $extrafiles 755f210c2aSfgschdo 765f210c2aSfgsch case $ef in 775f210c2aSfgsch ..) ;; 785f210c2aSfgsch opinst) extrafile_args="-Q tmp-opinst.c1 $extrafile_args" ;; 795f210c2aSfgsch esac 805f210c2aSfgschdone 815f210c2aSfgsch 825f210c2aSfgschcase $action in 835f210c2aSfgschopcodes) 845f210c2aSfgsch # Remove residual working files. 855f210c2aSfgsch rm -f tmp-desc.h tmp-desc.h1 865f210c2aSfgsch rm -f tmp-desc.c tmp-desc.c1 875f210c2aSfgsch rm -f tmp-opc.h tmp-opc.h1 885f210c2aSfgsch rm -f tmp-opc.c tmp-opc.c1 895f210c2aSfgsch rm -f tmp-opinst.c tmp-opinst.c1 905f210c2aSfgsch rm -f tmp-ibld.h tmp-ibld.h1 915f210c2aSfgsch rm -f tmp-ibld.c tmp-ibld.in1 925f210c2aSfgsch rm -f tmp-asm.c tmp-asm.in1 935f210c2aSfgsch rm -f tmp-dis.c tmp-dis.in1 945f210c2aSfgsch 955f210c2aSfgsch # Run CGEN. 965f210c2aSfgsch ${cgen} -s ${cgendir}/cgen-opc.scm \ 975f210c2aSfgsch -s ${cgendir} \ 985f210c2aSfgsch ${cgenflags} \ 995f210c2aSfgsch -f "${options}" \ 1005f210c2aSfgsch -m all \ 101*cf2f2c56Smiod -a ${archfile} \ 102*cf2f2c56Smiod -OPC ${opcfile} \ 1035f210c2aSfgsch -H tmp-desc.h1 \ 1045f210c2aSfgsch -C tmp-desc.c1 \ 1055f210c2aSfgsch -O tmp-opc.h1 \ 1065f210c2aSfgsch -P tmp-opc.c1 \ 1075f210c2aSfgsch -L tmp-ibld.in1 \ 1085f210c2aSfgsch -A tmp-asm.in1 \ 1095f210c2aSfgsch -D tmp-dis.in1 \ 1105f210c2aSfgsch ${extrafile_args} 1115f210c2aSfgsch 1125f210c2aSfgsch # Customise generated files for the particular architecture. 1135f210c2aSfgsch sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-desc.h1 > tmp-desc.h 1145f210c2aSfgsch ${rootdir}/move-if-change tmp-desc.h ${srcdir}/${prefix}-desc.h 1155f210c2aSfgsch 1165f210c2aSfgsch sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 1175f210c2aSfgsch -e "s/@prefix@/${prefix}/" < tmp-desc.c1 > tmp-desc.c 1185f210c2aSfgsch ${rootdir}/move-if-change tmp-desc.c ${srcdir}/${prefix}-desc.c 1195f210c2aSfgsch 1205f210c2aSfgsch sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-opc.h1 > tmp-opc.h 1215f210c2aSfgsch ${rootdir}/move-if-change tmp-opc.h ${srcdir}/${prefix}-opc.h 1225f210c2aSfgsch 1235f210c2aSfgsch sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 1245f210c2aSfgsch -e "s/@prefix@/${prefix}/" < tmp-opc.c1 > tmp-opc.c 1255f210c2aSfgsch ${rootdir}/move-if-change tmp-opc.c ${srcdir}/${prefix}-opc.c 1265f210c2aSfgsch 1275f210c2aSfgsch case $extrafiles in 1285f210c2aSfgsch *opinst*) 1295f210c2aSfgsch sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 1305f210c2aSfgsch -e "s/@prefix@/${prefix}/" < tmp-opinst.c1 >tmp-opinst.c 1315f210c2aSfgsch ${rootdir}/move-if-change tmp-opinst.c ${srcdir}/${prefix}-opinst.c 1325f210c2aSfgsch ;; 1335f210c2aSfgsch esac 1345f210c2aSfgsch 1355f210c2aSfgsch cat ${srcdir}/cgen-ibld.in tmp-ibld.in1 | \ 1365f210c2aSfgsch sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 1375f210c2aSfgsch -e "s/@prefix@/${prefix}/" > tmp-ibld.c 1385f210c2aSfgsch ${rootdir}/move-if-change tmp-ibld.c ${srcdir}/${prefix}-ibld.c 1395f210c2aSfgsch 1405f210c2aSfgsch sed -e "/ -- assembler routines/ r tmp-asm.in1" ${srcdir}/cgen-asm.in \ 1415f210c2aSfgsch | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 1425f210c2aSfgsch -e "s/@prefix@/${prefix}/" > tmp-asm.c 1435f210c2aSfgsch ${rootdir}/move-if-change tmp-asm.c ${srcdir}/${prefix}-asm.c 1445f210c2aSfgsch 1455f210c2aSfgsch sed -e "/ -- disassembler routines/ r tmp-dis.in1" ${srcdir}/cgen-dis.in \ 1465f210c2aSfgsch | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \ 1475f210c2aSfgsch -e "s/@prefix@/${prefix}/" > tmp-dis.c 1485f210c2aSfgsch ${rootdir}/move-if-change tmp-dis.c ${srcdir}/${prefix}-dis.c 1495f210c2aSfgsch 1505f210c2aSfgsch # Remove temporary files. 1515f210c2aSfgsch rm -f tmp-desc.h1 tmp-desc.c1 1525f210c2aSfgsch rm -f tmp-opc.h1 tmp-opc.c1 1535f210c2aSfgsch rm -f tmp-opinst.c1 1545f210c2aSfgsch rm -f tmp-ibld.h1 tmp-ibld.in1 1555f210c2aSfgsch rm -f tmp-asm.in1 tmp-dis.in1 1565f210c2aSfgsch ;; 1575f210c2aSfgsch 1585f210c2aSfgsch*) 1595f210c2aSfgsch echo "$0: bad action: ${action}" >&2 1605f210c2aSfgsch exit 1 1615f210c2aSfgsch ;; 1625f210c2aSfgsch 1635f210c2aSfgschesac 1645f210c2aSfgsch 1655f210c2aSfgschexit 0 166