2 # Copyright 2016 Vincent Danjean <vincent.danjean@inria.fr>
3 # Christian Heinrich <franz-christian.heinrich@inria.fr>
5 # Call this script like this:
6 # C/C++ : ./generate_smpi_defines.pl ../../include/smpi/smpi.h
7 # FORTRAN: ./generate_smpi_defines.pl -f ../../include/smpi/smpi.h
9 # It will generate macros that are useful for adding file and line numbers to
10 # traces without obtaining a backtrace (as this would be very slow and make
11 # the simulation/trace unreliable when compared to a "real" trace as obtained
18 getopts("fc", \%options);
20 # $incall denotes whether we are currently parsing a macro or not...
24 if (defined $options{f}) {
28 print "$commentChar This file has been automatically generated by the script\n";
29 print "$commentChar in tools/smpi/generate_smpi_defines.pl\n";
30 print "$commentChar DO NOT EDIT MANUALLY. ALL CHANGES WILL BE OVERWRITTEN!\n";
32 # Formatting of the output
35 my @parts = split (/\s*,\s*/, $line);
38 # This is a GCC extension. The last statement is the value of the expression
40 if (defined $options{f}) {
41 print "#define ". lc($id) ." smpi_trace_set_call_location(__FILE__,__LINE__); call ". ucfirst $id ."\n";
42 print "#define ". uc($id) ." smpi_trace_set_call_location(__FILE__,__LINE__); call ". ucfirst $id ."\n";
45 if ($id eq "MPI_Init") {
46 print "#define MPI_Init(...) ({ smpi_process_init(__VA_ARGS__); smpi_trace_set_call_location(__FILE__,__LINE__); MPI_Init(NULL, NULL); })\n";
49 print "#define $id(...) ({ smpi_trace_set_call_location(__FILE__,__LINE__); $id(__VA_ARGS__); })\n";
56 while (defined($line = <>)) {
58 if ($line =~ /^MPI_CALL/) {
60 output_macro($wholemacro);
64 } elsif ($incall && $line =~ /^\s+\S/) {
65 # Did we already start parsing an MPI_CALL macro? If so, just concatenate
66 $wholemacro .= ' '.$line;
68 output_macro($wholemacro);