author | blanchet |
Thu, 16 Dec 2010 22:43:22 +0100 | |
changeset 41219 | 41f3fdc49ec3 |
parent 41218 | 028449eb1548 |
child 41221 | da6907b67fac |
permissions | -rwxr-xr-x |
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 |
|
41218
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
13 |
use strict; |
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
14 |
use warnings; |
41216 | 15 |
use POSIX; |
16 |
||
41218
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
17 |
my $in_file = $ARGV[$#ARGV - 1]; |
41216 | 18 |
my $out_file = tmpnam(); |
19 |
my $err_file = tmpnam(); |
|
20 |
||
41213
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
21 |
$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
|
22 |
|
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
23 |
RUN: |
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
24 |
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
|
25 |
|
41218
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
26 |
open(ERR_FILE, "<$err_file") || die "Cannot open file \"$err_file\""; |
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
27 |
my @err_lines = <ERR_FILE>; |
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
28 |
close(ERR_FILE); |
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
29 |
print STDERR join("", @err_lines); |
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
30 |
|
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
31 |
if ($code != 0) { |
41219
41f3fdc49ec3
keep track of errors in Z3 input file for debugging purposes
blanchet
parents:
41218
diff
changeset
|
32 |
foreach my $err_line (@err_lines) { |
41f3fdc49ec3
keep track of errors in Z3 input file for debugging purposes
blanchet
parents:
41218
diff
changeset
|
33 |
if ($err_line =~ /[lL]ine ([0-9]+)/) { |
41f3fdc49ec3
keep track of errors in Z3 input file for debugging purposes
blanchet
parents:
41218
diff
changeset
|
34 |
my $line_num = $1; |
41f3fdc49ec3
keep track of errors in Z3 input file for debugging purposes
blanchet
parents:
41218
diff
changeset
|
35 |
|
41213
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
36 |
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
|
37 |
my @in_lines = <IN_FILE>; |
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
38 |
close(IN_FILE); |
41219
41f3fdc49ec3
keep track of errors in Z3 input file for debugging purposes
blanchet
parents:
41218
diff
changeset
|
39 |
|
41f3fdc49ec3
keep track of errors in Z3 input file for debugging purposes
blanchet
parents:
41218
diff
changeset
|
40 |
$err_line =~ s/[\n\r]//g; |
41f3fdc49ec3
keep track of errors in Z3 input file for debugging purposes
blanchet
parents:
41218
diff
changeset
|
41 |
$in_lines[$line_num - 1] = ";;; " . $err_line . " -- " |
41f3fdc49ec3
keep track of errors in Z3 input file for debugging purposes
blanchet
parents:
41218
diff
changeset
|
42 |
. $in_lines[$line_num - 1]; |
41f3fdc49ec3
keep track of errors in Z3 input file for debugging purposes
blanchet
parents:
41218
diff
changeset
|
43 |
|
41213
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
44 |
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
|
45 |
print IN_FILE join ("", @in_lines); |
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
46 |
close(IN_FILE); |
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
47 |
goto RUN; |
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
48 |
} |
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
49 |
} |
ee24717e3fe3
added self-correcting wrapper for Z3 -- see comment in the file for details
blanchet
parents:
diff
changeset
|
50 |
} |
41216 | 51 |
|
41218
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
52 |
open(OUT_FILE, "<$out_file") || die "Cannot open file \"$out_file\""; |
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
53 |
my @out_lines = <OUT_FILE>; |
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
54 |
close(OUT_FILE); |
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
55 |
print join("", @out_lines); |
028449eb1548
better propagation of stdout in case of failure + comply with strict/warnings
blanchet
parents:
41216
diff
changeset
|
56 |
|
41216 | 57 |
unlink($out_file); |
58 |
unlink($err_file); |
|
59 |
exit $code; |