OSDN Git Service

Remove libcall notes.
[pf3gnuchains/gcc-fork.git] / gcc / opth-gen.awk
1 #  Copyright (C) 2003,2004,2005,2006,2007 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 3, 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; see the file COPYING3.  If not see
17 # <http://www.gnu.org/licenses/>.
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
26 BEGIN {
27         n_opts = 0
28         n_langs = 0
29         n_extra_masks = 0
30         quote = "\042"
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 {
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                         }
52                 }
53         }
54
55 # Dump out an enumeration into a .h file.
56 # Combine the flags of duplicate options.
57 END {
58 print "/* This file is auto-generated by opth-gen.awk.  */"
59 print ""
60 print "#ifndef OPTIONS_H"
61 print "#define OPTIONS_H"
62 print ""
63 print "extern int target_flags;"
64 print "extern int target_flags_explicit;"
65 print ""
66
67 for (i = 0; i < n_opts; i++) {
68         name = var_name(flags[i]);
69         if (name == "")
70                 continue;
71
72         print "extern " var_type(flags[i]) name ";"
73 }
74 print ""
75
76 for (i = 0; i < n_opts; i++) {
77         name = opt_args("Mask", flags[i])
78         vname = var_name(flags[i])
79         mask = "MASK_"
80         if (vname != "") {
81                 mask = "OPTION_MASK_"
82         }
83         if (name != "" && !flag_set_p("MaskExists", flags[i]))
84                 print "#define " mask name " (1 << " masknum[vname]++ ")"
85 }
86 for (i = 0; i < n_extra_masks; i++) {
87         print "#define MASK_" extra_masks[i] " (1 << " masknum[""]++ ")"
88 }
89
90 for (var in masknum) {
91         if (masknum[var] > 31) {
92                 if (var == "")
93                         print "#error too many target masks"
94                 else
95                         print "#error too many masks for " var
96         }
97 }
98 print ""
99
100 for (i = 0; i < n_opts; i++) {
101         name = opt_args("Mask", flags[i])
102         vname = var_name(flags[i])
103         macro = "OPTION_"
104         mask = "OPTION_MASK_"
105         if (vname == "") {
106                 vname = "target_flags"
107                 macro = "TARGET_"
108                 mask = "MASK_"
109         }
110         if (name != "" && !flag_set_p("MaskExists", flags[i]))
111                 print "#define " macro name \
112                       " ((" vname " & " mask name ") != 0)"
113 }
114 for (i = 0; i < n_extra_masks; i++) {
115         print "#define TARGET_" extra_masks[i] \
116               " ((target_flags & MASK_" extra_masks[i] ") != 0)"
117 }
118 print ""
119
120 for (i = 0; i < n_opts; i++) {
121         opt = opt_args("InverseMask", flags[i])
122         if (opt ~ ",") {
123                 vname = var_name(flags[i])
124                 macro = "OPTION_"
125                 mask = "OPTION_MASK_"
126                 if (vname == "") {
127                         vname = "target_flags"
128                         macro = "TARGET_"
129                         mask = "MASK_"
130                 }
131                 print "#define " macro nth_arg(1, opt) \
132                       " ((" vname " & " mask nth_arg(0, opt) ") == 0)"
133         }
134 }
135 print ""
136
137 for (i = 0; i < n_langs; i++) {
138         macros[i] = "CL_" langs[i]
139         gsub( "[^A-Za-z0-9_]", "X", macros[i] )
140         s = substr("            ", length (macros[i]))
141         print "#define " macros[i] s " (1 << " i ")"
142     }
143 print "#define CL_LANG_ALL   ((1 << " n_langs ") - 1)"
144
145 print ""
146 print "enum opt_code"
147 print "{"
148         
149 for (i = 0; i < n_opts; i++)
150         back_chain[i] = "N_OPTS";
151
152 for (i = 0; i < n_opts; i++) {
153         # Combine the flags of identical switches.  Switches
154         # appear many times if they are handled by many front
155         # ends, for example.
156         while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
157                 flags[i + 1] = flags[i] " " flags[i + 1];
158                 i++;
159         }
160
161         len = length (opts[i]);
162         enum = "OPT_" opts[i]
163         if (opts[i] == "finline-limit=" || opts[i] == "Wlarger-than=")
164                 enum = enum "eq"
165         gsub ("[^A-Za-z0-9]", "_", enum)
166
167         # If this switch takes joined arguments, back-chain all
168         # subsequent switches to it for which it is a prefix.  If
169         # a later switch S is a longer prefix of a switch T, T
170         # will be back-chained to S in a later iteration of this
171         # for() loop, which is what we want.
172         if (flag_set_p("Joined.*", flags[i])) {
173                 for (j = i + 1; j < n_opts; j++) {
174                         if (substr (opts[j], 1, len) != opts[i])
175                                 break;
176                         back_chain[j] = enum;
177                 }
178         }
179
180         s = substr("                                     ", length (opts[i]))
181         if (i + 1 == n_opts)
182                 comma = ""
183
184         if (help[i] == "")
185                 hlp = "0"
186         else
187                 hlp = "N_(\"" help[i] "\")";
188
189         print "  " enum "," s "/* -" opts[i] " */"
190 }
191
192 print "  N_OPTS"
193 print "};"
194 print ""
195 print "#endif /* OPTIONS_H */"
196 }