From 19f45df02bf434477731a9aab9b3add5c642d01a Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 22 Mar 2020 17:15:50 +0100 Subject: [PATCH] bench: use *.cc for C++ Using *.c is simpler, but triggers annoying warnings with Clang++. * etc/bench.pl.in: Please the dictator. --- etc/bench.pl.in | 58 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 16 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,7 +775,31 @@ sub run ($) ################################################################## -=item C +=item C + +The language to use depending on the %language specification in +C<$base.y>: C or C. + +=cut + +sub language ($) +{ + my ($base) = @_; + if ($gbench) + { + "c++"; + } + else + { + my $language = `sed -ne '/%language "\\(.*\\)"/{s//\\1/;p;q;}' $base.y`; + chomp $language; + $language eq 'C++' ? "c++" : "c"; + } +} + +################################################################## + +=item C The compiler to use depending on the %language specification in C<$base.y>. @@ -785,16 +809,12 @@ C<$base.y>. sub compiler ($) { my ($base) = @_; - if ($gbench) - { - $cxx; - } - else - { - my $language = `sed -ne '/%language "\\(.*\\)"/{s//\\1/;p;q;}' $base.y`; - chomp $language; - $language eq 'C++' ? $cxx : $cc; - } + my %compiler = + ( + 'c++' => $cxx, + 'c' => $cc, + ); + $compiler{language ($base)}; } ################################################################## @@ -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 < 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"; }