blob: 872f61b33a77b61b2975b687f1b4cdfc8e392491 [file] [log] [blame]
Ted Kremenek3a465302012-05-21 23:29:01 +00001#!/usr/bin/perl -w
2use strict;
3use File::Temp qw/ tempdir /;
4my $prog = "reducer";
5
6die "$prog <code file> <error string> [optional command]\n" if ($#ARGV < 0);
7my $file = shift @ARGV;
8die "$prog: [error] cannot read file $file\n" if (! -r $file);
9
10my $magic = shift @ARGV;
11die "$prog: [error] no error string specified\n" if (! defined $magic);
12
Ted Kremenek7c451632012-05-22 00:54:40 +000013# Create a backup of the file.
Ted Kremenek3a465302012-05-21 23:29:01 +000014my $dir = tempdir( CLEANUP => 1 );
15print "$prog: created temporary directory '$dir'\n";
16my $srcFile = "$dir/$file";
17`cp $file $srcFile`;
18
19# Create the script.
20my $scriptFile = "$dir/script";
21open(OUT, ">$scriptFile") or die "$prog: cannot create '$scriptFile'\n";
22my $reduceOut = "$dir/reduceOut";
23
24my $command;
25if (scalar(@ARGV) > 0) { $command = \@ARGV; }
26else {
Ted Kremenek86674ec2012-05-22 00:52:49 +000027 my $compiler = "clang";
Ted Kremenek3a465302012-05-21 23:29:01 +000028 $command = [$compiler, "-fsyntax-only", "-Wfatal-errors", "-Wno-deprecated-declarations", "-Wimplicit-function-declaration"];
29}
30push @$command, $srcFile;
31my $commandStr = "@$command";
32
33print OUT <<ENDTEXT;
34#!/usr/bin/perl -w
35use strict;
36my \$BAD = 1;
37my \$GOOD = 0;
38`rm -f $reduceOut`;
39my \$command = "$commandStr > $reduceOut 2>&1";
40system(\$command);
41open(IN, "$reduceOut") or exit(\$BAD);
42my \$found = 0;
43while(<IN>) {
44 if (/$magic/) { exit \$GOOD; }
45}
46exit \$BAD;
47ENDTEXT
48close(OUT);
49`chmod +x $scriptFile`;
50
51print "$prog: starting reduction\n";
Ted Kremenek86674ec2012-05-22 00:52:49 +000052sub multidelta($) {
53 my ($level) = @_;
Ted Kremenek3a465302012-05-21 23:29:01 +000054 system("multidelta -level=$level $scriptFile $srcFile");
55}
56
57for (my $i = 1 ; $i <= 5; $i++) {
58 foreach my $level (0,0,1,1,2,2,10) {
59 multidelta($level);
60 }
61}
62
63# Copy the final file.
64`cp $srcFile $file.reduced`;
65print "$prog: generated '$file.reduced";