]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/opth-gen.awk
[multiple changes]
[thirdparty/gcc.git] / gcc / opth-gen.awk
CommitLineData
776dc15d
KC
1# Copyright (C) 2003,2004 Free Software Foundation, Inc.
2# Contributed by Kelley Cook, June 2004.
3# Original code from Neil Booth, May 2003.
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License as published by the
7# Free Software Foundation; either version 2, or (at your option) any
8# later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19# This Awk script reads in the option records generated from
20# opt-gather.awk, combines the flags of duplicate options and generates a
21# C header file.
22#
23# This program uses functions from opt-functions.awk
24# Usage: awk -f opt-functions.awk -f opth-gen.awk < inputfile > options.h
25
26BEGIN {
27 n_opts = 0
28 n_langs = 0
fe609b0f
EB
29 n_extra_masks = 0
30 quote = "\042"
776dc15d
KC
31 comma = ","
32 FS=SUBSEP
33}
34
35# Collect the text and flags of each option into an array
36 {
37 if ($1 == "Language") {
38 langs[n_langs] = $2
39 n_langs++;
40 }
41 else {
fe609b0f
EB
42 name = opt_args("Mask", $1)
43 if (name == "") {
44 opts[n_opts] = $1
45 flags[n_opts] = $2
46 help[n_opts] = $3
47 n_opts++;
48 }
49 else {
50 extra_masks[n_extra_masks++] = name
51 }
776dc15d
KC
52 }
53 }
54
55# Dump out an enumeration into a .h file.
56# Combine the flags of duplicate options.
57END {
58print "/* This file is auto-generated by opts.sh. */"
59print ""
60print "#ifndef OPTIONS_H"
61print "#define OPTIONS_H"
62print ""
75685792 63print "extern int target_flags;"
fe609b0f 64print ""
776dc15d
KC
65
66for (i = 0; i < n_opts; i++) {
67 name = var_name(flags[i]);
68 if (name == "")
69 continue;
70
71 print "/* Set by -" opts[i] "."
72 print " " help[i] " */"
73 print "extern int " name ";"
74 print ""
75
76 }
77
75685792
RS
78masknum = 0
79for (i = 0; i < n_opts; i++) {
80 name = opt_args("Mask", flags[i])
f9b4c1db 81 if (name != "" && !flag_set_p("MaskExists", flags[i]))
75685792
RS
82 print "#define MASK_" name " (1 << " masknum++ ")"
83}
fe609b0f
EB
84for (i = 0; i < n_extra_masks; i++) {
85 print "#define MASK_" extra_masks[i] " (1 << " masknum++ ")"
86}
75685792
RS
87if (masknum > 31)
88 print "#error too many target masks"
89print ""
90
91for (i = 0; i < n_opts; i++) {
92 name = opt_args("Mask", flags[i])
f9b4c1db 93 if (name != "" && !flag_set_p("MaskExists", flags[i]))
75685792
RS
94 print "#define TARGET_" name \
95 " ((target_flags & MASK_" name ") != 0)"
96}
fe609b0f
EB
97for (i = 0; i < n_extra_masks; i++) {
98 print "#define TARGET_" extra_masks[i] \
99 " ((target_flags & MASK_" extra_masks[i] ") != 0)"
100}
75685792
RS
101print ""
102
103for (i = 0; i < n_opts; i++) {
104 opt = opt_args("InverseMask", flags[i])
105 if (opt ~ ",")
106 print "#define TARGET_" nth_arg(1, opt) \
107 " ((target_flags & MASK_" nth_arg(0, opt) ") == 0)"
108}
109print ""
776dc15d
KC
110
111for (i = 0; i < n_langs; i++) {
112 macros[i] = "CL_" langs[i]
113 gsub( "[^A-Za-z0-9_]", "X", macros[i] )
114 s = substr(" ", length (macros[i]))
115 print "#define " macros[i] s " (1 << " i ")"
116 }
117
118print ""
119print "enum opt_code"
120print "{"
121
122for (i = 0; i < n_opts; i++)
123 back_chain[i] = "N_OPTS";
124
125 for (i = 0; i < n_opts; i++) {
126 # Combine the flags of identical switches. Switches
127 # appear many times if they are handled by many front
128 # ends, for example.
129 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
130 flags[i + 1] = flags[i] " " flags[i + 1];
131 i++;
132 }
133
134 len = length (opts[i]);
135 enum = "OPT_" opts[i]
136 if (opts[i] == "finline-limit=")
137 enum = enum "eq"
138 gsub ("[^A-Za-z0-9]", "_", enum)
139
140 # If this switch takes joined arguments, back-chain all
141 # subsequent switches to it for which it is a prefix. If
142 # a later switch S is a longer prefix of a switch T, T
143 # will be back-chained to S in a later iteration of this
144 # for() loop, which is what we want.
a56a0779 145 if (flag_set_p("Joined.*", flags[i])) {
776dc15d
KC
146 for (j = i + 1; j < n_opts; j++) {
147 if (substr (opts[j], 1, len) != opts[i])
148 break;
149 back_chain[j] = enum;
150 }
151 }
152
153 s = substr(" ", length (opts[i]))
154 if (i + 1 == n_opts)
155 comma = ""
156
157 if (help[i] == "")
158 hlp = "0"
159 else
160 hlp = "N_(\"" help[i] "\")";
161
162 print " " enum "," s "/* -" opts[i] " */"
163}
164
165print " N_OPTS"
166print "};"
167print ""
168print "#endif /* OPTIONS_H */"
169}