OSDN Git Service

* config/frv/frv.h: Remove declaration of g_switch_value.
[pf3gnuchains/gcc-fork.git] / gcc / opts.sh
1 #!/bin/sh
2 #
3 #  Copyright (C) 2003 Free Software Foundation, Inc.
4 #  Contributed by Neil Booth, May 2003.
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2, or (at your option) any
9 # later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #
20 # Usage: opts.sh outfile.c outfile.h file1.opt [file2.opt, ...]
21
22 # Always operate in the C locale.
23 LANG=C
24 LANGUAGE=C
25 LC_ALL=C
26 export LANG LANGUAGE LC_ALL
27
28 # Set AWK if environment has not already set it.
29 AWK=${AWK-awk}
30
31 SORT=sort               # Could be /bin/sort or /usr/bin/sort
32
33 C_FILE=$1; shift
34 H_FILE=$1; shift
35
36 # Must unset, so that RS="" works in gawk 3.0-3.1.1 (possibly earlier too)
37 # Appears to be a gawk bug, RS="" is not an extension
38 unset POSIXLY_CORRECT
39
40 ${AWK} '
41         BEGIN{ RS=""; FS="\n" }
42         # Ignore comments and blank lines
43         /^[ \t]*(;|$)/  { next }
44         /^[^ \t]/       { gsub ("\n", "\034", $0); print }
45 ' "$@" | ${SORT} | ${AWK} '
46     function switch_flags (flags,   result)
47     {
48         flags = " " flags " "
49         result = "0"
50         for (j = 0; j < n_langs; j++) {
51             regex = " " langs[j] " "
52             gsub ( "\\+", "\\+", regex )
53             if (flags ~ regex)
54                 result = result " | " macros[j]
55         }
56         if (flags ~ " Common ") result = result " | CL_COMMON"
57         if (flags ~ " Joined ") result = result " | CL_JOINED"
58         if (flags ~ " Separate ") result = result " | CL_SEPARATE"
59         if (flags ~ " RejectNegative ") result = result " | CL_REJECT_NEGATIVE"
60         sub( "^0 \\| ", "", result )
61         return result
62     }
63
64     BEGIN {
65         FS = "\034"
66         n_opts = 0
67         n_langs = 0
68     }
69
70 # Collect the text and flags of each option into an array
71     {
72         if ($1 == "Language") {
73                 langs[n_langs] = $2
74                 n_langs++;
75         } else {
76                 opts[n_opts] = $1
77                 flags[n_opts] = $2
78                 n_opts++;
79         }
80     }
81
82 # Dump out an enumeration into a .h file, and an array of options into a
83 # C file.  Combine the flags of duplicate options.
84     END {
85         c_file = "'${C_FILE}'"
86         h_file = "'${H_FILE}'"
87         comma = ","
88
89         print "/* This file is auto-generated by opts.sh.  */\n" > h_file
90         for (i = 0; i < n_langs; i++) {
91             macros[i] = "CL_" langs[i]
92             gsub( "[^A-Za-z0-9_]", "X", macros[i] )
93             s = substr("         ", length (macros[i]))
94             print "#define " macros[i] s " (1 << " i ")" >> h_file
95         }
96         print "\nenum opt_code\n{"                      >> h_file
97
98         print "/* This file is auto-generated by opts.sh.  */\n" > c_file
99         print "#include \"" h_file "\""                 >> c_file
100         print "#include \"opts.h\"\n"                   >> c_file
101         print "const unsigned int cl_options_count = N_OPTS;\n" >> c_file
102         print "const struct cl_option cl_options[] =\n{" >> c_file
103
104         for (i = 0; i < n_opts; i++) {
105             while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
106                 flags[i + 1] = flags[i] " " flags[i + 1];
107                 i++;
108             }
109
110             enum = "OPT_" opts[i]
111             gsub( "[^A-Za-z0-9]", "_", enum)
112             s = substr("                                  ", length (opts[i]))
113             if (i + 1 == n_opts)
114                 comma = ""
115
116             printf("  %s,%s/* -%s */\n", enum, s, opts[i]) >> h_file
117             printf("  { \"%s\", %u, %s }%s\n", opts[i], \
118                 length(opts[i]), switch_flags(flags[i]), comma) >> c_file
119         }
120
121         print "  N_OPTS\n};"                            >> h_file
122         print "};"                                      >> c_file
123     }
124 '