2 # Generate CGEN simulator files.
4 # Usage: /bin/sh cgen.sh {"arch"|"cpu"|"decode"|"defs"|"cpu-decode"} \
5 # srcdir cgen cgendir cgenflags \
6 # arch archflags cpu mach suffix archfile extrafiles opcfile
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.
12 # We want to behave like make, any error forces us to stop.
24 # portably bring parameters beyond $9 into view
31 rootdir
=${srcdir}/..
/..
33 test -z "${opcfile}" && opcfile
=/dev
/null
35 if test -z "$isa" ; then
42 lowercase
='abcdefghijklmnopqrstuvwxyz'
43 uppercase
='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
44 ARCH
=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
45 CPU
=`echo ${cpu} | tr "${lowercase}" "${uppercase}"`
46 PREFIX
=`echo ${prefix} | tr "${lowercase}" "${uppercase}"`
49 -e s/@ARCH@/${ARCH}/g -e s/@arch@/${arch}/g \
50 -e s/@CPU@/${CPU}/g -e s/@cpu@/${cpu}/g \
51 -e s/@PREFIX@/${PREFIX}/g -e s/@prefix@/${prefix}/g"
53 # avoid collisions in parallel makes
58 rm -f ${tmp}-arch.h1
${tmp}-arch.h
59 rm -f ${tmp}-arch.c1
${tmp}-arch.c
60 rm -f ${tmp}-all.h1
${tmp}-all.h
62 ${cgen} ${cgendir}/cgen-sim.scm \
72 sed $sedscript < ${tmp}-arch.h1
> ${tmp}-arch.h
73 ${rootdir}/move-if-change ${tmp}-arch.h ${srcdir}/arch.h
74 sed $sedscript < ${tmp}-arch.c1
> ${tmp}-arch.c
75 ${rootdir}/move-if-change ${tmp}-arch.c ${srcdir}/arch.c
76 sed $sedscript < ${tmp}-all.h1
> ${tmp}-all.h
77 ${rootdir}/move-if-change ${tmp}-all.h ${srcdir}/cpuall.h
79 rm -f ${tmp}-arch.h1 ${tmp}-arch.c1 ${tmp}-all.h1
82 cpu | decode | cpu-decode
)
88 rm -f ${tmp}-cpu.h1
${tmp}-cpu.c1
89 rm -f ${tmp}-ext.c1 ${tmp}-read.c1 ${tmp}-write.c1
90 rm -f ${tmp}-sem.c1
${tmp}-semsw.c1
92 rm -f ${tmp}-cpu.h
${tmp}-cpu.c
93 rm -f ${tmp}-ext.c ${tmp}-read.c ${tmp}-write.c
94 rm -f ${tmp}-sem.c ${tmp}-semsw.c ${tmp}-mod.c
104 rm -f ${tmp}-dec.h1 ${tmp}-dec.h ${tmp}-dec.c1 ${tmp}-dec.c
105 fileopts
="$fileopts \
111 case "$extrafiles" in
112 */extr
/*) fileopts
="${fileopts} -E ${tmp}-ext.c1" ;;
114 case "$extrafiles" in
115 */read
/*) fileopts
="${fileopts} -R ${tmp}-read.c1" ;;
117 case "$extrafiles" in
118 */write
/*) fileopts
="${fileopts} -W ${tmp}-write.c1" ;;
120 case "$extrafiles" in
121 */sem
/*) fileopts
="${fileopts} -S ${tmp}-sem.c1" ;;
123 case "$extrafiles" in
124 */semsw
/*) fileopts
="${fileopts} -X ${tmp}-semsw.c1" ;;
127 ${cgen} ${cgendir}/cgen-sim.scm \
138 sed $sedscript < ${tmp}-cpu.h1
> ${tmp}-cpu.h
139 ${rootdir}/move-if-change ${tmp}-cpu.h ${srcdir}/cpu${suffix}.h
140 sed $sedscript < ${tmp}-cpu.c1
> ${tmp}-cpu.c
141 ${rootdir}/move-if-change ${tmp}-cpu.c ${srcdir}/cpu${suffix}.c
142 sed $sedscript < ${tmp}-mod.c1
> ${tmp}-mod.c
143 ${rootdir}/move-if-change ${tmp}-mod.c ${srcdir}/model${suffix}.c
144 rm -f ${tmp}-cpu.h1 ${tmp}-cpu.c1 ${tmp}-mod.c1
150 sed $sedscript < ${tmp}-dec.h1
> ${tmp}-dec.h
151 ${rootdir}/move-if-change ${tmp}-dec.h ${srcdir}/decode${suffix}.h
152 sed $sedscript < ${tmp}-dec.c1
> ${tmp}-dec.c
153 ${rootdir}/move-if-change ${tmp}-dec.c ${srcdir}/decode${suffix}.c
154 rm -f ${tmp}-dec.h1
${tmp}-dec.c1
158 if test -f ${tmp}-ext.c1
; then \
159 sed $sedscript < ${tmp}-ext.c1
> ${tmp}-ext.c
; \
160 ${rootdir}/move-if-change ${tmp}-ext.c ${srcdir}/extract${suffix}.c
; \
163 if test -f ${tmp}-read.c1
; then \
164 sed $sedscript < ${tmp}-read.c1
> ${tmp}-read.c
; \
165 ${rootdir}/move-if-change ${tmp}-read.c ${srcdir}/read${suffix}.c
; \
168 if test -f ${tmp}-write.c1
; then \
169 sed $sedscript < ${tmp}-write.c1
> ${tmp}-write.c
; \
170 ${rootdir}/move-if-change ${tmp}-write.c ${srcdir}/write${suffix}.c
; \
171 rm -f ${tmp}-write.c1
173 if test -f ${tmp}-sem.c1
; then \
174 sed $sedscript < ${tmp}-sem.c1
> ${tmp}-sem.c
; \
175 ${rootdir}/move-if-change ${tmp}-sem.c ${srcdir}/sem${suffix}.c
; \
178 if test -f ${tmp}-semsw.c1
; then \
179 sed $sedscript < ${tmp}-semsw.c1
> ${tmp}-semsw.c
; \
180 ${rootdir}/move-if-change ${tmp}-semsw.c ${srcdir}/sem${suffix}-switch.c
; \
181 rm -f ${tmp}-semsw.c1
187 rm -f ${tmp}-defs.h1
${tmp}-defs.h
189 ${cgen} ${cgendir}/cgen-sim.scm \
197 sed $sedscript < ${tmp}-defs.h1
> ${tmp}-defs.h
198 ${rootdir}/move-if-change ${tmp}-defs.h ${srcdir}/defs${suffix}.h
203 rm -f ${tmp}-desc.h1
${tmp}-desc.h
204 rm -f ${tmp}-desc.c1
${tmp}-desc.c
205 rm -f ${tmp}-opc.h1
${tmp}-opc.h
207 ${cgen} ${cgendir}/cgen-opc.scm \
218 sed $sedscript < ${tmp}-desc.h1
> ${tmp}-desc.h
219 ${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${arch}-desc.h
220 sed $sedscript < ${tmp}-desc.c1
> ${tmp}-desc.c
221 ${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${arch}-desc.c
222 sed $sedscript < ${tmp}-opc.h1
> ${tmp}-opc.h
223 ${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${arch}-opc.h
225 rm -f ${tmp}-desc.h1 ${tmp}-desc.c1 ${tmp}-opc.h1
229 echo "`basename $0`: unknown action: ${action}" >&2