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
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
23 # This program uses functions from opt-functions.awk
24 # Usage: awk -f opt-functions.awk -f opth-gen.awk < inputfile > options.h
35 # Collect the text and flags of each option into an array
37 if ($
1 ==
"Language") {
42 name = opt_args
("Mask", $
1)
50 extra_masks
[n_extra_masks
++] = name
55 # Dump out an enumeration into a .h file.
56 # Combine the flags of duplicate options.
58 print "/* This file is auto-generated by opts.sh. */"
60 print "#ifndef OPTIONS_H"
61 print "#define OPTIONS_H"
63 print "extern int target_flags;"
66 for (i =
0; i
< n_opts
; i
++) {
67 name = var_name
(flags
[i
]);
71 print "/* Set by -" opts
[i
] "."
72 print " " help
[i
] " */"
73 print "extern int " name
";"
78 for (i =
0; i
< n_opts
; i
++) {
79 name = opt_args
("Mask", flags
[i
])
80 vname = var_name
(flags
[i
])
85 if (name
!= "" && !flag_set_p
("MaskExists", flags
[i
]))
86 print "#define " mask name
" (1 << " masknum
[vname
]++ ")"
88 for (i =
0; i
< n_extra_masks
; i
++) {
89 print "#define MASK_" extra_masks
[i
] " (1 << " masknum
[""]++ ")"
92 for (var in masknum
) {
93 if (masknum
[var
] > 31) {
95 print "#error too many target masks"
97 print "#error too many masks for " var
102 for (i =
0; i
< n_opts
; i
++) {
103 name = opt_args
("Mask", flags
[i
])
104 vname = var_name
(flags
[i
])
106 mask =
"OPTION_MASK_"
108 vname =
"target_flags"
112 if (name
!= "" && !flag_set_p
("MaskExists", flags
[i
]))
113 print "#define " macro name \
114 " ((" vname
" & " mask name
") != 0)"
116 for (i =
0; i
< n_extra_masks
; i
++) {
117 print "#define TARGET_" extra_masks
[i
] \
118 " ((target_flags & MASK_" extra_masks
[i
] ") != 0)"
122 for (i =
0; i
< n_opts
; i
++) {
123 opt = opt_args
("InverseMask", flags
[i
])
125 print "#define TARGET_" nth_arg
(1, opt
) \
126 " ((target_flags & MASK_" nth_arg
(0, opt
) ") == 0)"
130 for (i =
0; i
< n_langs
; i
++) {
131 macros
[i
] =
"CL_" langs
[i
]
132 gsub( "[^A-Za-z0-9_]", "X", macros
[i
] )
133 s =
substr(" ", length (macros
[i
]))
134 print "#define " macros
[i
] s
" (1 << " i
")"
138 print "enum opt_code"
141 for (i =
0; i
< n_opts
; i
++)
142 back_chain
[i
] =
"N_OPTS";
144 for (i =
0; i
< n_opts
; i
++) {
145 # Combine the flags of identical switches. Switches
146 # appear many times if they are handled by many front
148 while( i
+ 1 != n_opts
&& opts
[i
] == opts
[i
+ 1] ) {
149 flags
[i
+ 1] = flags
[i
] " " flags
[i
+ 1];
153 len =
length (opts
[i
]);
154 enum =
"OPT_" opts
[i
]
155 if (opts
[i
] ==
"finline-limit=")
157 gsub ("[^A-Za-z0-9]", "_", enum
)
159 # If this switch takes joined arguments, back-chain all
160 # subsequent switches to it for which it is a prefix. If
161 # a later switch S is a longer prefix of a switch T, T
162 # will be back-chained to S in a later iteration of this
163 # for() loop, which is what we want.
164 if (flag_set_p
("Joined.*", flags
[i
])) {
165 for (j = i
+ 1; j
< n_opts
; j
++) {
166 if (substr (opts
[j
], 1, len
) != opts
[i
])
168 back_chain
[j
] = enum
;
172 s =
substr(" ", length (opts
[i
]))
179 hlp =
"N_(\"" help
[i
] "\")";
181 print " " enum
"," s
"/* -" opts
[i
] " */"
187 print "#endif /* OPTIONS_H */"