gen-atomic-long.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. ATOMICDIR=$(dirname $0)
  4. . ${ATOMICDIR}/atomic-tbl.sh
  5. #gen_cast(arg, int, atomic)
  6. gen_cast()
  7. {
  8. local arg="$1"; shift
  9. local int="$1"; shift
  10. local atomic="$1"; shift
  11. [ "${arg%%:*}" = "p" ] || return
  12. printf "($(gen_param_type "${arg}" "${int}" "${atomic}"))"
  13. }
  14. #gen_args_cast(int, atomic, arg...)
  15. gen_args_cast()
  16. {
  17. local int="$1"; shift
  18. local atomic="$1"; shift
  19. while [ "$#" -gt 0 ]; do
  20. local cast="$(gen_cast "$1" "${int}" "${atomic}")"
  21. local arg="$(gen_param_name "$1")"
  22. printf "${cast}${arg}"
  23. [ "$#" -gt 1 ] && printf ", "
  24. shift;
  25. done
  26. }
  27. #gen_proto_order_variant(meta, pfx, name, sfx, order, arg...)
  28. gen_proto_order_variant()
  29. {
  30. local meta="$1"; shift
  31. local pfx="$1"; shift
  32. local name="$1"; shift
  33. local sfx="$1"; shift
  34. local order="$1"; shift
  35. local atomicname="${pfx}${name}${sfx}${order}"
  36. local ret="$(gen_ret_type "${meta}" "long")"
  37. local params="$(gen_params "long" "atomic_long" "$@")"
  38. local argscast_32="$(gen_args_cast "int" "atomic" "$@")"
  39. local argscast_64="$(gen_args_cast "s64" "atomic64" "$@")"
  40. local retstmt="$(gen_ret_stmt "${meta}")"
  41. gen_kerneldoc "raw_" "${meta}" "${pfx}" "${name}" "${sfx}" "${order}" "atomic_long" "long" "$@"
  42. cat <<EOF
  43. static __always_inline ${ret}
  44. raw_atomic_long_${atomicname}(${params})
  45. {
  46. #ifdef CONFIG_64BIT
  47. ${retstmt}raw_atomic64_${atomicname}(${argscast_64});
  48. #else
  49. ${retstmt}raw_atomic_${atomicname}(${argscast_32});
  50. #endif
  51. }
  52. EOF
  53. }
  54. cat << EOF
  55. // SPDX-License-Identifier: GPL-2.0
  56. // Generated by $0
  57. // DO NOT MODIFY THIS FILE DIRECTLY
  58. #ifndef _LINUX_ATOMIC_LONG_H
  59. #define _LINUX_ATOMIC_LONG_H
  60. #include <linux/compiler.h>
  61. #include <asm/types.h>
  62. #ifdef CONFIG_64BIT
  63. typedef atomic64_t atomic_long_t;
  64. #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
  65. #define atomic_long_cond_read_acquire atomic64_cond_read_acquire
  66. #define atomic_long_cond_read_relaxed atomic64_cond_read_relaxed
  67. #else
  68. typedef atomic_t atomic_long_t;
  69. #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
  70. #define atomic_long_cond_read_acquire atomic_cond_read_acquire
  71. #define atomic_long_cond_read_relaxed atomic_cond_read_relaxed
  72. #endif
  73. EOF
  74. grep '^[a-z]' "$1" | while read name meta args; do
  75. gen_proto "${meta}" "${name}" ${args}
  76. done
  77. cat <<EOF
  78. #endif /* _LINUX_ATOMIC_LONG_H */
  79. EOF