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