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