genopt.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/bin/sh
  2. # Generate mips-tables.opt from the list of CPUs in mips-cpus.def.
  3. # Copyright (C) 2011-2015 Free Software Foundation, Inc.
  4. #
  5. # This file is part of GCC.
  6. #
  7. # GCC 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, or (at your option)
  10. # any later version.
  11. #
  12. # GCC 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 GCC; see the file COPYING3. If not see
  19. # <http://www.gnu.org/licenses/>.
  20. cat <<EOF
  21. ; -*- buffer-read-only: t -*-
  22. ; Generated automatically by genopt.sh from mips-cpus.def.
  23. ; Copyright (C) 2011-2015 Free Software Foundation, Inc.
  24. ;
  25. ; This file is part of GCC.
  26. ;
  27. ; GCC is free software; you can redistribute it and/or modify it under
  28. ; the terms of the GNU General Public License as published by the Free
  29. ; Software Foundation; either version 3, or (at your option) any later
  30. ; version.
  31. ;
  32. ; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  33. ; WARRANTY; without even the implied warranty of MERCHANTABILITY or
  34. ; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  35. ; for more details.
  36. ;
  37. ; You should have received a copy of the GNU General Public License
  38. ; along with GCC; see the file COPYING3. If not see
  39. ; <http://www.gnu.org/licenses/>.
  40. Enum
  41. Name(mips_arch_opt_value) Type(int)
  42. Known MIPS CPUs (for use with the -march= and -mtune= options):
  43. Enum
  44. Name(mips_mips_opt_value) Type(int)
  45. Known MIPS ISA levels (for use with the -mips option):
  46. EnumValue
  47. Enum(mips_arch_opt_value) String(from-abi) Value(MIPS_ARCH_OPTION_FROM_ABI)
  48. EnumValue
  49. Enum(mips_arch_opt_value) String(native) Value(MIPS_ARCH_OPTION_NATIVE) DriverOnly
  50. EOF
  51. awk -F'[(, ]+' '
  52. BEGIN {
  53. value = 0
  54. }
  55. # Write an entry for a single string accepted as a -march= argument.
  56. function write_one_arch_value(name, value, flags)
  57. {
  58. print "EnumValue"
  59. print "Enum(mips_arch_opt_value) String(" name ") Value(" value ")" flags
  60. print ""
  61. if (name ~ "^mips") {
  62. sub("^mips", "", name)
  63. print "EnumValue"
  64. print "Enum(mips_mips_opt_value) String(" name ") Value(" value ")"
  65. print ""
  66. }
  67. }
  68. # The logic for matching CPU name variants should be the same as in GAS.
  69. # Write an entry for a single string accepted as a -march= argument,
  70. # plus any variant with a final "000" replaced by "k".
  71. function write_arch_value_maybe_k(name, value, flags)
  72. {
  73. write_one_arch_value(name, value, flags)
  74. if (name ~ "000$") {
  75. sub("000$", "k", name)
  76. write_one_arch_value(name, value, "")
  77. }
  78. }
  79. # Write all the entries for a -march= argument. In addition to
  80. # replacement of a final "000" with "k", an argument starting with
  81. # "vr", "rm" or "r" followed by a number, or just a plain number,
  82. # matches a plain number or "r" followed by a plain number.
  83. function write_all_arch_values(name, value)
  84. {
  85. write_arch_value_maybe_k(name, value, " Canonical")
  86. cname = name
  87. if (cname ~ "^vr") {
  88. sub("^vr", "", cname)
  89. } else if (cname ~ "^rm") {
  90. sub("^rm", "", cname)
  91. } else if (cname ~ "^r") {
  92. sub("^r", "", cname)
  93. }
  94. if (cname ~ "^[0-9]") {
  95. if (cname != name)
  96. write_arch_value_maybe_k(cname, value, "")
  97. rname = "r" cname
  98. if (rname != name)
  99. write_arch_value_maybe_k(rname, value, "")
  100. }
  101. }
  102. /^MIPS_CPU/ {
  103. name = $2
  104. gsub("\"", "", name)
  105. write_all_arch_values(name, value)
  106. value++
  107. }' $1/mips-cpus.def