aboutsummaryrefslogtreecommitdiff
path: root/extract-function-header.sh
blob: 3535e3c3721492bc31ee633782827d319b3317a6 (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
#!/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

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