lib/Tools/codegen
author haftmann
Thu, 12 Mar 2009 18:01:25 +0100
changeset 30494 c150e6fa4e0d
parent 30242 aea5d7fa7ef5
permissions -rwxr-xr-x
consider exit status of code generation direcitve
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21884
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
     1
#!/usr/bin/env bash
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
     2
#
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
     3
# Author: Florian Haftmann, TUM
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
     4
#
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
     5
# DESCRIPTION: issue code generation from shell
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
     6
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
     7
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
     8
## diagnostics
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
     9
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    10
PRG="$(basename "$0")"
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    11
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    12
function usage()
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    13
{
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    14
  echo
28650
a7ba12e0d3b7 tuned usage line;
wenzelm
parents: 28502
diff changeset
    15
  echo "Usage: isabelle $PRG IMAGE THY CMD"
21884
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    16
  echo
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    17
  echo "  Issues code generation using image IMAGE,"
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    18
  echo "  theory THY,"
25611
c0deb7307732 isatool codegen now returns exit value
haftmann
parents: 25451
diff changeset
    19
  echo "  with Isar command 'export_code CMD'"
21884
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    20
  echo
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    21
  exit 1
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    22
}
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    23
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    24
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    25
## process command line
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    26
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    27
[ "$#" -lt 2 -o "$1" = "-?" ] && usage
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    28
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    29
IMAGE="$1"; shift
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    30
THY="$1"; shift
25611
c0deb7307732 isatool codegen now returns exit value
haftmann
parents: 25451
diff changeset
    31
CMD="$1"
21884
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    32
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    33
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    34
## main
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    35
30494
c150e6fa4e0d consider exit status of code generation direcitve
haftmann
parents: 30242
diff changeset
    36
CODE_CMD=$(echo $CMD | perl -pe 's/\\/\\\\/g; s/"/\\\"/g')
c150e6fa4e0d consider exit status of code generation direcitve
haftmann
parents: 30242
diff changeset
    37
CTXT_CMD="ML_Context.eval_in (SOME (ProofContext.init (theory \"HOL\"))) false Position.none \"Code_Target.shell_command thyname cmd\";"
c150e6fa4e0d consider exit status of code generation direcitve
haftmann
parents: 30242
diff changeset
    38
FULL_CMD="val thyname = \"$THY\"; val cmd = \"$CODE_CMD\"; $CTXT_CMD"
21884
7df02627898e added isatool codegen
haftmann
parents:
diff changeset
    39
30494
c150e6fa4e0d consider exit status of code generation direcitve
haftmann
parents: 30242
diff changeset
    40
"$ISABELLE" -q -e "$FULL_CMD" "$IMAGE" || exit 1