blob: 08d5f11814a0ad8e64bb74ede1f5d7cc39104e3c [file] [log] [blame]
Elvira Khabirova09294222015-08-04 01:47:02 +03001#!/bin/sh -e
2
3export LC_ALL=C
4
5MPERS_AWK="${0%/*}/mpers.awk"
6ARCH_FLAG=$1
7PARSER_FILE=$2
8
9CC="${CC-gcc}"
Dmitry V. Levin4b08afd2015-12-16 01:26:27 +000010CFLAGS="$CFLAGS -gdwarf-2 -c"
Elvira Khabirova09294222015-08-04 01:47:02 +030011CPP="${CPP-$CC -E}"
12CPPFLAGS="$CPPFLAGS -MM -MG"
13
14VAR_NAME='mpers_target_var'
15BITS_DIR="mpers${ARCH_FLAG}"
16
17mkdir -p ${BITS_DIR}
18set -- $(sed -n \
19 's/^#[[:space:]]*include[[:space:]]\+DEF_MPERS_TYPE(\([^)[:space:]]*\))$/\1/p' \
20 "${PARSER_FILE}")
21for m_type; do
22 f_h="${BITS_DIR}/${m_type}.h"
23 f_c="${BITS_DIR}/${m_type}.c"
24 f_i="${BITS_DIR}/${m_type}.i"
25 f_o="${BITS_DIR}/${m_type}.o"
26 f_d1="${BITS_DIR}/${m_type}.d1"
27 f_d2="${BITS_DIR}/${m_type}.d2"
28 sed -e '
29 /DEF_MPERS_TYPE('"${m_type}"')$/n
30 /DEF_MPERS_TYPE/d
31 /^[[:space:]]*#[[:space:]]*include[[:space:]]\+\"xlat\//d
32 /^#[[:space:]]*include[[:space:]]\+MPERS_DEFS$/ {s//'"${m_type} ${VAR_NAME}"';/;q}
33 ' "${PARSER_FILE}" > "${f_c}"
34 $CPP $CPPFLAGS "${f_c}" > "${f_i}"
35 grep -F -q "${m_type}.h" "${f_i}" ||
36 continue
37 sed -i -e '/DEF_MPERS_TYPE/d' "${f_c}"
38 $CC $CFLAGS $ARCH_FLAG "${f_c}" -o "${f_o}"
39 readelf --debug-dump=info "${f_o}" > "${f_d1}"
40 sed -n '
41 /^[[:space:]]*<1>/,/^[[:space:]]*<1><[^>]\+>: Abbrev Number: 0/!d
42 /^[[:space:]]*<[^>]\+><[^>]\+>: Abbrev Number: 0/d
43 s/^[[:space:]]*<[[:xdigit:]]\+>[[:space:]]\+//
44 s/^[[:space:]]*\(\(<[[:xdigit:]]\+>\)\{2\}\):[[:space:]]\+/\1\n/
45 s/[[:space:]]\+$//
46 p' "${f_d1}" > "${f_d2}"
47 gawk -v VAR_NAME="$VAR_NAME" -v ARCH_FLAG="${ARCH_FLAG#-}" \
48 -f "$MPERS_AWK" "${f_d2}" > "${f_h}"
49done