]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/gen-pass-instances.awk
gen-pass-instances.awk: Add comments in handle_line
[thirdparty/gcc.git] / gcc / gen-pass-instances.awk
1 # Copyright (C) 2013-2015 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 where = match(line, /NEXT_PASS \((.+)\)/);
47 if (where == 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_close = length(")");
58
59 # Find pass_name argument
60 len_of_pass_name = len_of_call - (len_of_start + len_of_close);
61 pass_starts_at = where + len_of_start;
62 pass_name = substr(line, pass_starts_at, len_of_pass_name);
63
64 # Set pass_counts
65 if (pass_name in pass_counts)
66 pass_counts[pass_name]++;
67 else
68 pass_counts[pass_name] = 1;
69
70 # Print call expression with extra pass_num argument
71 printf "%s, %s%s\n",
72 substr(line, 1, pass_starts_at + len_of_pass_name - 1),
73 pass_counts[pass_name],
74 substr(line, pass_starts_at + len_of_pass_name);
75 }
76
77 { handle_line() }
78
79 # Local Variables:
80 # mode:awk
81 # c-basic-offset:8
82 # End: