1*3d8817e4Smiod#! /bin/sh
2*3d8817e4Smiod# CGEN generic assembler support code.
3*3d8817e4Smiod#
4*3d8817e4Smiod#  Copyright 2000, 2003, 2005 Free Software Foundation, Inc.
5*3d8817e4Smiod#
6*3d8817e4Smiod#   This file is part of the GNU Binutils and GDB, the GNU debugger.
7*3d8817e4Smiod#
8*3d8817e4Smiod#   This program is free software; you can redistribute it and/or modify
9*3d8817e4Smiod#   it under the terms of the GNU General Public License as published by
10*3d8817e4Smiod#   the Free Software Foundation; either version 2, or (at your option)
11*3d8817e4Smiod#   any later version.
12*3d8817e4Smiod#
13*3d8817e4Smiod#   This program is distributed in the hope that it will be useful,
14*3d8817e4Smiod#   but WITHOUT ANY WARRANTY; without even the implied warranty of
15*3d8817e4Smiod#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*3d8817e4Smiod#   GNU General Public License for more details.
17*3d8817e4Smiod#
18*3d8817e4Smiod#   You should have received a copy of the GNU General Public License along
19*3d8817e4Smiod#   with this program; if not, write to the Free Software Foundation, Inc.,
20*3d8817e4Smiod#   51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
21*3d8817e4Smiod#
22*3d8817e4Smiod# Generate CGEN opcode files: arch-desc.[ch], arch-opc.[ch],
23*3d8817e4Smiod# arch-asm.c, arch-dis.c, arch-opinst.c, arch-ibld.[ch].
24*3d8817e4Smiod#
25*3d8817e4Smiod# Usage:
26*3d8817e4Smiod# cgen.sh action srcdir cgen cgendir cgenflags arch prefix \
27*3d8817e4Smiod#         arch-file opc-file options [extrafiles]
28*3d8817e4Smiod#
29*3d8817e4Smiod# ACTION is currently always "opcodes". It exists to be consistent with the
30*3d8817e4Smiod# simulator.
31*3d8817e4Smiod# ARCH is the name of the architecture.
32*3d8817e4Smiod# It is substituted into @arch@ and @ARCH@ in the generated files.
33*3d8817e4Smiod# PREFIX is both the generated file prefix and is substituted into
34*3d8817e4Smiod# @prefix@ in the generated files.
35*3d8817e4Smiod# ARCH-FILE is the name of the .cpu file (including path).
36*3d8817e4Smiod# OPC-FILE is the name of the .opc file (including path).
37*3d8817e4Smiod# OPTIONS is comma separated list of options (???).
38*3d8817e4Smiod# EXTRAFILES is a space separated list (1 arg still) of extra files to build:
39*3d8817e4Smiod#	- opinst - arch-opinst.c is being made, causes semantic analysis
40*3d8817e4Smiod#
41*3d8817e4Smiod# We store the generated files in the source directory until we decide to
42*3d8817e4Smiod# ship a Scheme interpreter (or other implementation) with gdb/binutils.
43*3d8817e4Smiod# Maybe we never will.
44*3d8817e4Smiod
45*3d8817e4Smiod# We want to behave like make, any error forces us to stop.
46*3d8817e4Smiodset -e
47*3d8817e4Smiod
48*3d8817e4Smiodaction=$1
49*3d8817e4Smiodsrcdir=$2
50*3d8817e4Smiodcgen="$3"
51*3d8817e4Smiodcgendir=$4
52*3d8817e4Smiodcgenflags=$5
53*3d8817e4Smiodarch=$6
54*3d8817e4Smiodprefix=$7
55*3d8817e4Smiodarchfile=$8
56*3d8817e4Smiodopcfile=$9
57*3d8817e4Smiodshift ; options=$9
58*3d8817e4Smiod
59*3d8817e4Smiod# List of extra files to build.
60*3d8817e4Smiod# Values: opinst (only 1 extra file at present)
61*3d8817e4Smiodshift ; extrafiles=$9
62*3d8817e4Smiod
63*3d8817e4Smiodrootdir=${srcdir}/..
64*3d8817e4Smiod
65*3d8817e4Smiod# $arch is $6, as passed on the command line.
66*3d8817e4Smiod# $ARCH is the same argument but in all uppercase.
67*3d8817e4Smiod# Both forms are used in this script.
68*3d8817e4Smiod
69*3d8817e4Smiodlowercase='abcdefghijklmnopqrstuvwxyz'
70*3d8817e4Smioduppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
71*3d8817e4SmiodARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
72*3d8817e4Smiod
73*3d8817e4Smiodextrafile_args=""
74*3d8817e4Smiodfor ef in .. $extrafiles
75*3d8817e4Smioddo
76*3d8817e4Smiod    case $ef in
77*3d8817e4Smiod    ..) ;;
78*3d8817e4Smiod    opinst) extrafile_args="-Q tmp-opinst.c1 $extrafile_args" ;;
79*3d8817e4Smiod    esac
80*3d8817e4Smioddone
81*3d8817e4Smiod
82*3d8817e4Smiodcase $action in
83*3d8817e4Smiodopcodes)
84*3d8817e4Smiod	# Remove residual working files.
85*3d8817e4Smiod	rm -f tmp-desc.h tmp-desc.h1
86*3d8817e4Smiod	rm -f tmp-desc.c tmp-desc.c1
87*3d8817e4Smiod	rm -f tmp-opc.h tmp-opc.h1
88*3d8817e4Smiod	rm -f tmp-opc.c tmp-opc.c1
89*3d8817e4Smiod	rm -f tmp-opinst.c tmp-opinst.c1
90*3d8817e4Smiod	rm -f tmp-ibld.h tmp-ibld.h1
91*3d8817e4Smiod	rm -f tmp-ibld.c tmp-ibld.in1
92*3d8817e4Smiod	rm -f tmp-asm.c tmp-asm.in1
93*3d8817e4Smiod	rm -f tmp-dis.c tmp-dis.in1
94*3d8817e4Smiod
95*3d8817e4Smiod	# Run CGEN.
96*3d8817e4Smiod	${cgen} ${cgendir}/cgen-opc.scm \
97*3d8817e4Smiod		-s ${cgendir} \
98*3d8817e4Smiod		${cgenflags} \
99*3d8817e4Smiod		-f "${options}" \
100*3d8817e4Smiod		-m all \
101*3d8817e4Smiod		-a ${archfile} \
102*3d8817e4Smiod	        -OPC ${opcfile} \
103*3d8817e4Smiod		-H tmp-desc.h1 \
104*3d8817e4Smiod		-C tmp-desc.c1 \
105*3d8817e4Smiod		-O tmp-opc.h1 \
106*3d8817e4Smiod		-P tmp-opc.c1 \
107*3d8817e4Smiod		-L tmp-ibld.in1 \
108*3d8817e4Smiod		-A tmp-asm.in1 \
109*3d8817e4Smiod		-D tmp-dis.in1 \
110*3d8817e4Smiod		${extrafile_args}
111*3d8817e4Smiod
112*3d8817e4Smiod	# Customise generated files for the particular architecture.
113*3d8817e4Smiod	sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-desc.h1 > tmp-desc.h
114*3d8817e4Smiod	${rootdir}/move-if-change tmp-desc.h ${srcdir}/${prefix}-desc.h
115*3d8817e4Smiod
116*3d8817e4Smiod	sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
117*3d8817e4Smiod		-e "s/@prefix@/${prefix}/" < tmp-desc.c1 > tmp-desc.c
118*3d8817e4Smiod	${rootdir}/move-if-change tmp-desc.c ${srcdir}/${prefix}-desc.c
119*3d8817e4Smiod
120*3d8817e4Smiod	sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-opc.h1 > tmp-opc.h
121*3d8817e4Smiod	${rootdir}/move-if-change tmp-opc.h ${srcdir}/${prefix}-opc.h
122*3d8817e4Smiod
123*3d8817e4Smiod	sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
124*3d8817e4Smiod		-e "s/@prefix@/${prefix}/" < tmp-opc.c1 > tmp-opc.c
125*3d8817e4Smiod	${rootdir}/move-if-change tmp-opc.c ${srcdir}/${prefix}-opc.c
126*3d8817e4Smiod
127*3d8817e4Smiod	case $extrafiles in
128*3d8817e4Smiod	*opinst*)
129*3d8817e4Smiod	  sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
130*3d8817e4Smiod		-e "s/@prefix@/${prefix}/" < tmp-opinst.c1 >tmp-opinst.c
131*3d8817e4Smiod	  ${rootdir}/move-if-change tmp-opinst.c ${srcdir}/${prefix}-opinst.c
132*3d8817e4Smiod	  ;;
133*3d8817e4Smiod	esac
134*3d8817e4Smiod
135*3d8817e4Smiod	cat ${srcdir}/cgen-ibld.in tmp-ibld.in1 | \
136*3d8817e4Smiod	  sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
137*3d8817e4Smiod		-e "s/@prefix@/${prefix}/" > tmp-ibld.c
138*3d8817e4Smiod	${rootdir}/move-if-change tmp-ibld.c ${srcdir}/${prefix}-ibld.c
139*3d8817e4Smiod
140*3d8817e4Smiod	sed -e "/ -- assembler routines/ r tmp-asm.in1" ${srcdir}/cgen-asm.in \
141*3d8817e4Smiod	  | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
142*3d8817e4Smiod		-e "s/@prefix@/${prefix}/" > tmp-asm.c
143*3d8817e4Smiod	${rootdir}/move-if-change tmp-asm.c ${srcdir}/${prefix}-asm.c
144*3d8817e4Smiod
145*3d8817e4Smiod	sed -e "/ -- disassembler routines/ r tmp-dis.in1" ${srcdir}/cgen-dis.in \
146*3d8817e4Smiod	  | sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
147*3d8817e4Smiod		-e "s/@prefix@/${prefix}/" > tmp-dis.c
148*3d8817e4Smiod	${rootdir}/move-if-change tmp-dis.c ${srcdir}/${prefix}-dis.c
149*3d8817e4Smiod
150*3d8817e4Smiod	# Remove temporary files.
151*3d8817e4Smiod	rm -f tmp-desc.h1 tmp-desc.c1
152*3d8817e4Smiod	rm -f tmp-opc.h1 tmp-opc.c1
153*3d8817e4Smiod	rm -f tmp-opinst.c1
154*3d8817e4Smiod	rm -f tmp-ibld.h1 tmp-ibld.in1
155*3d8817e4Smiod	rm -f tmp-asm.in1 tmp-dis.in1
156*3d8817e4Smiod	;;
157*3d8817e4Smiod
158*3d8817e4Smiod*)
159*3d8817e4Smiod	echo "$0: bad action: ${action}" >&2
160*3d8817e4Smiod	exit 1
161*3d8817e4Smiod	;;
162*3d8817e4Smiod
163*3d8817e4Smiodesac
164*3d8817e4Smiod
165*3d8817e4Smiodexit 0
166