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 \
71 sed $sedscript < ${tmp}-arch.h1
> ${tmp}-arch.h
72 ${rootdir}/move-if-change ${tmp}-arch.h ${srcdir}/arch.h
73 sed $sedscript < ${tmp}-arch.c1
> ${tmp}-arch.c
74 ${rootdir}/move-if-change ${tmp}-arch.c ${srcdir}/arch.c
75 sed $sedscript < ${tmp}-all.h1
> ${tmp}-all.h
76 ${rootdir}/move-if-change ${tmp}-all.h ${srcdir}/cpuall.h
78 rm -f ${tmp}-arch.h1 ${tmp}-arch.c1 ${tmp}-all.h1
81 cpu | decode | cpu-decode
)
87 rm -f ${tmp}-cpu.h1
${tmp}-cpu.c1
88 rm -f ${tmp}-ext.c1 ${tmp}-read.c1 ${tmp}-write.c1
89 rm -f ${tmp}-sem.c1
${tmp}-semsw.c1
91 rm -f ${tmp}-cpu.h
${tmp}-cpu.c
92 rm -f ${tmp}-ext.c ${tmp}-read.c ${tmp}-write.c
93 rm -f ${tmp}-sem.c ${tmp}-semsw.c ${tmp}-mod.c
103 rm -f ${tmp}-dec.h1 ${tmp}-dec.h ${tmp}-dec.c1 ${tmp}-dec.c
104 fileopts
="$fileopts \
110 case "$extrafiles" in
111 */extr
/*) fileopts
="${fileopts} -E ${tmp}-ext.c1" ;;
113 case "$extrafiles" in
114 */read
/*) fileopts
="${fileopts} -R ${tmp}-read.c1" ;;
116 case "$extrafiles" in
117 */write
/*) fileopts
="${fileopts} -W ${tmp}-write.c1" ;;
119 case "$extrafiles" in
120 */sem
/*) fileopts
="${fileopts} -S ${tmp}-sem.c1" ;;
122 case "$extrafiles" in
123 */semsw
/*) fileopts
="${fileopts} -X ${tmp}-semsw.c1" ;;
126 ${cgen} ${cgendir}/cgen-sim.scm \
136 sed $sedscript < ${tmp}-cpu.h1
> ${tmp}-cpu.h
137 ${rootdir}/move-if-change ${tmp}-cpu.h ${srcdir}/cpu${suffix}.h
138 sed $sedscript < ${tmp}-cpu.c1
> ${tmp}-cpu.c
139 ${rootdir}/move-if-change ${tmp}-cpu.c ${srcdir}/cpu${suffix}.c
140 sed $sedscript < ${tmp}-mod.c1
> ${tmp}-mod.c
141 ${rootdir}/move-if-change ${tmp}-mod.c ${srcdir}/model${suffix}.c
142 rm -f ${tmp}-cpu.h1 ${tmp}-cpu.c1 ${tmp}-mod.c1
148 sed $sedscript < ${tmp}-dec.h1
> ${tmp}-dec.h
149 ${rootdir}/move-if-change ${tmp}-dec.h ${srcdir}/decode${suffix}.h
150 sed $sedscript < ${tmp}-dec.c1
> ${tmp}-dec.c
151 ${rootdir}/move-if-change ${tmp}-dec.c ${srcdir}/decode${suffix}.c
152 rm -f ${tmp}-dec.h1
${tmp}-dec.c1
156 if test -f ${tmp}-ext.c1
; then \
157 sed $sedscript < ${tmp}-ext.c1
> ${tmp}-ext.c
; \
158 ${rootdir}/move-if-change ${tmp}-ext.c ${srcdir}/extract${suffix}.c
; \
161 if test -f ${tmp}-read.c1
; then \
162 sed $sedscript < ${tmp}-read.c1
> ${tmp}-read.c
; \
163 ${rootdir}/move-if-change ${tmp}-read.c ${srcdir}/read${suffix}.c
; \
166 if test -f ${tmp}-write.c1
; then \
167 sed $sedscript < ${tmp}-write.c1
> ${tmp}-write.c
; \
168 ${rootdir}/move-if-change ${tmp}-write.c ${srcdir}/write${suffix}.c
; \
169 rm -f ${tmp}-write.c1
171 if test -f ${tmp}-sem.c1
; then \
172 sed $sedscript < ${tmp}-sem.c1
> ${tmp}-sem.c
; \
173 ${rootdir}/move-if-change ${tmp}-sem.c ${srcdir}/sem${suffix}.c
; \
176 if test -f ${tmp}-semsw.c1
; then \
177 sed $sedscript < ${tmp}-semsw.c1
> ${tmp}-semsw.c
; \
178 ${rootdir}/move-if-change ${tmp}-semsw.c ${srcdir}/sem${suffix}-switch.c
; \
179 rm -f ${tmp}-semsw.c1
185 rm -f ${tmp}-defs.h1
${tmp}-defs.h
187 ${cgen} ${cgendir}/cgen-sim.scm \
194 sed $sedscript < ${tmp}-defs.h1
> ${tmp}-defs.h
195 ${rootdir}/move-if-change ${tmp}-defs.h ${srcdir}/defs${suffix}.h
200 rm -f ${tmp}-desc.h1
${tmp}-desc.h
201 rm -f ${tmp}-desc.c1
${tmp}-desc.c
202 rm -f ${tmp}-opc.h1
${tmp}-opc.h
204 ${cgen} ${cgendir}/cgen-opc.scm \
214 sed $sedscript < ${tmp}-desc.h1
> ${tmp}-desc.h
215 ${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${arch}-desc.h
216 sed $sedscript < ${tmp}-desc.c1
> ${tmp}-desc.c
217 ${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${arch}-desc.c
218 sed $sedscript < ${tmp}-opc.h1
> ${tmp}-opc.h
219 ${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${arch}-opc.h
221 rm -f ${tmp}-desc.h1 ${tmp}-desc.c1 ${tmp}-opc.h1
225 echo "`basename $0`: unknown action: ${action}" >&2