Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 1 | #!/bin/sh -e |
Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com> |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions |
| 8 | # are met: |
| 9 | # 1. Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # 2. Redistributions in binary form must reproduce the above copyright |
| 12 | # notice, this list of conditions and the following disclaimer in the |
| 13 | # documentation and/or other materials provided with the distribution. |
| 14 | # 3. The name of the author may not be used to endorse or promote products |
| 15 | # derived from this software without specific prior written permission. |
| 16 | # |
| 17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 27 | |
| 28 | export LC_ALL=C |
| 29 | |
| 30 | MPERS_AWK="${0%/*}/mpers.awk" |
| 31 | ARCH_FLAG=$1 |
| 32 | PARSER_FILE=$2 |
| 33 | |
| 34 | CC="${CC-gcc}" |
Dmitry V. Levin | 4b08afd | 2015-12-16 01:26:27 +0000 | [diff] [blame] | 35 | CFLAGS="$CFLAGS -gdwarf-2 -c" |
Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 36 | CPP="${CPP-$CC -E}" |
| 37 | CPPFLAGS="$CPPFLAGS -MM -MG" |
| 38 | |
| 39 | VAR_NAME='mpers_target_var' |
| 40 | BITS_DIR="mpers${ARCH_FLAG}" |
| 41 | |
| 42 | mkdir -p ${BITS_DIR} |
Dmitry V. Levin | 469fd10 | 2016-07-28 16:51:58 +0000 | [diff] [blame] | 43 | set -- $(sed -r -n \ |
| 44 | 's/^#[[:space:]]*include[[:space:]]+DEF_MPERS_TYPE\(([^)[:space:]]*)\)$/\1/p' \ |
Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 45 | "${PARSER_FILE}") |
| 46 | for m_type; do |
| 47 | f_h="${BITS_DIR}/${m_type}.h" |
| 48 | f_c="${BITS_DIR}/${m_type}.c" |
| 49 | f_i="${BITS_DIR}/${m_type}.i" |
| 50 | f_o="${BITS_DIR}/${m_type}.o" |
| 51 | f_d1="${BITS_DIR}/${m_type}.d1" |
| 52 | f_d2="${BITS_DIR}/${m_type}.d2" |
| 53 | sed -e ' |
| 54 | /DEF_MPERS_TYPE('"${m_type}"')$/n |
| 55 | /DEF_MPERS_TYPE/d |
Dmitry V. Levin | 469fd10 | 2016-07-28 16:51:58 +0000 | [diff] [blame] | 56 | /^[[:space:]]*#[[:space:]]*include[[:space:]]*"xlat\//d |
| 57 | /^#[[:space:]]*include[[:space:]][[:space:]]*MPERS_DEFS$/ {s//'"${m_type} ${VAR_NAME}"';/;q} |
Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 58 | ' "${PARSER_FILE}" > "${f_c}" |
| 59 | $CPP $CPPFLAGS "${f_c}" > "${f_i}" |
| 60 | grep -F -q "${m_type}.h" "${f_i}" || |
| 61 | continue |
| 62 | sed -i -e '/DEF_MPERS_TYPE/d' "${f_c}" |
| 63 | $CC $CFLAGS $ARCH_FLAG "${f_c}" -o "${f_o}" |
| 64 | readelf --debug-dump=info "${f_o}" > "${f_d1}" |
Dmitry V. Levin | 469fd10 | 2016-07-28 16:51:58 +0000 | [diff] [blame] | 65 | sed -r -n ' |
| 66 | /^[[:space:]]*<1>/,/^[[:space:]]*<1><[^>]+>: Abbrev Number: 0/!d |
| 67 | /^[[:space:]]*<[^>]*><[^>]*>: Abbrev Number: 0/d |
| 68 | s/^[[:space:]]*<[[:xdigit:]]+>[[:space:]]+// |
| 69 | s/^[[:space:]]*((<[[:xdigit:]]+>){2}):[[:space:]]+/\1\n/ |
| 70 | s/[[:space:]]+$// |
Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 71 | p' "${f_d1}" > "${f_d2}" |
| 72 | gawk -v VAR_NAME="$VAR_NAME" -v ARCH_FLAG="${ARCH_FLAG#-}" \ |
| 73 | -f "$MPERS_AWK" "${f_d2}" > "${f_h}" |
| 74 | done |