* config.gcc (extra_options): New variable for listing option files.
[official-gcc.git] / gcc / opth-gen.awk
blob83d19343e879c2738551913b31bf493a999e6bf5
1 # Copyright (C) 2003,2004 Free Software Foundation, Inc.
2 # Contributed by Kelley Cook, June 2004.
3 # Original code from Neil Booth, May 2003.
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.
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.
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.
23 # This program uses functions from opt-functions.awk
24 # Usage: awk -f opt-functions.awk -f opth-gen.awk < inputfile > options.h
26 BEGIN {
27 n_opts = 0
28 n_langs = 0
29 quote = "\042"
30 comma = ","
31 FS=SUBSEP
34 # Collect the text and flags of each option into an array
36 if ($1 == "Language") {
37 langs[n_langs] = $2
38 n_langs++;
40 else {
41 opts[n_opts] = $1
42 flags[n_opts] = $2
43 help[n_opts] = $3
44 n_opts++;
48 # Dump out an enumeration into a .h file.
49 # Combine the flags of duplicate options.
50 END {
51 print "/* This file is auto-generated by opts.sh. */"
52 print ""
53 print "#ifndef OPTIONS_H"
54 print "#define OPTIONS_H"
55 print ""
56 print "extern int target_flags;"
58 for (i = 0; i < n_opts; i++) {
59 name = var_name(flags[i]);
60 if (name == "")
61 continue;
63 print "/* Set by -" opts[i] "."
64 print " " help[i] " */"
65 print "extern int " name ";"
66 print ""
70 masknum = 0
71 for (i = 0; i < n_opts; i++) {
72 name = opt_args("Mask", flags[i])
73 if (name != "")
74 print "#define MASK_" name " (1 << " masknum++ ")"
76 if (masknum > 31)
77 print "#error too many target masks"
78 print ""
80 for (i = 0; i < n_opts; i++) {
81 name = opt_args("Mask", flags[i])
82 if (name != "")
83 print "#define TARGET_" name \
84 " ((target_flags & MASK_" name ") != 0)"
86 print ""
88 for (i = 0; i < n_opts; i++) {
89 opt = opt_args("InverseMask", flags[i])
90 if (opt ~ ",")
91 print "#define TARGET_" nth_arg(1, opt) \
92 " ((target_flags & MASK_" nth_arg(0, opt) ") == 0)"
94 print ""
96 for (i = 0; i < n_langs; i++) {
97 macros[i] = "CL_" langs[i]
98 gsub( "[^A-Za-z0-9_]", "X", macros[i] )
99 s = substr(" ", length (macros[i]))
100 print "#define " macros[i] s " (1 << " i ")"
103 print ""
104 print "enum opt_code"
105 print "{"
107 for (i = 0; i < n_opts; i++)
108 back_chain[i] = "N_OPTS";
110 for (i = 0; i < n_opts; i++) {
111 # Combine the flags of identical switches. Switches
112 # appear many times if they are handled by many front
113 # ends, for example.
114 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
115 flags[i + 1] = flags[i] " " flags[i + 1];
116 i++;
119 len = length (opts[i]);
120 enum = "OPT_" opts[i]
121 if (opts[i] == "finline-limit=")
122 enum = enum "eq"
123 gsub ("[^A-Za-z0-9]", "_", enum)
125 # If this switch takes joined arguments, back-chain all
126 # subsequent switches to it for which it is a prefix. If
127 # a later switch S is a longer prefix of a switch T, T
128 # will be back-chained to S in a later iteration of this
129 # for() loop, which is what we want.
130 if (flags[i] ~ "Joined") {
131 for (j = i + 1; j < n_opts; j++) {
132 if (substr (opts[j], 1, len) != opts[i])
133 break;
134 back_chain[j] = enum;
138 s = substr(" ", length (opts[i]))
139 if (i + 1 == n_opts)
140 comma = ""
142 if (help[i] == "")
143 hlp = "0"
144 else
145 hlp = "N_(\"" help[i] "\")";
147 print " " enum "," s "/* -" opts[i] " */"
150 print " N_OPTS"
151 print "};"
152 print ""
153 print "#endif /* OPTIONS_H */"