regdat.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/bin/sh -u
  2. # Register protocol definitions for GDB, the GNU debugger.
  3. # Copyright (C) 2001-2022 Free Software Foundation, Inc.
  4. #
  5. # This file is part of GDB.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. # Format of the input files
  20. read="type entry"
  21. do_read ()
  22. {
  23. type=""
  24. entry=""
  25. while read line
  26. do
  27. if test "${line}" = ""
  28. then
  29. continue
  30. elif test "${line}" = "#" -a "${comment}" = ""
  31. then
  32. continue
  33. elif expr "${line}" : "#" > /dev/null
  34. then
  35. comment="${comment}
  36. ${line}"
  37. else
  38. # The semantics of IFS varies between different SH's. Some
  39. # treat ``::' as three fields while some treat it as just too.
  40. # Work around this by eliminating ``::'' ....
  41. line="`echo "${line}" | sed -e 's/::/: :/g' -e 's/::/: :/g'`"
  42. OFS="${IFS}" ; IFS="[:]"
  43. eval read ${read} <<EOF
  44. ${line}
  45. EOF
  46. IFS="${OFS}"
  47. # .... and then going back through each field and strip out those
  48. # that ended up with just that space character.
  49. for r in ${read}
  50. do
  51. if eval test \"\${${r}}\" = \"\ \"
  52. then
  53. eval ${r}=""
  54. fi
  55. done
  56. break
  57. fi
  58. done
  59. if [ -n "${type}" ]
  60. then
  61. true
  62. else
  63. false
  64. fi
  65. }
  66. if test ! -r $1; then
  67. echo "$0: Could not open $1." 1>&2
  68. exit 1
  69. fi
  70. copyright ()
  71. {
  72. cat <<EOF
  73. /* *INDENT-OFF* */ /* THIS FILE IS GENERATED */
  74. /* A register protocol for GDB, the GNU debugger.
  75. Copyright (C) 2001-2013 Free Software Foundation, Inc.
  76. This file is part of GDB.
  77. This program is free software; you can redistribute it and/or modify
  78. it under the terms of the GNU General Public License as published by
  79. the Free Software Foundation; either version 3 of the License, or
  80. (at your option) any later version.
  81. This program is distributed in the hope that it will be useful,
  82. but WITHOUT ANY WARRANTY; without even the implied warranty of
  83. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  84. GNU General Public License for more details.
  85. You should have received a copy of the GNU General Public License
  86. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  87. /* This file was created with the aid of \`\`regdat.sh'' and \`\`$1''. */
  88. EOF
  89. }
  90. exec > new-$2
  91. copyright $1
  92. echo '#include "server.h"'
  93. echo '#include "regdef.h"'
  94. echo '#include "tdesc.h"'
  95. echo
  96. offset=0
  97. i=0
  98. name=x
  99. xmltarget=x
  100. xmlarch=x
  101. xmlosabi=x
  102. expedite=x
  103. feature=x
  104. exec < $1
  105. while do_read
  106. do
  107. if test "${type}" = "name"; then
  108. name="${entry}"
  109. echo "const struct target_desc *tdesc_${name};"
  110. echo ""
  111. # This is necessary for -Wmissing-declarations.
  112. echo "void init_registers_${name} (void);"
  113. echo "void"
  114. echo "init_registers_${name} (void)"
  115. echo "{"
  116. echo " static struct target_desc tdesc_${name}_s;"
  117. echo " struct target_desc *result = &tdesc_${name}_s;"
  118. echo " struct tdesc_feature *feature = tdesc_create_feature (result, \"${name}\");"
  119. continue
  120. elif test "${type}" = "xmltarget"; then
  121. xmltarget="${entry}"
  122. continue
  123. elif test "${type}" = "xmlarch"; then
  124. xmlarch="${entry}"
  125. continue
  126. elif test "${type}" = "osabi"; then
  127. xmlosabi="${entry}"
  128. continue
  129. elif test "${type}" = "expedite"; then
  130. expedite="${entry}"
  131. continue
  132. elif test "${type}" = "feature"; then
  133. feature="${entry}"
  134. continue
  135. elif test "${name}" = x; then
  136. echo "$0: $1 does not specify \`\`name''." 1>&2
  137. exit 1
  138. else
  139. echo " tdesc_create_reg (feature, \"${entry}\","
  140. echo " 0, 0, NULL, ${type}, NULL);"
  141. offset=`expr ${offset} + ${type}`
  142. i=`expr $i + 1`
  143. fi
  144. done
  145. echo
  146. echo "static const char *expedite_regs_${name}[] = { \"`echo ${expedite} | sed 's/,/", "/g'`\", 0 };"
  147. echo "#ifndef IN_PROCESS_AGENT"
  148. if test "${feature}" != x; then
  149. echo "static const char *xmltarget_${name} = 0;"
  150. elif test "${xmltarget}" = x; then
  151. if test "${xmlarch}" = x && test "${xmlosabi}" = x; then
  152. echo "static const char *xmltarget_${name} = 0;"
  153. else
  154. echo "static const char *xmltarget_${name} = \"@<target>\\"
  155. if test "${xmlarch}" != x; then
  156. echo "<architecture>${xmlarch}</architecture>\\"
  157. fi
  158. if test "${xmlosabi}" != x; then
  159. echo "<osabi>${xmlosabi}</osabi>\\"
  160. fi
  161. echo "</target>\";"
  162. fi
  163. else
  164. echo "static const char *xmltarget_${name} = \"${xmltarget}\";"
  165. fi
  166. echo
  167. cat <<EOF
  168. result->xmltarget = xmltarget_${name};
  169. #endif
  170. init_target_desc (result, expedite_regs_${name});
  171. tdesc_${name} = result;
  172. }
  173. EOF
  174. # close things off
  175. exec 1>&2
  176. mv -- "new-$2" "$2"