Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / tools / smpi / generate_smpi_defines.pl
1 #!/usr/bin/env perl
2 #
3 # Copyright (c) 2016-2023. The SimGrid Team. All rights reserved.
4 #
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.
7 #
8 # Copyright 2016 Vincent Danjean <vincent.danjean@inria.fr>
9 #                Christian Heinrich <franz-christian.heinrich@inria.fr>
10 #
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
14 #
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
18 # with MPI+TAU).
19 use strict;
20 use warnings;
21 use Getopt::Std;
22
23 my %options=();
24 getopts("fc", \%options);
25
26 # $incall denotes whether we are currently parsing a macro or not...
27 my $incall=0;
28
29 my $commentChar="//";
30 if (defined $options{f}) {
31   $commentChar="!"
32 }
33
34 print "$commentChar Copyright (c) 2016-2023. The SimGrid Team. All rights reserved.\n";
35 print "\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";
38 print "\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";
42 print "\n";
43
44 # Formatting of the output
45 sub output_macro {
46   my $line = shift;
47   my @parts = split (/\s*,\s*/, $line);
48   my $id = $parts[1];
49
50   # This is a GCC extension. The last statement is the value of the expression
51   # in parentheses.
52   if (defined $options{f}) {
53     print "#define ". lc($id) ." smpi_trace_set_call_location(__FILE__,__LINE__,\"". lc($id) ."\"); call ". ucfirst $id ."\n";
54     print "#define ". uc($id) ." smpi_trace_set_call_location(__FILE__,__LINE__,\"". uc($id) ."\"); call ". ucfirst $id ."\n";
55   }
56   else {
57     print "#define $id(...) (smpi_trace_set_call_location(__FILE__, __LINE__, \"$id\"), $id(__VA_ARGS__))\n";
58   }
59 }
60
61 my $wholemacro;
62 my $line;
63 while (defined($line = <>)) {
64   chomp($line);
65   if ($line =~ /^MPI_CALL/) {
66     if ($incall) {
67         output_macro($wholemacro);
68     }
69     $incall=1;
70     $wholemacro = $line;
71   } elsif ($incall && $line =~ /^\s+\S/) {
72     # Did we already start parsing an MPI_CALL macro? If so, just concatenate
73     $wholemacro .= ' '.$line;
74   } elsif ($incall) {
75     output_macro($wholemacro);
76     $incall=0;
77   }
78 }