2 # Copyright 2016 Vincent Danjean <vincent.danjean@inria.fr>
4 # Call this script like this:
5 # C/C++ : ./generate_smpi_defines.pl ../../include/smpi/smpi.h
6 # FORTRAN: ./generate_smpi_defines.pl -f ../../include/smpi/smpi.h
8 # It will generate macros that are useful for adding file and line numbers to
9 # traces without obtaining a backtrace (as this would be very slow and make
10 # the simulation/trace unreliable when compared to a "real" trace as obtained
17 getopts("fc", \%options);
19 # $incall denotes whether we are currently parsing a macro or not...
23 if (defined $options{f}) {
27 print "$commentChar This file has been automatically generated by the script\n";
28 print "$commentChar in " . __FILE__ ."\n";
29 print "$commentChar DO NOT EDIT MANUALLY. ALL CHANGES WILL BE OVERWRITTEN!\n";
31 # Formatting of the output
34 my @parts = split (/\s*,\s*/, $line);
37 # This is a GCC extension. The last statement is the value of the expression
39 if (defined $options{f}) {
40 print "#define ". uc($id) ." smpi_trace_set_call_location(__FILE__,__LINE__); call ". lc $id ."\n";
43 print "#define $id(...) ({ smpi_trace_set_call_location(__FILE__,__LINE__); $id(__VA_ARGS__); })\n";
49 while (defined($line = <>)) {
51 if ($line =~ /^MPI_CALL/) {
53 output_macro($wholemacro);
57 } elsif ($incall && $line =~ /^\s+\S/) {
58 # Did we already start parsing an MPI_CALL macro? If so, just concatenate
59 $wholemacro .= ' '.$line;
61 output_macro($wholemacro);