Daily bump.
[official-gcc.git] / gcc / optc-gen.awk
blob3ed1cf881bebc617223a7f26ecb6b476e22d0572
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 duplicat options and generates a
21 # C file.
23 # This program uses functions from opt-functions.awk
25 # Usage: awk -f opt-functions.awk -f optc-gen.awk \
26 # [-v header_name=header.h] < inputfile > options.c
28 BEGIN {
29 n_opts = 0
30 n_langs = 0
31 quote = "\042"
32 comma = ","
33 FS=SUBSEP
34 # Default the name of header created from opth-gen.awk to options.h
35 if (header_name == "") header_name="options.h"
38 # Collect the text and flags of each option into an array
40 if ($1 == "Language") {
41 langs[n_langs] = $2
42 n_langs++;
44 else {
45 opts[n_opts] = $1
46 flags[n_opts] = $2
47 help[n_opts] = $3
48 n_opts++;
52 # Dump that array of options into a C file.
53 END {
54 print "/* This file is auto-generated by opts.sh. */"
55 print ""
56 print "#include <intl.h>"
57 print "#include " quote header_name quote
58 print "#include " quote "opts.h" quote
59 print ""
61 for (i = 0; i < n_opts; i++) {
62 name = var_name(flags[i]);
63 if (name == "")
64 continue;
66 if (flags[i] ~ "VarExists")
67 continue;
69 if (flags[i] ~ "Init\\(")
71 init = flags[i];
72 sub(".*Init\\(","",init);
73 sub("\\).*","",init);
74 init = " = " init;
76 else
77 init = "";
79 printf ("/* Set by -%s.\n %s */\nint %s%s;\n\n",
80 opts[i], help[i], name,init)
84 print "const char * const lang_names[] =\n{"
85 for (i = 0; i < n_langs; i++) {
86 macros[i] = "CL_" langs[i]
87 gsub( "[^A-Za-z0-9_]", "X", macros[i] )
88 s = substr(" ", length (macros[i]))
89 print " " quote langs[i] quote ","
92 print " 0\n};\n"
93 print "const unsigned int cl_options_count = N_OPTS;\n"
95 print "const struct cl_option cl_options[] =\n{"
97 for (i = 0; i < n_opts; i++)
98 back_chain[i] = "N_OPTS";
100 for (i = 0; i < n_opts; i++) {
101 # Combine the flags of identical switches. Switches
102 # appear many times if they are handled by many front
103 # ends, for example.
104 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
105 flags[i + 1] = flags[i] " " flags[i + 1];
106 i++;
109 len = length (opts[i]);
110 enum = "OPT_" opts[i]
111 if (opts[i] == "finline-limit=")
112 enum = enum "eq"
113 gsub ("[^A-Za-z0-9]", "_", enum)
115 # If this switch takes joined arguments, back-chain all
116 # subsequent switches to it for which it is a prefix. If
117 # a later switch S is a longer prefix of a switch T, T
118 # will be back-chained to S in a later iteration of this
119 # for() loop, which is what we want.
120 if (flags[i] ~ "Joined") {
121 for (j = i + 1; j < n_opts; j++) {
122 if (substr (opts[j], 1, len) != opts[i])
123 break;
124 back_chain[j] = enum;
128 s = substr(" ", length (opts[i]))
129 if (i + 1 == n_opts)
130 comma = ""
132 if (help[i] == "")
133 hlp = "0"
134 else
135 hlp = "N_(" quote help[i] quote ")";
137 printf(" { %c-%s%c,\n %s,\n %s, %u, %s, %s, %s }%s\n",
138 quote, opts[i], quote, hlp, back_chain[i], len,
139 switch_flags(flags[i]),
140 var_ref(flags[i]), var_set(flags[i]), comma)
143 print "};"