src/HOL/Tools/Mirabelle/lib/scripts/mirabelle.pl
author boehmes
Fri, 21 Aug 2009 13:21:19 +0200
changeset 32385 594890623c46
parent 32383 521065a499c6
child 32395 9692b0714295
permissions -rw-r--r--
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
     1 #
     2 # Author: Jasmin Blanchette and Sascha Boehme
     3 #
     4 # Testing tool for automated proof tools.
     5 #
     6 
     7 use File::Basename;
     8 
     9 # environment
    10 
    11 my $isabelle_home = $ENV{'ISABELLE_HOME'};
    12 my $mirabelle_home = $ENV{'MIRABELLE_HOME'};
    13 my $mirabelle_logic = $ENV{'MIRABELLE_LOGIC'};
    14 my $mirabelle_theory = $ENV{'MIRABELLE_THEORY'};
    15 my $output_path = $ENV{'MIRABELLE_OUTPUT_PATH'};
    16 my $verbose = $ENV{'MIRABELLE_VERBOSE'};
    17 my $timeout = $ENV{'MIRABELLE_TIMEOUT'};
    18 
    19 my $mirabelle_thy = $mirabelle_home . "/Mirabelle";
    20 
    21 
    22 # arguments
    23 
    24 my $actions = $ARGV[0];
    25 
    26 my $thy_file = $ARGV[1];
    27 my $start_line = "0";
    28 my $end_line = "~1";
    29 if ($thy_file =~ /^(.*)\[([0-9]+)\:(~?[0-9]+)\]$/) { # FIXME
    30   my $thy_file = $1;
    31   my $start_line = $2;
    32   my $end_line = $3;
    33 }
    34 my ($thy_name, $path, $ext) = fileparse($thy_file, ".thy");
    35 my $new_thy_name = $thy_name . "_Mirabelle";
    36 my $new_thy_file = $output_path . "/" . $new_thy_name . $ext;
    37 
    38 
    39 # setup
    40 
    41 my $setup_thy_name = $thy_name . "_Setup";
    42 my $setup_file = $output_path . "/" . $setup_thy_name . ".thy";
    43 my $log_file = $output_path . "/" . $thy_name . ".log";
    44 
    45 my @action_files;
    46 foreach (split(/:/, $actions)) {
    47   if (m/([^[]*)/) {
    48     push @action_files, "\"$mirabelle_home/Tools/mirabelle_$1.ML\"";
    49   }
    50 }
    51 my $tools = "";
    52 if ($#action_files >= 0) {
    53   $tools = "uses " . join(" ", @action_files);
    54 }
    55 
    56 open(SETUP_FILE, ">$setup_file") || die "Could not create file '$setup_file'";
    57 
    58 print SETUP_FILE <<END;
    59 theory "$setup_thy_name"
    60 imports "$mirabelle_thy" "$mirabelle_theory"
    61 $tools
    62 begin
    63 
    64 setup {* 
    65   Mirabelle.set_logfile "$log_file" #>
    66   Config.put_thy Mirabelle.timeout $timeout #>
    67   Config.put_thy Mirabelle.verbose $verbose #>
    68   Config.put_thy Mirabelle.start_line $start_line #>
    69   Config.put_thy Mirabelle.end_line $end_line
    70 *}
    71 
    72 END
    73 
    74 foreach (split(/:/, $actions)) {
    75   if (m/([^[]*)(?:\[(.*)\])?/) {
    76     my ($name, $settings_str) = ($1, $2 || "");
    77     $name =~ s/^([a-z])/\U$1/;
    78     print SETUP_FILE "setup {* Mirabelle_$name.invoke [";
    79     my $sep = "";
    80     foreach (split(/,/, $settings_str)) {
    81       if (m/\s*(.*)\s*=\s*(.*)\s*/) {
    82         print SETUP_FILE "$sep(\"$1\", \"$2\")";
    83         $sep = ", ";
    84       }
    85     }
    86     print SETUP_FILE "] *}\n";
    87   }
    88 }
    89 
    90 print SETUP_FILE "\nend";
    91 close SETUP_FILE;
    92 
    93 
    94 # modify target theory file
    95 
    96 open(OLD_FILE, "<$thy_file") || die "Cannot open file '$thy_file'";
    97 my @lines = <OLD_FILE>;
    98 close(OLD_FILE);
    99 
   100 my $thy_text = join("", @lines);
   101 my $old_len = length($thy_text);
   102 $thy_text =~ s/\btheory\b[^\n]*\s*\bimports\s/theory $new_thy_name\nimports "$setup_thy_name" /gm;
   103 die "No 'imports' found" if length($thy_text) == $old_len;
   104 
   105 open(NEW_FILE, ">$new_thy_file") || die "Cannot create file '$new_thy_file'";
   106 print NEW_FILE $thy_text;
   107 close(NEW_FILE);
   108 
   109 my $root_file = "$output_path/ROOT_$thy_name.ML";
   110 open(ROOT_FILE, ">$root_file") || die "Cannot create file '$root_file'";
   111 print ROOT_FILE "use_thy \"$output_path/$new_thy_name\";\n";
   112 close(ROOT_FILE);
   113 
   114 
   115 # run isabelle
   116 
   117 my $r = system "$isabelle_home/bin/isabelle-process " .
   118   "-e 'use \"$root_file\";' -q $mirabelle_logic" . "\n";
   119 
   120 
   121 # cleanup
   122 
   123 unlink $root_file;
   124 unlink $new_thy_file;
   125 unlink $setup_file;
   126 
   127 exit $r;
   128