mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13: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
|
=cut
|
||||||
|
|
||||||
sub compile ($)
|
sub compile ($$)
|
||||||
{
|
{
|
||||||
my ($base) = @_;
|
my ($makefile, $base) = @_;
|
||||||
my $compiler = compiler ($base);
|
my $compiler = compiler ($base);
|
||||||
|
|
||||||
my $my_bison = `sed -ne '/[/][/] %bison "\\(.*\\)"/{s//\\1/;p;q;}' $base.y`;
|
my $my_bison = `sed -ne '/[/][/] %bison "\\(.*\\)"/{s//\\1/;p;q;}' $base.y`;
|
||||||
@@ -838,14 +838,21 @@ sub compile ($)
|
|||||||
'c' => 'c',
|
'c' => 'c',
|
||||||
);
|
);
|
||||||
my $ext = $ext{language ($base)};
|
my $ext = $ext{language ($base)};
|
||||||
run ((length $my_bison ? $my_bison : $bison) . " $base.y -o $base.$ext");
|
|
||||||
if ($gbench)
|
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
|
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.
|
# For each bench, capture the size.
|
||||||
my %size;
|
my %size;
|
||||||
|
|
||||||
|
my $makefile = new IO::File ">Makefile";
|
||||||
while (my ($name, $directives) = each %bench)
|
while (my ($name, $directives) = each %bench)
|
||||||
{
|
{
|
||||||
generate_grammar ($grammar, $name, $directives);
|
generate_grammar ($grammar, $name, $directives);
|
||||||
# Compile the executable.
|
# Compile the executable.
|
||||||
compile ($name);
|
compile ($makefile, $name);
|
||||||
|
run "make $name";
|
||||||
$bench{$name} = "system ('./$name');";
|
$bench{$name} = "system ('./$name');";
|
||||||
chop($size{$name} = `wc -c <$name`);
|
chop($size{$name} = `wc -c <$name`);
|
||||||
}
|
}
|
||||||
@@ -932,6 +941,14 @@ sub bench_with_gbenchmark ($@)
|
|||||||
my $readme = new IO::File ">README.md";
|
my $readme = new IO::File ">README.md";
|
||||||
print $readme <<EOF;
|
print $readme <<EOF;
|
||||||
compiler: $compiler $cflags
|
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
|
EOF
|
||||||
|
|
||||||
my @obj = ();
|
my @obj = ();
|
||||||
@@ -942,7 +959,7 @@ EOF
|
|||||||
print $m;
|
print $m;
|
||||||
print $readme $m;
|
print $readme $m;
|
||||||
generate_grammar ($grammar, $base, $directive[$i]);
|
generate_grammar ($grammar, $base, $directive[$i]);
|
||||||
compile ($base);
|
compile ($makefile, $base);
|
||||||
push @obj, "$base.o";
|
push @obj, "$base.o";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -953,8 +970,12 @@ EOF
|
|||||||
BENCHMARK_MAIN();
|
BENCHMARK_MAIN();
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
run "$compiler -o main $cflags main.cc @obj -lbenchmark";
|
print $makefile <<EOF;
|
||||||
run "./main | tee -a README.md";
|
main: @{obj}
|
||||||
|
\t$compiler -o main $cflags main.cc @obj -lbenchmark
|
||||||
|
EOF
|
||||||
|
|
||||||
|
run "make";
|
||||||
}
|
}
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user