]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gen-pass-instances.awk
gen-pass-instances.awk: Add comments in handle_line
[thirdparty/gcc.git] / gcc / gen-pass-instances.awk
CommitLineData
d353bf18 1# Copyright (C) 2013-2015 Free Software Foundation, Inc.
743d5ab7 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
36BEGIN {
37 print "/* This file is auto-generated by gen-pass-instances.awk";
38 print " from passes.def. */";
39}
40
41function handle_line()
42{
43 line = $0;
cbfc4279 44
031e0483 45 # Find call expression.
4f393913 46 where = match(line, /NEXT_PASS \((.+)\)/);
cbfc4279 47 if (where == 0)
743d5ab7 48 {
743d5ab7 49 print line;
cbfc4279 50 return;
743d5ab7 51 }
cbfc4279 52
031e0483 53 # Length of the call expression.
54 len_of_call = RLENGTH;
55
cbfc4279 56 len_of_start = length("NEXT_PASS (");
dc0fce29 57 len_of_close = length(")");
58
89e9bb5d 59 # Find pass_name argument
dc0fce29 60 len_of_pass_name = len_of_call - (len_of_start + len_of_close);
cbfc4279 61 pass_starts_at = where + len_of_start;
62 pass_name = substr(line, pass_starts_at, len_of_pass_name);
89e9bb5d 63
64 # Set pass_counts
cbfc4279 65 if (pass_name in pass_counts)
66 pass_counts[pass_name]++;
67 else
68 pass_counts[pass_name] = 1;
89e9bb5d 69
70 # Print call expression with extra pass_num argument
cbfc4279 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);
743d5ab7 75}
76
77{ handle_line() }
71fd3d00 78
79# Local Variables:
80# mode:awk
81# c-basic-offset:8
82# End: