gen-vector-variants.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/sh -e
  2. # Copyright (C) 2018 Ariadne Devos
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # Run this script if you have a lot of untracked files in your tree,
  17. # before pushing to the public repo.
  18. set -e
  19. LC_ALL=C.UTF-8
  20. export LC_ALL
  21. type="$1"
  22. func="$2"
  23. source="$3"
  24. IFS=' '
  25. sizes='2 4 8 16 32 64'
  26. cat <<EOF
  27. #include <sHT/vector.h>
  28. EOF
  29. for size in $sizes; do
  30. cat <<EOF
  31. #if defined(sHT_target_${size}) && (${size} >= sHT_${type}_bytes)
  32. # define sHT_size ${size}
  33. # define sHT_target sHT_target_${size}
  34. # define ${func} ${func}_${size}
  35. # include "${source}"
  36. # undef ${func}
  37. # undef sHT_target
  38. # undef sHT_size
  39. #endif
  40. EOF
  41. done
  42. cat <<EOF
  43. /* musl doesn't allow GNU indirect functions.
  44. Do the portable thing: save a pointer. */
  45. #if 0
  46. EOF
  47. for size in $sizes; do
  48. cat <<EOF
  49. #elif defined(sHT_target_${size}) && (${size} >= sHT_${type}_bytes)
  50. typedef __typeof__(&${func}_${size}) ${func}_type;
  51. EOF
  52. done
  53. cat <<EOF
  54. #else
  55. # error impossible
  56. #endif
  57. static const ${func}_type ${func}_variants[] = {
  58. EOF
  59. for size in $sizes; do
  60. cat <<EOF
  61. #if defined(sHT_target_${size}) && (${size} >= sHT_${type}_bytes)
  62. ${func}_${size},
  63. #endif
  64. EOF
  65. done
  66. cat <<EOF
  67. };
  68. EOF