src/HOL/Tools/SMT/lib/scripts/z3_wrapper
author blanchet
Thu, 16 Dec 2010 21:02:08 +0100
changeset 41213 ee24717e3fe3
child 41216 5cee84180cd7
permissions -rwxr-xr-x
added self-correcting wrapper for Z3 -- see comment in the file for details
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41213
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
     1
#!/usr/bin/env perl
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
     2
#
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
     3
# Author: Jasmin Blanchette, TU Muenchen
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
     4
#
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
     5
# Invoke Z3 with error detection and correction.
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
     6
# To use this wrapper, set
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
     7
#
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
     8
#     Z3_REAL_SOLVER=/path-to-z3/z3
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
     9
#     Z3_SOLVER=$ISABELLE_HOME/src/HOL/Tools/SMT/lib/scripts/z3_wrapper
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    10
#
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    11
# in your "~/.isabelle/etc/settings" file.
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    12
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    13
my $in_file = @ARGV[$ARGV - 1];
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    14
my $out_file = "/tmp/foo"; # FIXME
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    15
my $err_file = "/tmp/bar"; # FIXME
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    16
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    17
$ENV{'Z3_REAL_SOLVER'} || die "Environment variable \"Z3_REAL_SOLVER\" not set";
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    18
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    19
RUN:
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    20
my $code = system $ENV{'Z3_REAL_SOLVER'} . " " . join(" ", @ARGV) . " >$out_file 2>$err_file";
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    21
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    22
if ($code == 0) {
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    23
  open(OUT_FILE, "<$out_file") || die "Cannot open file \"$out_file\"";
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    24
  my @out_lines = <OUT_FILE>;
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    25
  close(OUT_FILE);
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    26
  print @out_lines;
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    27
} else {
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    28
  open(ERR_FILE, "<$err_file") || die "Cannot open file \"$err_file\"";
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    29
  my @err_lines = <ERR_FILE>;
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    30
  close(ERR_FILE);
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    31
  foreach (@err_lines) {
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    32
    if (m/[lL]ine ([0-9]+)/) {
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    33
      open(IN_FILE, "<$in_file") || die "Cannot open file \"$in_file\"";
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    34
      my @in_lines = <IN_FILE>;
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    35
      close(IN_FILE);
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    36
      delete $in_lines[$1 - 1];
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    37
      open(IN_FILE, ">$in_file") || die "Cannot open file \"$in_file\"";
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    38
      print IN_FILE join ("", @in_lines);
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    39
      close(IN_FILE);
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    40
      goto RUN;
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    41
    }
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    42
  }
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    43
  print STDERR @err_lines;
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    44
  exit $code;
ee24717e3fe3 added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff changeset
    45
}