rulimine/common/gensyms.sh

50 lines
1020 B
Bash
Raw Normal View History

2022-01-21 04:24:36 +03:00
#! /bin/sh
2021-02-25 03:24:54 +03:00
set -e
2022-02-01 10:04:55 +03:00
LC_ALL=C
export LC_ALL
2022-01-21 04:24:36 +03:00
2022-05-21 04:19:57 +03:00
TMP0="$(mktemp)"
2021-08-07 08:26:34 +03:00
cat >"$TMP0" <<EOF
#! /bin/sh
set -e
set -o pipefail 2>/dev/null
EOF
chmod +x "$TMP0"
"$TMP0" && set -o pipefail
rm "$TMP0"
2021-02-25 03:24:54 +03:00
2022-05-21 04:19:57 +03:00
TMP1="$(mktemp)"
TMP2="$(mktemp)"
TMP3="$(mktemp)"
TMP4="$(mktemp)"
trap "rm -f '$TMP1' '$TMP2' '$TMP3' '$TMP4'; trap - EXIT; exit" EXIT INT TERM QUIT HUP
2021-02-25 03:24:54 +03:00
"$FREESTANDING_OBJDUMP" -t "$1" | ( "$SED" '/[[:<:]]d[[:>:]]/d' 2>/dev/null || "$SED" '/\bd\b/d' ) | sort > "$TMP1"
2022-04-20 05:00:00 +03:00
"$GREP" "$4" < "$TMP1" | cut -d' ' -f1 > "$TMP2"
"$GREP" "$4" < "$TMP1" | "$AWK" 'NF{ print $NF }' > "$TMP3"
2021-02-25 03:24:54 +03:00
echo ".section .$2_map" > "$TMP4"
echo ".globl $2_map" >> "$TMP4"
2022-02-01 10:04:55 +03:00
echo "$2_map:" >> "$TMP4"
2021-02-25 03:24:54 +03:00
2022-02-01 10:04:55 +03:00
if [ "$3" = "32" ]; then
paste -d'#' "$TMP2" "$TMP3" | "$SED" 's/^/.long 0x/g;s/$/"/g;s/#/\
.asciz "/g' >> "$TMP4"
echo ".long 0xffffffff" >> "$TMP4"
2022-02-01 10:04:55 +03:00
elif [ "$3" = "64" ]; then
paste -d'#' "$TMP2" "$TMP3" | "$SED" 's/^/.quad 0x/g;s/$/"/g;s/#/\
.asciz "/g' >> "$TMP4"
echo ".quad 0xffffffffffffffff" >> "$TMP4"
2021-04-08 02:15:35 +03:00
fi
mv "$TMP4" "$2.map.S"