aboutsummaryrefslogtreecommitdiff
path: root/extract-function-header.sh
blob: 36676db06a1c165b5cb6b827fb433c9567ffa981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
set -eu

case "$#" in
  0)
    funcname=f
    ;;
  1)
    funcname="$1"
    ;;
  *)
    exit 111
    ;;
esac

cat <<"EOF"
#include <stdint.h>

#undef force_inline
#define force_inline __attribute__((always_inline))

EOF

if [ -z "${BITWIDTH}" ]; then
  BITWIDTH=64
fi

while IFS= read -r line; do
  case "$line" in
    *"λ '"*)
      echo -n "void force_inline $funcname("
      echo -n "uint${BITWIDTH}_t* out"
      echo "$line" | grep -owP -- '\w+\d+' | \
        while IFS= read -r arg; do
          echo -n ", uint${BITWIDTH}_t $arg"
        done
        echo ');'
      break
      ;;
  esac
done