gcc50: Disconnect from buildworld.
[dragonfly.git] / contrib / gcc-5.0 / 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         where = match(line, /NEXT_PASS \((.+)\)/)
45         if (where != 0)
46         {
47                 len_of_start = length("NEXT_PASS (")
48                 len_of_end = length(")")
49                 len_of_pass_name = RLENGTH - (len_of_start + len_of_end)
50                 line_length = length(line)
51                 pass_starts_at = where + len_of_start
52                 pass_name = substr(line, pass_starts_at, len_of_pass_name)
53                 if (pass_name in pass_counts)
54                         pass_counts[pass_name]++;
55                 else
56                         pass_counts[pass_name] = 1;
57                 printf "%s, %s%s\n",
58                         substr(line, 1, pass_starts_at + len_of_pass_name - 1),
59                         pass_counts[pass_name],
60                         substr(line, pass_starts_at + len_of_pass_name);
61         } else {
62                 print line;
63         }
64 }
65
66 { handle_line() }