| author | krauss |
| Mon, 21 Mar 2011 12:43:23 +0100 | |
| changeset 42033 | 60350051ef93 |
| parent 41361 | d1e4a20911cb |
| child 42034 | a77df5241959 |
| permissions | -rw-r--r-- |
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
1 |
# |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
2 |
# Author: Jasmin Blanchette and Sascha Boehme |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
3 |
# |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
4 |
# Testing tool for automated proof tools. |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
5 |
# |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
6 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
7 |
use File::Basename; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
8 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
9 |
# environment |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
10 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
11 |
my $isabelle_home = $ENV{'ISABELLE_HOME'};
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
12 |
my $mirabelle_home = $ENV{'MIRABELLE_HOME'};
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
13 |
my $mirabelle_logic = $ENV{'MIRABELLE_LOGIC'};
|
|
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
14 |
my $mirabelle_theory = $ENV{'MIRABELLE_THEORY'};
|
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
15 |
my $output_path = $ENV{'MIRABELLE_OUTPUT_PATH'};
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
16 |
my $timeout = $ENV{'MIRABELLE_TIMEOUT'};
|
| 32521 | 17 |
my $be_quiet = $ENV{'MIRABELLE_QUIET'};
|
18 |
my $actions = $ENV{'MIRABELLE_ACTIONS'};
|
|
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
19 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
20 |
my $mirabelle_thy = $mirabelle_home . "/Mirabelle"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
21 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
22 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
23 |
# arguments |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
24 |
|
| 32521 | 25 |
my $thy_file = $ARGV[0]; |
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
26 |
my $start_line = "0"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
27 |
my $end_line = "~1"; |
|
32454
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32434
diff
changeset
|
28 |
if ($thy_file =~ /^(.*)\[([0-9]+)\:(~?[0-9]+)\]$/) {
|
|
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32434
diff
changeset
|
29 |
$thy_file = $1; |
|
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32434
diff
changeset
|
30 |
$start_line = $2; |
|
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32434
diff
changeset
|
31 |
$end_line = $3; |
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
32 |
} |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
33 |
my ($thy_name, $path, $ext) = fileparse($thy_file, ".thy"); |
|
42033
60350051ef93
mirabelle: create modified theory file in original location, to ensure that its dependencies can be found (cf. aa8dce9ab8a9)
krauss
parents:
41361
diff
changeset
|
34 |
my $rand_suffix = map { ('a'..'z')[rand(26)] } 1 .. 10;
|
|
60350051ef93
mirabelle: create modified theory file in original location, to ensure that its dependencies can be found (cf. aa8dce9ab8a9)
krauss
parents:
41361
diff
changeset
|
35 |
my $new_thy_name = $thy_name . "_Mirabelle_" . $rand_suffix; |
|
60350051ef93
mirabelle: create modified theory file in original location, to ensure that its dependencies can be found (cf. aa8dce9ab8a9)
krauss
parents:
41361
diff
changeset
|
36 |
my $new_thy_file = $path . "/" . $new_thy_name . $ext; |
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
37 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
38 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
39 |
# setup |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
40 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
41 |
my $setup_thy_name = $thy_name . "_Setup"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
42 |
my $setup_file = $output_path . "/" . $setup_thy_name . ".thy"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
43 |
my $log_file = $output_path . "/" . $thy_name . ".log"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
44 |
|
|
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
45 |
my @action_files; |
| 32396 | 46 |
my @action_names; |
|
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
47 |
foreach (split(/:/, $actions)) {
|
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
48 |
if (m/([^[]*)/) {
|
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
49 |
push @action_files, "\"$mirabelle_home/Tools/mirabelle_$1.ML\""; |
| 32396 | 50 |
push @action_names, $1; |
|
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
51 |
} |
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
52 |
} |
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
53 |
my $tools = ""; |
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
54 |
if ($#action_files >= 0) {
|
| 38895 | 55 |
# uniquify |
56 |
my $s = join ("\n", @action_files);
|
|
57 |
my @action_files = split(/\n/, $s . "\n" . $s); |
|
58 |
%action_files = sort(@action_files); |
|
59 |
$tools = "uses " . join(" ", sort(keys(%action_files)));
|
|
|
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
60 |
} |
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
61 |
|
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
62 |
open(SETUP_FILE, ">$setup_file") || die "Could not create file '$setup_file'"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
63 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
64 |
print SETUP_FILE <<END; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
65 |
theory "$setup_thy_name" |
|
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
66 |
imports "$mirabelle_thy" "$mirabelle_theory" |
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
67 |
$tools |
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
68 |
begin |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
69 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
70 |
setup {*
|
| 37378 | 71 |
Config.put_global Mirabelle.logfile "$log_file" #> |
72 |
Config.put_global Mirabelle.timeout $timeout #> |
|
73 |
Config.put_global Mirabelle.start_line $start_line #> |
|
74 |
Config.put_global Mirabelle.end_line $end_line |
|
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
75 |
*} |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
76 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
77 |
END |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
78 |
|
|
38898
a243f8883e8e
execute actions in same order as specified on command line
blanchet
parents:
38895
diff
changeset
|
79 |
foreach (reverse(split(/:/, $actions))) {
|
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
80 |
if (m/([^[]*)(?:\[(.*)\])?/) {
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
81 |
my ($name, $settings_str) = ($1, $2 || ""); |
|
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
82 |
$name =~ s/^([a-z])/\U$1/; |
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
32383
diff
changeset
|
83 |
print SETUP_FILE "setup {* Mirabelle_$name.invoke [";
|
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
84 |
my $sep = ""; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
85 |
foreach (split(/,/, $settings_str)) {
|
|
41361
d1e4a20911cb
better parsing of options, in case the value has '='
blanchet
parents:
38898
diff
changeset
|
86 |
if (m/\s*([^=]*)\s*=\s*(.*)\s*/) {
|
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
87 |
print SETUP_FILE "$sep(\"$1\", \"$2\")"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
88 |
$sep = ", "; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
89 |
} |
|
32522
1b70db55c811
Mirabelle: command-line action options may either be key=value or just key
boehmes
parents:
32521
diff
changeset
|
90 |
elsif (m/\s*(.*)\s*/) {
|
|
1b70db55c811
Mirabelle: command-line action options may either be key=value or just key
boehmes
parents:
32521
diff
changeset
|
91 |
print SETUP_FILE "$sep(\"$1\", \"\")"; |
|
1b70db55c811
Mirabelle: command-line action options may either be key=value or just key
boehmes
parents:
32521
diff
changeset
|
92 |
$sep = ", "; |
|
1b70db55c811
Mirabelle: command-line action options may either be key=value or just key
boehmes
parents:
32521
diff
changeset
|
93 |
} |
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
94 |
} |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
95 |
print SETUP_FILE "] *}\n"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
96 |
} |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
97 |
} |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
98 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
99 |
print SETUP_FILE "\nend"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
100 |
close SETUP_FILE; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
101 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
102 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
103 |
# modify target theory file |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
104 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
105 |
open(OLD_FILE, "<$thy_file") || die "Cannot open file '$thy_file'"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
106 |
my @lines = <OLD_FILE>; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
107 |
close(OLD_FILE); |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
108 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
109 |
my $thy_text = join("", @lines);
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
110 |
my $old_len = length($thy_text); |
| 32395 | 111 |
$thy_text =~ s/(theory\s+)\"?$thy_name\"?/$1"$new_thy_name"/g; |
|
42033
60350051ef93
mirabelle: create modified theory file in original location, to ensure that its dependencies can be found (cf. aa8dce9ab8a9)
krauss
parents:
41361
diff
changeset
|
112 |
$thy_text =~ s/(imports)(\s+)/$1 "$output_path\/$setup_thy_name"$2/g; |
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
113 |
die "No 'imports' found" if length($thy_text) == $old_len; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
114 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
115 |
open(NEW_FILE, ">$new_thy_file") || die "Cannot create file '$new_thy_file'"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
116 |
print NEW_FILE $thy_text; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
117 |
close(NEW_FILE); |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
118 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
119 |
my $root_file = "$output_path/ROOT_$thy_name.ML"; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
120 |
open(ROOT_FILE, ">$root_file") || die "Cannot create file '$root_file'"; |
|
42033
60350051ef93
mirabelle: create modified theory file in original location, to ensure that its dependencies can be found (cf. aa8dce9ab8a9)
krauss
parents:
41361
diff
changeset
|
121 |
print ROOT_FILE "use_thy \"$path/$new_thy_name\";\n"; |
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
122 |
close(ROOT_FILE); |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
123 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
124 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
125 |
# run isabelle |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
126 |
|
| 32396 | 127 |
open(LOG_FILE, ">$log_file"); |
128 |
print LOG_FILE "Run of $new_thy_file with:\n"; |
|
129 |
foreach $name (@action_names) {
|
|
130 |
print LOG_FILE " $name\n"; |
|
131 |
} |
|
132 |
close(LOG_FILE); |
|
133 |
||
| 32521 | 134 |
my $quiet = ""; |
135 |
if (defined $be_quiet and $be_quiet ne "") {
|
|
136 |
$quiet = " > /dev/null 2>&1"; |
|
137 |
} |
|
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
138 |
|
| 32521 | 139 |
print "Mirabelle: $thy_file\n" if ($quiet ne ""); |
|
32498
1132c7c13f36
Mirabelle: actions are responsible for handling exceptions,
boehmes
parents:
32496
diff
changeset
|
140 |
|
| 32521 | 141 |
my $result = system "\"$ENV{'ISABELLE_PROCESS'}\" " .
|
142 |
"-e 'use \"$root_file\";' -q $mirabelle_logic" . $quiet; |
|
143 |
||
144 |
print "Finished: $thy_file\n" if ($quiet ne ""); |
|
|
32498
1132c7c13f36
Mirabelle: actions are responsible for handling exceptions,
boehmes
parents:
32496
diff
changeset
|
145 |
|
|
1132c7c13f36
Mirabelle: actions are responsible for handling exceptions,
boehmes
parents:
32496
diff
changeset
|
146 |
|
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
147 |
# cleanup |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
148 |
|
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
149 |
unlink $root_file; |
|
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
150 |
unlink $setup_file; |
|
42033
60350051ef93
mirabelle: create modified theory file in original location, to ensure that its dependencies can be found (cf. aa8dce9ab8a9)
krauss
parents:
41361
diff
changeset
|
151 |
unlink $new_thy_file; |
|
32382
98674ac811c4
Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff
changeset
|
152 |
|
|
32498
1132c7c13f36
Mirabelle: actions are responsible for handling exceptions,
boehmes
parents:
32496
diff
changeset
|
153 |
exit $result; |