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