cgen.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #! /bin/sh
  2. # CGEN generic assembler support code.
  3. #
  4. # Copyright (C) 2000-2022 Free Software Foundation, Inc.
  5. #
  6. # This file is part of the GNU opcodes library.
  7. #
  8. # This library is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 3, or (at your option)
  11. # any later version.
  12. #
  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.
  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.,
  20. # 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  21. #
  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:
  26. # cgen.sh action srcdir cgen cgendir cgenflags arch prefix \
  27. # arch-file opc-file options [extrafiles]
  28. #
  29. # ACTION is currently always "opcodes". It exists to be consistent with the
  30. # simulator.
  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:
  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. # We want to behave like make, any error forces us to stop.
  45. set -e
  46. action=$1
  47. srcdir=$2
  48. cgen="$3"
  49. cgendir=$4
  50. cgenflags=$5
  51. arch=$6
  52. prefix=$7
  53. archfile=$8
  54. opcfile=$9
  55. shift ; options=$9
  56. # List of extra files to build.
  57. # Values: opinst (only 1 extra file at present)
  58. shift ; extrafiles=$9
  59. rootdir=${srcdir}/..
  60. # $arch is $6, as passed on the command line.
  61. # $ARCH is the same argument but in all uppercase.
  62. # Both forms are used in this script.
  63. lowercase='abcdefghijklmnopqrstuvwxyz'
  64. uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  65. ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
  66. # Allow parallel makes to run multiple cgen's without colliding.
  67. tmp=tmp-$$
  68. extrafile_args=""
  69. for ef in .. $extrafiles
  70. do
  71. case $ef in
  72. ..) ;;
  73. opinst) extrafile_args="-Q ${tmp}-opinst.c1 $extrafile_args" ;;
  74. esac
  75. done
  76. header="/* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */"
  77. case $action in
  78. opcodes)
  79. # Remove residual working files.
  80. rm -f ${tmp}-desc.h ${tmp}-desc.h1
  81. rm -f ${tmp}-desc.c ${tmp}-desc.c1
  82. rm -f ${tmp}-opc.h ${tmp}-opc.h1
  83. rm -f ${tmp}-opc.c ${tmp}-opc.c1
  84. rm -f ${tmp}-opinst.c ${tmp}-opinst.c1
  85. rm -f ${tmp}-ibld.h ${tmp}-ibld.h1
  86. rm -f ${tmp}-ibld.c ${tmp}-ibld.in1
  87. rm -f ${tmp}-asm.c ${tmp}-asm.in1
  88. rm -f ${tmp}-dis.c ${tmp}-dis.in1
  89. # Run CGEN.
  90. ${cgen} ${cgendir}/cgen-opc.scm \
  91. -s ${cgendir} \
  92. ${cgenflags} \
  93. -f "${options}" \
  94. -m all \
  95. -a ${archfile} \
  96. -OPC ${opcfile} \
  97. -H ${tmp}-desc.h1 \
  98. -C ${tmp}-desc.c1 \
  99. -O ${tmp}-opc.h1 \
  100. -P ${tmp}-opc.c1 \
  101. -L ${tmp}-ibld.in1 \
  102. -A ${tmp}-asm.in1 \
  103. -D ${tmp}-dis.in1 \
  104. ${extrafile_args}
  105. # Customise generated files for the particular architecture.
  106. sed -e "1i$header" \
  107. -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  108. -e 's/[ ][ ]*$//' < ${tmp}-desc.h1 > ${tmp}-desc.h
  109. ${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${prefix}-desc.h
  110. sed -e "1i$header" \
  111. -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  112. -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
  113. < ${tmp}-desc.c1 > ${tmp}-desc.c
  114. ${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${prefix}-desc.c
  115. sed -e "1i$header" \
  116. -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  117. -e 's/[ ][ ]*$//' < ${tmp}-opc.h1 > ${tmp}-opc.h
  118. ${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${prefix}-opc.h
  119. sed -e "1i$header" \
  120. -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  121. -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
  122. < ${tmp}-opc.c1 > ${tmp}-opc.c
  123. ${rootdir}/move-if-change ${tmp}-opc.c ${srcdir}/${prefix}-opc.c
  124. case $extrafiles in
  125. *opinst*)
  126. sed -e "1i$header" \
  127. -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  128. -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
  129. < ${tmp}-opinst.c1 >${tmp}-opinst.c
  130. ${rootdir}/move-if-change ${tmp}-opinst.c ${srcdir}/${prefix}-opinst.c
  131. ;;
  132. esac
  133. cat ${srcdir}/cgen-ibld.in ${tmp}-ibld.in1 | \
  134. sed -e "1i$header" \
  135. -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  136. -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' > ${tmp}-ibld.c
  137. ${rootdir}/move-if-change ${tmp}-ibld.c ${srcdir}/${prefix}-ibld.c
  138. sed -e "/ -- assembler routines/ r ${tmp}-asm.in1" ${srcdir}/cgen-asm.in \
  139. | sed -e "1i$header" \
  140. -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  141. -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
  142. > ${tmp}-asm.c
  143. ${rootdir}/move-if-change ${tmp}-asm.c ${srcdir}/${prefix}-asm.c
  144. sed -e "/ -- disassembler routines/ r ${tmp}-dis.in1" ${srcdir}/cgen-dis.in \
  145. | sed -e "1i$header" \
  146. -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  147. -e "s/@prefix@/${prefix}/" -e 's/[ ][ ]*$//' \
  148. > ${tmp}-dis.c
  149. ${rootdir}/move-if-change ${tmp}-dis.c ${srcdir}/${prefix}-dis.c
  150. # Remove temporary files.
  151. rm -f ${tmp}-desc.h1 ${tmp}-desc.c1
  152. rm -f ${tmp}-opc.h1 ${tmp}-opc.c1
  153. rm -f ${tmp}-opinst.c1
  154. rm -f ${tmp}-ibld.h1 ${tmp}-ibld.in1
  155. rm -f ${tmp}-asm.in1 ${tmp}-dis.in1
  156. ;;
  157. desc)
  158. # For ports that only generate the desc module & opc header.
  159. rm -f ${tmp}-desc.h1 ${tmp}-desc.h
  160. rm -f ${tmp}-desc.c1 ${tmp}-desc.c
  161. rm -f ${tmp}-opc.h1 ${tmp}-opc.h
  162. ${cgen} ${cgendir}/cgen-opc.scm \
  163. -s ${cgendir} \
  164. ${cgenflags} \
  165. -OPC ${opcfile} \
  166. -f "${archflags}" \
  167. -m all \
  168. -a ${archfile} \
  169. -i all \
  170. -H ${tmp}-desc.h1 \
  171. -C ${tmp}-desc.c1 \
  172. -O ${tmp}-opc.h1
  173. sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  174. -e "s/@prefix@/${prefix}/g" \
  175. < ${tmp}-desc.h1 > ${tmp}-desc.h
  176. ${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${arch}-desc.h
  177. sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  178. -e "s/@prefix@/${prefix}/g" \
  179. < ${tmp}-desc.c1 > ${tmp}-desc.c
  180. ${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${arch}-desc.c
  181. sed -e "s/@ARCH@/${ARCH}/g" -e "s/@arch@/${arch}/g" \
  182. -e "s/@prefix@/${prefix}/g" \
  183. < ${tmp}-opc.h1 > ${tmp}-opc.h
  184. ${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${arch}-opc.h
  185. rm -f ${tmp}-desc.h1 ${tmp}-desc.c1 ${tmp}-opc.h1
  186. ;;
  187. *)
  188. echo "$0: bad action: ${action}" >&2
  189. exit 1
  190. ;;
  191. esac
  192. exit 0