MAINTAINERS (Write After Approval): Add myself.
[platform/upstream/gcc.git] / gcc / gen-pass-instances.awk
1 #  Copyright (C) 2013-2016 Free Software Foundation, Inc.
2 #
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by the
5 # Free Software Foundation; either version 3, or (at your option) any
6 # later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; see the file COPYING3.  If not see
15 # <http://www.gnu.org/licenses/>.
16
17 # This Awk script takes passes.def and writes pass-instances.def,
18 # counting the instances of each kind of pass, adding an instance number
19 # to everywhere that NEXT_PASS is used.
20 #
21 # For example, the single-instanced pass:
22 #     NEXT_PASS (pass_warn_unused_result);
23 # becomes this in the output:
24 #     NEXT_PASS (pass_warn_unused_result, 1);
25 #
26 # The various instances of
27 #   NEXT_PASS (pass_copy_prop);
28 # become:
29 #   NEXT_PASS (pass_copy_prop, 1);
30 # through:
31 #   NEXT_PASS (pass_copy_prop, 8);
32 # (currently there are 8 instances of that pass)
33
34 # Usage: awk -f gen-pass-instances.awk passes.def
35
36 BEGIN {
37         print "/* This file is auto-generated by gen-pass-instances.awk";
38         print "   from passes.def.  */";
39 }
40
41 function handle_line()
42 {
43         line = $0;
44
45         # Find call expression.
46         call_starts_at = match(line, /NEXT_PASS \(.+\)/);
47         if (call_starts_at == 0)
48         {
49                 print line;
50                 return;
51         }
52
53         # Length of the call expression.
54         len_of_call = RLENGTH;
55
56         len_of_start = length("NEXT_PASS (");
57         len_of_open = length("(");
58         len_of_close = length(")");
59
60         # Find arguments
61         len_of_args = len_of_call - (len_of_start + len_of_close);
62         args_start_at = call_starts_at + len_of_start;
63         args_str = substr(line, args_start_at, len_of_args);
64         split(args_str, args, ",");
65
66         # Set pass_name argument, an optional with_arg argument
67         pass_name = args[1];
68         with_arg = args[2];
69
70         # Find call expression prefix
71         len_of_prefix = call_starts_at - 1;
72         prefix = substr(line, 1, len_of_prefix);
73
74         # Find call expression postfix
75         postfix_starts_at = call_starts_at + len_of_call;
76         postfix = substr(line, postfix_starts_at);
77
78         # Set pass_counts
79         if (pass_name in pass_counts)
80                 pass_counts[pass_name]++;
81         else
82                 pass_counts[pass_name] = 1;
83
84         pass_num = pass_counts[pass_name];
85
86         # Print call expression with extra pass_num argument
87         printf "%s", prefix;
88         if (with_arg)
89         {
90                 printf "NEXT_PASS_WITH_ARG";
91         }
92         else
93         {
94                 printf "NEXT_PASS";
95         }
96         printf " (";
97         printf "%s", pass_name;
98         printf ", %s", pass_num;
99         if (with_arg)
100         {
101                 printf ", %s", with_arg;
102         }
103         printf ")%s\n", postfix;
104 }
105
106 { handle_line() }
107
108 # Local Variables:
109 # mode:awk
110 # c-basic-offset:8
111 # End: