Home | History | Annotate | Line # | Download | only in opcodes
      1   1.1  christos #! /bin/sh
      2   1.1  christos # CGEN generic assembler support code.
      3   1.1  christos #
      4  1.10  christos #   Copyright (C) 2000-2025 Free Software Foundation, Inc.
      5   1.1  christos #
      6   1.1  christos #   This file is part of the GNU opcodes library.
      7   1.1  christos #
      8   1.1  christos #   This library is free software; you can redistribute it and/or modify
      9   1.1  christos #   it under the terms of the GNU General Public License as published by
     10   1.1  christos #   the Free Software Foundation; either version 3, or (at your option)
     11   1.1  christos #   any later version.
     12   1.1  christos #
     13   1.1  christos #   It is distributed in the hope that it will be useful, but WITHOUT
     14   1.1  christos #   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     15   1.1  christos #   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     16   1.1  christos #   License for more details.
     17   1.1  christos #
     18   1.1  christos #   You should have received a copy of the GNU General Public License along
     19   1.1  christos #   with this program; if not, write to the Free Software Foundation, Inc.,
     20   1.1  christos #   51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
     21   1.1  christos #
     22   1.1  christos # Generate CGEN opcode files: arch-desc.[ch], arch-opc.[ch],
     23   1.1  christos # arch-asm.c, arch-dis.c, arch-opinst.c, arch-ibld.[ch].
     24   1.1  christos #
     25   1.1  christos # Usage:
     26   1.1  christos # cgen.sh action srcdir cgen cgendir cgenflags arch prefix \
     27   1.1  christos #         arch-file opc-file options [extrafiles]
     28   1.1  christos #
     29   1.3  christos # ACTION is currently always "opcodes". It exists to be consistent with the
     30   1.1  christos # simulator.
     31   1.1  christos # ARCH is the name of the architecture.
     32   1.1  christos # It is substituted into @arch@ and @ARCH@ in the generated files.
     33   1.1  christos # PREFIX is both the generated file prefix and is substituted into
     34   1.1  christos # @prefix@ in the generated files.
     35   1.1  christos # ARCH-FILE is the name of the .cpu file (including path).
     36   1.1  christos # OPC-FILE is the name of the .opc file (including path).
     37   1.1  christos # OPTIONS is comma separated list of options (???).
     38   1.1  christos # EXTRAFILES is a space separated list (1 arg still) of extra files to build:
     39   1.1  christos #	- opinst - arch-opinst.c is being made, causes semantic analysis
     40   1.1  christos #
     41   1.1  christos # We store the generated files in the source directory until we decide to
     42   1.1  christos # ship a Scheme interpreter (or other implementation) with gdb/binutils.
     43   1.1  christos # Maybe we never will.
     44   1.1  christos 
     45   1.1  christos # We want to behave like make, any error forces us to stop.
     46   1.1  christos set -e
     47   1.1  christos 
     48   1.1  christos action=$1
     49   1.1  christos srcdir=$2
     50   1.1  christos cgen="$3"
     51   1.1  christos cgendir=$4
     52   1.1  christos cgenflags=$5
     53   1.1  christos arch=$6
     54   1.1  christos prefix=$7
     55   1.1  christos archfile=$8
     56   1.1  christos opcfile=$9
     57   1.1  christos shift ; options=$9
     58   1.1  christos 
     59   1.1  christos # List of extra files to build.
     60   1.1  christos # Values: opinst (only 1 extra file at present)
     61   1.1  christos shift ; extrafiles=$9
     62   1.1  christos 
     63   1.1  christos rootdir=${srcdir}/..
     64   1.1  christos move_if_change="${CONFIG_SHELL:-/bin/sh} ${rootdir}/move-if-change"
     65   1.1  christos 
     66   1.1  christos # $arch is $6, as passed on the command line.
     67   1.1  christos # $ARCH is the same argument but in all uppercase.
     68   1.1  christos # Both forms are used in this script.
     69   1.1  christos 
     70   1.1  christos lowercase='abcdefghijklmnopqrstuvwxyz'
     71   1.1  christos uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
     72   1.1  christos ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
     73   1.1  christos 
     74   1.1  christos # Allow parallel makes to run multiple cgen's without colliding.
     75   1.1  christos tmp=tmp-$$
     76   1.1  christos 
     77   1.1  christos extrafile_args=""
     78   1.1  christos for ef in .. $extrafiles
     79   1.1  christos do
     80   1.1  christos     case $ef in
     81   1.1  christos     ..) ;;
     82   1.1  christos     opinst) extrafile_args="-Q ${tmp}-opinst.c1 $extrafile_args" ;;
     83   1.1  christos     esac
     84   1.1  christos done
     85   1.1  christos 
     86   1.6  christos header="/* DO NOT EDIT!  -*- buffer-read-only: t -*- vi:set ro:  */"
     87   1.6  christos 
     88   1.1  christos case $action in
     89   1.1  christos opcodes)
     90   1.1  christos 	# Remove residual working files.
     91   1.1  christos 	rm -f ${tmp}-desc.h ${tmp}-desc.h1
     92   1.1  christos 	rm -f ${tmp}-desc.c ${tmp}-desc.c1
     93   1.1  christos 	rm -f ${tmp}-opc.h ${tmp}-opc.h1
     94   1.1  christos 	rm -f ${tmp}-opc.c ${tmp}-opc.c1
     95   1.1  christos 	rm -f ${tmp}-opinst.c ${tmp}-opinst.c1
     96   1.1  christos 	rm -f ${tmp}-ibld.h ${tmp}-ibld.h1
     97   1.1  christos 	rm -f ${tmp}-ibld.c ${tmp}-ibld.in1
     98   1.1  christos 	rm -f ${tmp}-asm.c ${tmp}-asm.in1
     99   1.1  christos 	rm -f ${tmp}-dis.c ${tmp}-dis.in1
    100   1.1  christos 
    101   1.1  christos 	# Run CGEN.
    102   1.1  christos 	${cgen} ${cgendir}/cgen-opc.scm \
    103   1.1  christos 		${cgenflags} \
    104   1.1  christos 		-f "${options}" \
    105   1.1  christos 		-m all \
    106   1.1  christos 		-a ${archfile} \
    107   1.1  christos 	        -OPC ${opcfile} \
    108   1.1  christos 		-H ${tmp}-desc.h1 \
    109   1.1  christos 		-C ${tmp}-desc.c1 \
    110   1.1  christos 		-O ${tmp}-opc.h1 \
    111   1.1  christos 		-P ${tmp}-opc.c1 \
    112   1.1  christos 		-L ${tmp}-ibld.in1 \
    113   1.1  christos 		-A ${tmp}-asm.in1 \
    114   1.1  christos 		-D ${tmp}-dis.in1 \
    115   1.1  christos 		${extrafile_args}
    116   1.1  christos 
    117   1.1  christos 	# Customise generated files for the particular architecture.
    118   1.6  christos 	sed -e "1i$header" \
    119   1.6  christos 	    -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    120   1.3  christos 	    -e 's/[ 	][ 	]*$//' < ${tmp}-desc.h1 > ${tmp}-desc.h
    121   1.1  christos 	${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${prefix}-desc.h
    122   1.1  christos 
    123   1.6  christos 	sed -e "1i$header" \
    124   1.6  christos 	    -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    125   1.3  christos 	    -e "s/@prefix@/${prefix}/" -e 's/[ 	][ 	]*$//' \
    126   1.3  christos 	    < ${tmp}-desc.c1 > ${tmp}-desc.c
    127   1.1  christos 	${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${prefix}-desc.c
    128   1.1  christos 
    129   1.6  christos 	sed -e "1i$header" \
    130   1.6  christos 	    -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    131   1.3  christos 	    -e 's/[ 	][ 	]*$//' < ${tmp}-opc.h1 > ${tmp}-opc.h
    132   1.1  christos 	${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${prefix}-opc.h
    133   1.1  christos 
    134   1.6  christos 	sed -e "1i$header" \
    135   1.6  christos 	    -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    136   1.3  christos 	    -e "s/@prefix@/${prefix}/" -e 's/[ 	][ 	]*$//' \
    137   1.3  christos 	    < ${tmp}-opc.c1 > ${tmp}-opc.c
    138   1.1  christos 	${rootdir}/move-if-change ${tmp}-opc.c ${srcdir}/${prefix}-opc.c
    139   1.1  christos 
    140   1.1  christos 	case $extrafiles in
    141   1.1  christos 	*opinst*)
    142   1.6  christos 	  sed -e "1i$header" \
    143   1.6  christos 	      -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    144   1.3  christos 	      -e "s/@prefix@/${prefix}/" -e 's/[ 	][ 	]*$//' \
    145   1.3  christos 	      < ${tmp}-opinst.c1 >${tmp}-opinst.c
    146   1.1  christos 	  ${rootdir}/move-if-change ${tmp}-opinst.c ${srcdir}/${prefix}-opinst.c
    147   1.1  christos 	  ;;
    148   1.1  christos 	esac
    149   1.1  christos 
    150   1.1  christos 	cat ${srcdir}/cgen-ibld.in ${tmp}-ibld.in1 | \
    151   1.6  christos 	  sed -e "1i$header" \
    152   1.6  christos 	    -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    153   1.3  christos 	    -e "s/@prefix@/${prefix}/" -e 's/[ 	][ 	]*$//' > ${tmp}-ibld.c
    154   1.1  christos 	${rootdir}/move-if-change ${tmp}-ibld.c ${srcdir}/${prefix}-ibld.c
    155   1.1  christos 
    156   1.1  christos 	sed -e "/ -- assembler routines/ r ${tmp}-asm.in1" ${srcdir}/cgen-asm.in \
    157   1.6  christos 	  | sed -e "1i$header" \
    158   1.6  christos 		-e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    159   1.3  christos 		-e "s/@prefix@/${prefix}/" -e 's/[ 	][ 	]*$//' \
    160   1.3  christos 	  > ${tmp}-asm.c
    161   1.1  christos 	${rootdir}/move-if-change ${tmp}-asm.c ${srcdir}/${prefix}-asm.c
    162   1.1  christos 
    163   1.1  christos 	sed -e "/ -- disassembler routines/ r ${tmp}-dis.in1" ${srcdir}/cgen-dis.in \
    164   1.6  christos 	  | sed -e "1i$header" \
    165   1.6  christos 		-e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    166   1.3  christos 		-e "s/@prefix@/${prefix}/" -e 's/[ 	][ 	]*$//' \
    167   1.3  christos 	  > ${tmp}-dis.c
    168   1.1  christos 	${rootdir}/move-if-change ${tmp}-dis.c ${srcdir}/${prefix}-dis.c
    169   1.1  christos 
    170   1.1  christos 	# Remove temporary files.
    171   1.1  christos 	rm -f ${tmp}-desc.h1 ${tmp}-desc.c1
    172   1.1  christos 	rm -f ${tmp}-opc.h1 ${tmp}-opc.c1
    173   1.1  christos 	rm -f ${tmp}-opinst.c1
    174   1.1  christos 	rm -f ${tmp}-ibld.h1 ${tmp}-ibld.in1
    175   1.1  christos 	rm -f ${tmp}-asm.in1 ${tmp}-dis.in1
    176   1.1  christos 	;;
    177   1.1  christos 
    178   1.8  christos desc)
    179   1.8  christos 	# For ports that only generate the desc module & opc header.
    180   1.8  christos 	rm -f ${tmp}-desc.h1 ${tmp}-desc.h
    181   1.8  christos 	rm -f ${tmp}-desc.c1 ${tmp}-desc.c
    182   1.8  christos 	rm -f ${tmp}-opc.h1 ${tmp}-opc.h
    183   1.8  christos 
    184   1.8  christos 	${cgen} ${cgendir}/cgen-opc.scm \
    185   1.8  christos 		${cgenflags} \
    186   1.8  christos 		-OPC ${opcfile} \
    187   1.8  christos 		-f "${archflags}" \
    188   1.8  christos 		-m all \
    189   1.8  christos 		-a ${archfile} \
    190   1.8  christos 		-i all \
    191   1.8  christos 		-H ${tmp}-desc.h1 \
    192   1.8  christos 		-C ${tmp}-desc.c1 \
    193   1.8  christos 		-O ${tmp}-opc.h1
    194   1.8  christos 
    195   1.8  christos 	sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    196  1.10  christos 		-e "s/@prefix@/${prefix}/g" -e 's/[ 	][ 	]*$//' \
    197   1.8  christos 		< ${tmp}-desc.h1 > ${tmp}-desc.h
    198   1.8  christos 	${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${arch}-desc.h
    199   1.8  christos 	sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    200  1.10  christos 		-e "s/@prefix@/${prefix}/g" -e 's/[ 	][ 	]*$//' \
    201   1.8  christos 		< ${tmp}-desc.c1 > ${tmp}-desc.c
    202   1.8  christos 	${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${arch}-desc.c
    203   1.8  christos 	sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
    204  1.10  christos 		-e "s/@prefix@/${prefix}/g" -e 's/[ 	][ 	]*$//' \
    205   1.8  christos 		< ${tmp}-opc.h1 > ${tmp}-opc.h
    206   1.8  christos 	${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${arch}-opc.h
    207   1.8  christos 
    208   1.8  christos 	rm -f ${tmp}-desc.h1 ${tmp}-desc.c1 ${tmp}-opc.h1
    209   1.8  christos 	;;
    210   1.8  christos 
    211   1.1  christos *)
    212   1.1  christos 	echo "$0: bad action: ${action}" >&2
    213   1.1  christos 	exit 1
    214   1.1  christos 	;;
    215   1.1  christos 
    216   1.1  christos esac
    217   1.1  christos 
    218   1.1  christos exit 0
    219