Skip to content

Commit

Permalink
Knock off a few more TODOs:
Browse files Browse the repository at this point in the history
- run sanity check after each pass

- save a copy after each complete iteration

- make sure file starts and ends with a blank
  • Loading branch information
regehr committed Jun 28, 2011
1 parent 235f87d commit fc6f6ec
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions utah/scripts/reduce/c_delta.pl
Expand Up @@ -4,14 +4,10 @@
use Regexp::Common;
use re 'eval';

# run sanity check after each pass

# save a copy after each complete iteration

# make sure file starts and ends with a blank

# print stats for individual regexes

# watch for unexpected abnormal compiler outputs

# add passes to
# remove digits from numbers to make them smaller
# turn checksum calls into regular printfs
Expand Down Expand Up @@ -159,14 +155,25 @@ ()
while (my $line = <INF>) {
$prog .= $line;
}
if (substr($prog, 0, 1) ne " ") {
$prog = " $prog";
}
if (substr ($prog, -1, 1) ne " ") {
$prog = "$prog ";
}
close INF;
}

sub save_copy ($) {
(my $fn) = @_;
open OUTF, ">$fn" or die;
print OUTF $prog;
close OUTF;
}

sub write_file () {
if (defined($DEBUG) && $DEBUG) {
open OUTF, ">delta_tmp_${trial_num}.c" or die;
print OUTF $prog;
close OUTF;
save_copy ("delta_tmp_${trial_num}.c");
}
$trial_num++;
open OUTF, ">$cfile" or die;
Expand Down Expand Up @@ -240,13 +247,23 @@ ($$)
}
}

sub sanity_check () {
print "sanity check... ";
my $res = run_test ();
if (!$res) {
die "test (and sanity check) fails";
}
}

sub delta_pass ($) {
(my $method) = @_;

$pos = 0;
$good_cnt = 0;
$bad_cnt = 0;

sanity_check();

print "========== starting pass <$method> ==========\n";

while (1) {
Expand Down Expand Up @@ -421,12 +438,6 @@ ()
}
}

print "making sure test succeeds on initial input...\n";
my $res = run_test ();
if (!$res) {
die "test fails!";
}

system "cp $cfile $cfile.orig";
system "cp $cfile $cfile.bak";

Expand All @@ -440,6 +451,7 @@ sub bymethod {

while (1) {
my $success = 0;
save_copy ("delta_backup_${pass_num}.c");
foreach my $method (sort bymethod keys %methods) {
$success |= delta_pass ($method);
}
Expand Down

0 comments on commit fc6f6ec

Please sign in to comment.