summaryrefslogtreecommitdiff
path: root/support/scripts/pic16_update_xinst.sh
blob: c8d883db57a2d24392afa6e8a9e4c35f017e8b34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh

GPUTILS="$1";
PIC16DEVICES="${2:-pic16devices.txt}";

usage()
{
  echo "Usage: $0 path-to-gputils-sources name-of-pic16devices.txt";
  echo "";
  exit 1;
}

if [ ! -f "$GPUTILS/libgputils/gpprocessor.c" ]; then
  echo "$GPUTILS/libgputils/gpprocessor.c not found.";
  usage;
fi;

if [ ! -f "$PIC16DEVICES" ]; then
  echo "$PIC16DEVICES not found.";
  usage;
fi;

BASE=$(readlink -f $(dirname "$0"));
SEDSCRIPT="update_xinst.sed";
FULL="${PIC16DEVICES}-full";
OUTPUT="${PIC16DEVICES}-xinst";

grep 'PROC_CLASS_PIC16' "$1/libgputils/gpprocessor.c" \
         | sed -e '/"p1\w*"/ { s/^.*"p\(1\w*\)".*,\s*\([01]\)\s*}[^}]*$/\1 \2/; p }; d' \
         | while read p xinst; do \
                printf '/name\s*'"$p"'\s*$/ {a\\\nXINST       '"$xinst"'\n}\n'; \
           done > "$SEDSCRIPT";
perl "$BASE/optimize_pic16devices.pl" -u "$PIC16DEVICES" | \
         grep -v '^XINST\s*[01]\s*$' | \
         sed -f "$SEDSCRIPT" > "$FULL";
rm -f "$SEDSCRIPT";
perl "$BASE/optimize_pic16devices.pl" -o "$FULL" > "$OUTPUT";
rm -f "$FULL";
if diff -up "$PIC16DEVICES" "$OUTPUT"; then
  echo "No update required.";
  rm -f "$OUTPUT";
else
  echo "Update $PIC16DEVICES from $OUTPUT [y/N]? ";
  read answer;
  case ${answer:-n} in
    y|Y|y*|Y*)
      echo "Updating ...";
      mv "$OUTPUT" "$PIC16DEVICES";
      ;;
    *)
      echo "Not updating.";
      ;;
  esac;
fi;