struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / scripts / pic16_update_xinst.sh
blobc8d883db57a2d24392afa6e8a9e4c35f017e8b34
1 #!/bin/sh
3 GPUTILS="$1";
4 PIC16DEVICES="${2:-pic16devices.txt}";
6 usage()
8 echo "Usage: $0 path-to-gputils-sources name-of-pic16devices.txt";
9 echo "";
10 exit 1;
13 if [ ! -f "$GPUTILS/libgputils/gpprocessor.c" ]; then
14 echo "$GPUTILS/libgputils/gpprocessor.c not found.";
15 usage;
16 fi;
18 if [ ! -f "$PIC16DEVICES" ]; then
19 echo "$PIC16DEVICES not found.";
20 usage;
21 fi;
23 BASE=$(readlink -f $(dirname "$0"));
24 SEDSCRIPT="update_xinst.sed";
25 FULL="${PIC16DEVICES}-full";
26 OUTPUT="${PIC16DEVICES}-xinst";
28 grep 'PROC_CLASS_PIC16' "$1/libgputils/gpprocessor.c" \
29 | sed -e '/"p1\w*"/ { s/^.*"p\(1\w*\)".*,\s*\([01]\)\s*}[^}]*$/\1 \2/; p }; d' \
30 | while read p xinst; do \
31 printf '/name\s*'"$p"'\s*$/ {a\\\nXINST '"$xinst"'\n}\n'; \
32 done > "$SEDSCRIPT";
33 perl "$BASE/optimize_pic16devices.pl" -u "$PIC16DEVICES" | \
34 grep -v '^XINST\s*[01]\s*$' | \
35 sed -f "$SEDSCRIPT" > "$FULL";
36 rm -f "$SEDSCRIPT";
37 perl "$BASE/optimize_pic16devices.pl" -o "$FULL" > "$OUTPUT";
38 rm -f "$FULL";
39 if diff -up "$PIC16DEVICES" "$OUTPUT"; then
40 echo "No update required.";
41 rm -f "$OUTPUT";
42 else
43 echo "Update $PIC16DEVICES from $OUTPUT [y/N]? ";
44 read answer;
45 case ${answer:-n} in
46 y|Y|y*|Y*)
47 echo "Updating ...";
48 mv "$OUTPUT" "$PIC16DEVICES";
51 echo "Not updating.";
53 esac;
54 fi;