summaryrefslogtreecommitdiffstats
path: root/src/arch-gperf-generate
blob: 9e6c0006a885e1792cc4674a64e45d80d9db811e (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
#!/bin/bash

# NOTE: changes to the arch_syscall_table struct in syscalls.h will affect
#       this script/gperf - BEWARE!

###
# helper functions

function exit_usage() {
	echo "usage: $0 <syscall_csv_file> <gperf_template>"
	exit 1
}

###
# main

# sanity check
[[ ! -r "$1" || ! -r "$2" ]] && exit_usage
sys_csv=$1
gperf_tmpl=$2

sys_csv_tmp=$(mktemp -t generate_syscalls_XXXXXX)

# filter and prepare the syscall csv file
cat $sys_csv | grep -v '^#' | nl -ba -s, -v0 | \
    sed -e 's/^[[:space:]]\+\([0-9]\+\),\([^,]\+\),\(.*\)/\2,\1,\3/' \
        -e ':repeat; {s|\([^,]\+\)\(.*\)[^_]PNR|\1\2,__PNR_\1|g;}; t repeat' \
         > $sys_csv_tmp
[[ $? -ne 0 ]] && exit 1

# create the gperf file
sed -e "/@@SYSCALLS_TABLE@@/r $sys_csv_tmp" \
    -e '/@@SYSCALLS_TABLE@@/d' \
    $gperf_tmpl > syscalls.perf
[[ $? -ne 0 ]] && exit 1

# cleanup
rm -f $sys_csv_tmp

exit 0