3 # Copyright (c) 2016-2023. The SimGrid Team. All rights reserved.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the license (GNU LGPL) which comes with this package.
8 # Copyright 2016 Vincent Danjean <vincent.danjean@inria.fr>
9 # Christian Heinrich <franz-christian.heinrich@inria.fr>
11 # Call this script like this:
12 # C/C++ : ./generate_smpi_defines.pl ../../include/smpi/smpi.h
13 # FORTRAN: ./generate_smpi_defines.pl -f ../../include/smpi/smpi.h
15 # It will generate macros that are useful for adding file and line numbers to
16 # traces without obtaining a backtrace (as this would be very slow and make
17 # the simulation/trace unreliable when compared to a "real" trace as obtained
24 getopts("fc", \%options);
26 # $incall denotes whether we are currently parsing a macro or not...
30 if (defined $options{f}) {
34 print "$commentChar Copyright (c) 2016-2023. The SimGrid Team. All rights reserved.\n";
36 print "$commentChar This program is free software; you can redistribute it and/or modify it\n";
37 print "$commentChar under the terms of the license (GNU LGPL) which comes with this package.\n";
39 print "$commentChar This file has been automatically generated by the script\n";
40 print "$commentChar in tools/smpi/generate_smpi_defines.pl\n";
41 print "$commentChar DO NOT EDIT MANUALLY. ALL CHANGES WILL BE OVERWRITTEN!\n";
44 # Formatting of the output
47 my @parts = split (/\s*,\s*/, $line);
50 # This is a GCC extension. The last statement is the value of the expression
52 if (defined $options{f}) {
53 print "#define ". lc($id) ." smpi_trace_set_call_location(__FILE__,__LINE__); call ". ucfirst $id ."\n";
54 print "#define ". uc($id) ." smpi_trace_set_call_location(__FILE__,__LINE__); call ". ucfirst $id ."\n";
57 print "#define $id(...) (smpi_trace_set_call_location(__FILE__, __LINE__), $id(__VA_ARGS__))\n";
63 while (defined($line = <>)) {
65 if ($line =~ /^MPI_CALL/) {
67 output_macro($wholemacro);
71 } elsif ($incall && $line =~ /^\s+\S/) {
72 # Did we already start parsing an MPI_CALL macro? If so, just concatenate
73 $wholemacro .= ' '.$line;
75 output_macro($wholemacro);