gen-rust-atomic-helpers.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. ATOMICDIR=$(dirname $0)
  4. . ${ATOMICDIR}/atomic-tbl.sh
  5. #gen_proto_order_variant(meta, pfx, name, sfx, order, atomic, int, arg...)
  6. gen_proto_order_variant()
  7. {
  8. local meta="$1"; shift
  9. local pfx="$1"; shift
  10. local name="$1"; shift
  11. local sfx="$1"; shift
  12. local order="$1"; shift
  13. local atomic="$1"; shift
  14. local int="$1"; shift
  15. local atomicname="${atomic}_${pfx}${name}${sfx}${order}"
  16. local ret="$(gen_ret_type "${meta}" "${int}")"
  17. local params="$(gen_params "${int}" "${atomic}" "$@")"
  18. local args="$(gen_args "$@")"
  19. local retstmt="$(gen_ret_stmt "${meta}")"
  20. cat <<EOF
  21. __rust_helper ${ret}
  22. rust_helper_${atomicname}(${params})
  23. {
  24. ${retstmt}${atomicname}(${args});
  25. }
  26. EOF
  27. }
  28. cat << EOF
  29. // SPDX-License-Identifier: GPL-2.0
  30. // Generated by $0
  31. // DO NOT MODIFY THIS FILE DIRECTLY
  32. /*
  33. * This file provides helpers for the various atomic functions for Rust.
  34. */
  35. #ifndef _RUST_ATOMIC_API_H
  36. #define _RUST_ATOMIC_API_H
  37. #include <linux/atomic.h>
  38. EOF
  39. grep '^[a-z]' "$1" | while read name meta args; do
  40. gen_proto "${meta}" "${name}" "atomic" "int" ${args}
  41. done
  42. grep '^[a-z]' "$1" | while read name meta args; do
  43. gen_proto "${meta}" "${name}" "atomic64" "s64" ${args}
  44. done
  45. cat <<EOF
  46. #endif /* _RUST_ATOMIC_API_H */
  47. EOF