Skip to content

Commit

Permalink
Add some patterns, tweak the termination condition to avoid
Browse files Browse the repository at this point in the history
infinite loops.
  • Loading branch information
regehr committed Oct 25, 2011
1 parent 2f6a8ed commit a20c81f
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions utah/scripts/reduce/c_delta.pl
Expand Up @@ -27,6 +27,8 @@

# TODO:

# add a global termination constraint-- reduce size across all passes

# turn a union type into a struct
# remove argument from function, including all calls
# transform a function to return void
Expand Down Expand Up @@ -83,7 +85,7 @@

my $DEBUG = 0;
my $INDENT_OPTS = "-bad -bap -bc -cs -pcs -prs -saf -sai -saw -sob -ss -bl ";
my $SANITY = 0;
my $SANITY = 1;

######################################################################

Expand All @@ -96,11 +98,10 @@
my $comp = "\\<\\=|\\>\\=|\\<|\\>|\\=\\=|\\!\\=|\\=";
my $logic = "\\&\\&|\\|\\|";
my $bit = "\\||\\&|\\^|\\<\\<|\\>\\>";
my $binop = "($arith)|($comp)|($logic)|($bit)";
my $binop = "($arith)|($comp)|($logic)|($bit)|(\\-\\>)";
my $border = "[\\*\\{\\(\\[\\:\\,\\}\\)\\]\\;\\,]";
my $borderorspc = "(($border)|(\\s))";
my $rettype = "int|void|short|long|char|signed|unsigned|const|static|(union\\s+U[0-9]+)|(struct\\s+S[0-9+])";
my $functype = "(($rettype)\\s*|\\*\\s*)+";
my $functype = "(($varnum)?\\s*|\\*\\s*)*";
my $fname = "(?<fname>$varnum)";
my $funcstart_free = "$functype\\s+(?<fname>$varnum)\\s*$RE{balanced}{-parens=>'()'}";
my $funcstart = "$functype\\s+XXX\\s*$RE{balanced}{-parens=>'()'}";
Expand All @@ -116,9 +117,12 @@
["=\\s*$RE{balanced}{-parens=>'{}'}", ""],
["\\:\\s*[0-9]+\\s*;", ";"],
["\\;", ""],
["\#(.*)\n", ""],
["\\^\\=", "="],
["\\|\\=", "="],
["\\&\\=", "="],
["\"(.*)\"", ""],
["\'(.*)\'", ""],
["\\+\\=", "="],
["\\-\\=", "="],
["\\*\\=", "="],
Expand All @@ -130,6 +134,9 @@
["\\-", ""],
["\\!", ""],
["\\~", ""],
["struct.*?;", ""],
["union.*?;", ""],
["enum.*?;", ""],
['"(.*?)"', ""],
['"(.*?)",', ""],
);
Expand All @@ -143,12 +150,13 @@
["long", "int"],
["signed", "int"],
["unsigned", "int"],
["int argc, char \\*argv\\[\\]", "void"],
["int(\\s+)argc(\\s*),(\\s*)(.*)(\\s*)\\*argv\\[\\]", "void"],
["int(\\s+)argc(\\s*),(\\s*)(.*)(\\s*)\\*(\\s*)\\*argv", "void"],
["int.*?;", ""],
["for", ""],
["\"(.*)\"", ""],
["\'(.*)\'", ""],
["if\\s+\\(.*?\\)", ""],
["struct.*?;", ""],
["union.*?;", ""],
["($functype)\\s*($varnum)\\s*$RE{balanced}{-parens=>'()'}\\s*$RE{balanced}{-parens=>'{}'}", ""],
["$call,", "0"],
["$call,", ""],
Expand Down Expand Up @@ -470,6 +478,7 @@ ($)
$prog = $first.$rest;
$worked |= delta_test ($method, 0);
}
return 0;
} elsif ($method eq "indent") {
write_file();
system "indent $INDENT_OPTS $cfile";
Expand Down Expand Up @@ -689,14 +698,23 @@ sub bymethod {
read_file ();
$orig_prog_len = length ($prog);

my $file_size = -s $cfile;
my $spinning = 0;

while (1) {
my $success = 0;
save_copy ("delta_backup_${pass_num}.c");
my $success = 0;
foreach my $method (sort bymethod keys %methods) {
$success |= delta_pass ($method);
}
$pass_num++;
last if (!$success);
my $s = -s $cfile;
if ($s >= $file_size) {
$spinning++;
}
last if ($spinning > 3);
$file_size = $s;
}

print "===================== done ====================\n";
Expand Down

0 comments on commit a20c81f

Please sign in to comment.