2000-09-12 Kazu Hirata <kazu@hxi.com>
[deliverable/binutils-gdb.git] / sim / common / cgen.sh
CommitLineData
604259a0
FCE
1#! /bin/sh
2# Generate CGEN simulator files.
3#
4# Usage: /bin/sh cgen.sh {"arch"|"cpu"|"decode"|"cpu-decode"} srcdir \
5# cgen cgendir cgenflags \
6# arch archflags cpu mach suffix extrafiles
7#
8# We store the generated files in the source directory until we decide to
9# ship a Scheme interpreter (or other implementation) with gdb/binutils.
10# Maybe we never will.
11
12# We want to behave like make, any error forces us to stop.
13set -e
14
15action=$1
16srcdir=$2
17cgen=$3
18cgendir=$4
19cgenflags=$5
20arch=$6
21archflags=$7
22cpu=$8
23mach=$9
24# bring parms past 9 portably into view
25shift ; suffix=$9
26shift ; extrafiles=$9
27
28rootdir=${srcdir}/../..
29
30lowercase='abcdefghijklmnopqrstuvwxyz'
31uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
32ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
33CPU=`echo ${cpu} | tr "${lowercase}" "${uppercase}"`
34
35case $action in
36arch)
37 rm -f tmp-arch.h1 tmp-arch.h
38 rm -f tmp-arch.c1 tmp-arch.c
39 rm -f tmp-all.h1 tmp-all.h
40
41 ${cgen} -s ${cgendir}/cgen-sim.scm \
42 -s ${cgendir} \
43 ${cgenflags} \
44 -f "${archflags}" \
45 -m ${mach} \
46 -a ${arch} \
47 -A tmp-arch.h1 \
48 -B tmp-arch.c1 \
49 -N tmp-all.h1
50 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-arch.h1 > tmp-arch.h
51 ${rootdir}/move-if-change tmp-arch.h ${srcdir}/arch.h
52 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-arch.c1 > tmp-arch.c
53 ${rootdir}/move-if-change tmp-arch.c ${srcdir}/arch.c
54 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-all.h1 > tmp-all.h
55 ${rootdir}/move-if-change tmp-all.h ${srcdir}/cpuall.h
56
57 rm -f tmp-arch.h1 tmp-arch.c1 tmp-all.h1
58 ;;
59
60cpu | decode | cpu-decode)
61
62 fileopts=""
63 case $action in
64 *cpu*)
65 rm -f tmp-cpu.h1 tmp-cpu.c1
66 rm -f tmp-ext.c1 tmp-read.c1 tmp-write.c1
67 rm -f tmp-sem.c1 tmp-semsw.c1
68 rm -f tmp-mod.c1
69 rm -f tmp-cpu.h tmp-cpu.c
70 rm -f tmp-ext.c tmp-read.c tmp-write.c
71 rm -f tmp-sem.c tmp-semsw.c tmp-mod.c
72 fileopts="$fileopts \
73 -C tmp-cpu.h1 \
74 -U tmp-cpu.c1 \
75 -M tmp-mod.c1 \
76 ${extrafiles}"
77 ;;
78 esac
79 case $action in
80 *decode*)
81 rm -f tmp-dec.h1 tmp-dec.h tmp-dec.c1 tmp-dec.c
82 fileopts="$fileopts \
83 -T tmp-dec.h1 \
84 -D tmp-dec.c1"
85 ;;
86 esac
87
88 ${cgen} -s ${cgendir}/cgen-sim.scm \
89 -s ${cgendir} \
90 ${cgenflags} \
91 -f "${archflags}" \
92 -m ${mach} \
93 -a ${arch} \
94 ${fileopts}
95
96 case $action in
97 *cpu*)
98 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" -e "s/@CPU@/${CPU}/g" -e "s/@cpu@/${cpu}/g" < tmp-cpu.h1 > tmp-cpu.h
99 ${rootdir}/move-if-change tmp-cpu.h ${srcdir}/cpu${suffix}.h
100 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" -e "s/@CPU@/${CPU}/g" -e "s/@cpu@/${cpu}/g" < tmp-cpu.c1 > tmp-cpu.c
101 ${rootdir}/move-if-change tmp-cpu.c ${srcdir}/cpu${suffix}.c
102 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" -e "s/@CPU@/${CPU}/g" -e "s/@cpu@/${cpu}/g" < tmp-mod.c1 > tmp-mod.c
103 ${rootdir}/move-if-change tmp-mod.c ${srcdir}/model${suffix}.c
104 if test -f tmp-ext.c1 ; then \
105 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" -e "s/@CPU@/${CPU}/g" -e "s/@cpu@/${cpu}/g" < tmp-ext.c1 > tmp-ext.c ; \
106 ${rootdir}/move-if-change tmp-ext.c ${srcdir}/extract${suffix}.c ; \
107 fi
108 if test -f tmp-read.c1 ; then \
109 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" -e "s/@CPU@/${CPU}/g" -e "s/@cpu@/${cpu}/g" < tmp-read.c1 > tmp-read.c ; \
110 ${rootdir}/move-if-change tmp-read.c ${srcdir}/read${suffix}.c ; \
111 fi
112 if test -f tmp-write.c1 ; then \
113 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" -e "s/@CPU@/${CPU}/g" -e "s/@cpu@/${cpu}/g" < tmp-write.c1 > tmp-write.c ; \
114 ${rootdir}/move-if-change tmp-write.c ${srcdir}/write${suffix}.c ; \
115 fi
116 if test -f tmp-sem.c1 ; then \
117 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" -e "s/@CPU@/${CPU}/g" -e "s/@cpu@/${cpu}/g" < tmp-sem.c1 > tmp-sem.c ; \
118 ${rootdir}/move-if-change tmp-sem.c ${srcdir}/sem${suffix}.c ; \
119 fi
120 if test -f tmp-semsw.c1 ; then \
121 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" -e "s/@CPU@/${CPU}/g" -e "s/@cpu@/${cpu}/g" < tmp-semsw.c1 > tmp-semsw.c ; \
122 ${rootdir}/move-if-change tmp-semsw.c ${srcdir}/sem${suffix}-switch.c ; \
123 fi
124
125 rm -f tmp-cpu.h1 tmp-cpu.c1
126 rm -f tmp-ext.c1 tmp-read.c1 tmp-write.c1
127 rm -f tmp-sem.c1 tmp-semsw.c1 tmp-mod.c1
128 ;;
129 esac
130
131 case $action in
132 *decode*)
133 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" -e "s/@CPU@/${CPU}/g" -e "s/@cpu@/${cpu}/g" < tmp-dec.h1 > tmp-dec.h
134 ${rootdir}/move-if-change tmp-dec.h ${srcdir}/decode${suffix}.h
135 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" -e "s/@CPU@/${CPU}/g" -e "s/@cpu@/${cpu}/g" < tmp-dec.c1 > tmp-dec.c
136 ${rootdir}/move-if-change tmp-dec.c ${srcdir}/decode${suffix}.c
137
138 rm -f tmp-dec.h1 tmp-dec.c1
139 ;;
140 esac
141
142 ;;
143
144desc)
145 rm -f tmp-desc.h1 tmp-desc.h
146 rm -f tmp-desc.c1 tmp-desc.c
147 rm -f tmp-opc.h1 tmp-opc.h
148
149 ${cgen} -s ${cgendir}/cgen-opc.scm \
150 -s ${cgendir} \
151 ${cgenflags} \
152 -f "${archflags}" \
153 -m ${mach} \
154 -a ${arch} \
155 -H tmp-desc.h1 \
156 -C tmp-desc.c1 \
157 -O tmp-opc.h1
158 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-desc.h1 > tmp-desc.h
159 ${rootdir}/move-if-change tmp-desc.h ${srcdir}/${arch}-desc.h
160 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
161 -e "s/@prefix@/${arch}/" < tmp-desc.c1 > tmp-desc.c
162 ${rootdir}/move-if-change tmp-desc.c ${srcdir}/${arch}-desc.c
163 sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" < tmp-opc.h1 > tmp-opc.h
164 ${rootdir}/move-if-change tmp-opc.h ${srcdir}/${arch}-opc.h
165
166 rm -f tmp-desc.h1 tmp-desc.c1 tmp-opc.h1
167 ;;
168
169*)
170 echo "cgen.sh: bad action: ${action}" >&2
171 exit 1
172 ;;
173
174esac
175
176exit 0
This page took 0.030379 seconds and 4 git commands to generate.