Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | |
| 6 | set -e |
| 7 | |
| 8 | output=jmptbl.s |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 9 | build=. |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 10 | |
| 11 | for i |
| 12 | do |
| 13 | case $i in |
| 14 | -o) |
| 15 | output=$2 |
| 16 | shift 2 |
| 17 | ;; |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 18 | -b) |
| 19 | build=$2 |
| 20 | shift 2 |
| 21 | ;; |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 22 | --) |
| 23 | shift |
| 24 | break |
| 25 | ;; |
| 26 | -*) |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 27 | echo usage: gentbl.sh [-o output] [-b dir] file ... >&2 |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 28 | exit 1 |
| 29 | ;; |
| 30 | esac |
| 31 | done |
| 32 | |
| 33 | tmp=`mktemp` |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 34 | trap "rm -f $$.tmp" EXIT INT QUIT |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 35 | rm -f $output |
| 36 | |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 37 | # Pre-process include files |
| 38 | awk '!/^$/ && !/[:blank:]*#.*/{ |
| 39 | if (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 | }' "$@" | |
| 47 | awk -v OFS="\t" ' |
| 48 | BEGIN{print "#index\tlib\tfunction\t[patch]"} |
| 49 | {print NR-1, $0}' | tee $build/jmptbl.i | |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 50 | awk -v OFS="\n" ' |
| 51 | BEGIN {print "\t.text", |
| 52 | "\t.globl\tjmptbl", |
| 53 | "jmptbl:"} |
| 54 | {sub(/[:blank:]*#.*/,"")} |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 55 | !/^$/ {if ($3 == "reserved") |
| 56 | print "\t.word\t0x0" |
| 57 | else |
| 58 | print "\tb\t" $3}' > $$.tmp && |
| 59 | mv $$.tmp $output |