blob: e64cfe2be318b996895d6b53f89d8a9132f50051 [file] [log] [blame]
Roberto Vargase92111a2018-05-22 16:05:42 +01001#!/bin/sh
2# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5
6set -e
7
8output=jmptbl.s
Sathees Balyad6839ef2018-10-31 14:05:08 +00009build=.
Roberto Vargase92111a2018-05-22 16:05:42 +010010
11for i
12do
13 case $i in
14 -o)
15 output=$2
16 shift 2
17 ;;
Sathees Balyad6839ef2018-10-31 14:05:08 +000018 -b)
19 build=$2
20 shift 2
21 ;;
Roberto Vargase92111a2018-05-22 16:05:42 +010022 --)
23 shift
24 break
25 ;;
26 -*)
Sathees Balyad6839ef2018-10-31 14:05:08 +000027 echo usage: gentbl.sh [-o output] [-b dir] file ... >&2
Roberto Vargase92111a2018-05-22 16:05:42 +010028 exit 1
29 ;;
30 esac
31done
32
33tmp=`mktemp`
Sathees Balyad6839ef2018-10-31 14:05:08 +000034trap "rm -f $$.tmp" EXIT INT QUIT
Roberto Vargase92111a2018-05-22 16:05:42 +010035rm -f $output
36
Sathees Balyad6839ef2018-10-31 14:05:08 +000037# Pre-process include files
38awk '!/^$/ && !/[:blank:]*#.*/{
39if (NF == 2 && $1 == "include") {
40 while ((getline line < $2) > 0)
41 if (line !~ /^$/ && line !~ /[:blank:]*#.*/)
42 print line
43 close($2)
44} else
45 print
46}' "$@" |
47awk -v OFS="\t" '
48BEGIN{print "#index\tlib\tfunction\t[patch]"}
49{print NR-1, $0}' | tee $build/jmptbl.i |
Roberto Vargase92111a2018-05-22 16:05:42 +010050awk -v OFS="\n" '
51BEGIN {print "\t.text",
52 "\t.globl\tjmptbl",
53 "jmptbl:"}
54 {sub(/[:blank:]*#.*/,"")}
Sathees Balyad6839ef2018-10-31 14:05:08 +000055!/^$/ {if ($3 == "reserved")
56 print "\t.word\t0x0"
57 else
58 print "\tb\t" $3}' > $$.tmp &&
59mv $$.tmp $output