summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-03-22 17:15:50 +0100
committerAkim Demaille <akim.demaille@gmail.com>2020-05-09 16:43:59 +0200
commit19f45df02bf434477731a9aab9b3add5c642d01a (patch)
tree45410b83b5a66b68c92a134b19bc364b3ec756d1 /etc
parent2ab4058de09d9f000d5f58bd058ced58f0160e7a (diff)
downloadbison-19f45df02bf434477731a9aab9b3add5c642d01a.tar.gz
bench: use *.cc for C++
Using *.c is simpler, but triggers annoying warnings with Clang++. * etc/bench.pl.in: Please the dictator.
Diffstat (limited to 'etc')
-rwxr-xr-xetc/bench.pl.in48
1 files changed, 37 insertions, 11 deletions
diff --git a/etc/bench.pl.in b/etc/bench.pl.in
index 96299939..053efd22 100755
--- a/etc/bench.pl.in
+++ b/etc/bench.pl.in
@@ -775,30 +775,50 @@ sub run ($)
##################################################################
-=item C<compile ($base)>
+=item C<language ($base)>
-The compiler to use depending on the %language specification in
-C<$base.y>.
+The language to use depending on the %language specification in
+C<$base.y>: C<c> or C<c++>.
=cut
-sub compiler ($)
+sub language ($)
{
my ($base) = @_;
if ($gbench)
{
- $cxx;
+ "c++";
}
else
{
my $language = `sed -ne '/%language "\\(.*\\)"/{s//\\1/;p;q;}' $base.y`;
chomp $language;
- $language eq 'C++' ? $cxx : $cc;
+ $language eq 'C++' ? "c++" : "c";
}
}
##################################################################
+=item C<compiler ($base)>
+
+The compiler to use depending on the %language specification in
+C<$base.y>.
+
+=cut
+
+sub compiler ($)
+{
+ my ($base) = @_;
+ my %compiler =
+ (
+ 'c++' => $cxx,
+ 'c' => $cc,
+ );
+ $compiler{language ($base)};
+}
+
+##################################################################
+
=item C<compile ($base)>
Compile C<$base.y> to an executable.
@@ -812,14 +832,20 @@ sub compile ($)
my $my_bison = `sed -ne '/[/][/] %bison "\\(.*\\)"/{s//\\1/;p;q;}' $base.y`;
chop $my_bison;
- run ((length $my_bison ? $my_bison : $bison) . " $base.y -o $base.c");
+ my %ext =
+ (
+ 'c++' => 'cc',
+ '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.c";
+ run "$compiler -c -o $base.o $cflags $base.$ext";
}
else
{
- run "$compiler -o $base $cflags $base.c";
+ run "$compiler -o $base $cflags $base.$ext";
}
}
@@ -920,14 +946,14 @@ EOF
push @obj, "$base.o";
}
- my $out = new IO::File ">main.c";
+ my $out = new IO::File ">main.cc";
print $out <<EOF;
#include <benchmark/benchmark.h>
BENCHMARK_MAIN();
EOF
- run "$compiler -o main $cflags main.c @obj -lbenchmark";
+ run "$compiler -o main $cflags main.cc @obj -lbenchmark";
run "./main | tee -a README.md";
}