mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
bench: use a Makefile
This makes it much easier to toy with the benchs. * etc/bench.pl.in: Generate a Makefile instead of directly compiling the files.
This commit is contained in:
@@ -825,9 +825,9 @@ Compile C<$base.y> to an executable.
|
||||
|
||||
=cut
|
||||
|
||||
sub compile ($)
|
||||
sub compile ($$)
|
||||
{
|
||||
my ($base) = @_;
|
||||
my ($makefile, $base) = @_;
|
||||
my $compiler = compiler ($base);
|
||||
|
||||
my $my_bison = `sed -ne '/[/][/] %bison "\\(.*\\)"/{s//\\1/;p;q;}' $base.y`;
|
||||
@@ -838,14 +838,21 @@ sub compile ($)
|
||||
'c' => 'c',
|
||||
);
|
||||
my $ext = $ext{language ($base)};
|
||||
run ((length $my_bison ? $my_bison : $bison) . " $base.y -o $base.$ext");
|
||||
if ($gbench)
|
||||
{
|
||||
run "$compiler -c -o $base.o $cflags $base.$ext";
|
||||
print $makefile <<EOF;
|
||||
$base.o: $base.y
|
||||
\t@{[length $my_bison ? $my_bison : $bison]} $base.y -o $base.$ext
|
||||
\t$compiler -c -o $base.o $cflags $base.$ext
|
||||
EOF
|
||||
}
|
||||
else
|
||||
{
|
||||
run "$compiler -o $base $cflags $base.$ext";
|
||||
print $makefile <<EOF;
|
||||
$base: $base.y
|
||||
\t@{[length $my_bison ? $my_bison : $bison]} $base.y -o $base.$ext
|
||||
\t$compiler -o $base $cflags $base.$ext
|
||||
EOF
|
||||
}
|
||||
}
|
||||
|
||||
@@ -875,11 +882,13 @@ sub bench_with_timethese ($@)
|
||||
# For each bench, capture the size.
|
||||
my %size;
|
||||
|
||||
my $makefile = new IO::File ">Makefile";
|
||||
while (my ($name, $directives) = each %bench)
|
||||
{
|
||||
generate_grammar ($grammar, $name, $directives);
|
||||
# Compile the executable.
|
||||
compile ($name);
|
||||
compile ($makefile, $name);
|
||||
run "make $name";
|
||||
$bench{$name} = "system ('./$name');";
|
||||
chop($size{$name} = `wc -c <$name`);
|
||||
}
|
||||
@@ -932,6 +941,14 @@ sub bench_with_gbenchmark ($@)
|
||||
my $readme = new IO::File ">README.md";
|
||||
print $readme <<EOF;
|
||||
compiler: $compiler $cflags
|
||||
EOF
|
||||
|
||||
my $makefile = new IO::File ">Makefile";
|
||||
print $makefile <<EOF;
|
||||
.PHONY: bench
|
||||
bench: main
|
||||
\t./main \$(BENCHFLAGS) | tee -a README.md
|
||||
|
||||
EOF
|
||||
|
||||
my @obj = ();
|
||||
@@ -942,7 +959,7 @@ EOF
|
||||
print $m;
|
||||
print $readme $m;
|
||||
generate_grammar ($grammar, $base, $directive[$i]);
|
||||
compile ($base);
|
||||
compile ($makefile, $base);
|
||||
push @obj, "$base.o";
|
||||
}
|
||||
|
||||
@@ -953,8 +970,12 @@ EOF
|
||||
BENCHMARK_MAIN();
|
||||
EOF
|
||||
|
||||
run "$compiler -o main $cflags main.cc @obj -lbenchmark";
|
||||
run "./main | tee -a README.md";
|
||||
print $makefile <<EOF;
|
||||
main: @{obj}
|
||||
\t$compiler -o main $cflags main.cc @obj -lbenchmark
|
||||
EOF
|
||||
|
||||
run "make";
|
||||
}
|
||||
|
||||
######################################################################
|
||||
|
||||
Reference in New Issue
Block a user